#include
//#include
_FOSC(CSW_FSCM_OFF & XT_PLL4); //XT with 4xPLL oscillator, Failsafe clock off
_FWDT(WDT_OFF); //Watchdog timer disabled
_FBORPOR(PBOR_OFF & MCLR_EN); //Brown-out reset disabled, MCLR reset enabled
_FGS(CODE_PROT_OFF); //Code protect disabled
#define Fcy 16000000
void delay(void)
{
short temp;
for (temp=0;temp<255;temp++)
;
}
int main(void)
{
//LATBbits.LATB2 = 1; //不知此处SS1是否需要配置
//TRISBbits.TRISB2 = 1;
LATF = 0x0000;
TRISF = 0x0080;
while(1)
{
//LATBbits.LATB2 = 0;
IFS0bits.SPI1IF = 0;
IEC0bits.SPI1IE = 1;
IPC2bits.SPI1IP = 0x010;
SPI1BUF = 0x0; //SPI相关寄存器配置
SPI1STAT = 0x0;
SPI1CON = 0x043C;
SPI1STAT = 0x8000;
LATDbits.LATD10 = 0; //mcp41010的片选CS接在DSP的RD10
SPI1BUF = 0x11F0; //前八位是命令字,后8位是电阻值
while(!IFS0bits.SPI1IF);
LATDbits.LATD10 = 1;
//LATBbits.LATB2 = 1;
delay();
}return 1;
}