參考了一些source code ,好像也沒特別的設定,不過我用Mplab sim 發現sck sdo 都沒反應,WriteSpi會一直停在等SSPSTATbits.BF flag ,請問是那邊有設定問題呢?
void main(void){
init_io();
init_timer();
OpenSPI(SPI_FOSC_64, MODE_11, SMPMID);
Nop();
while(1){
WriteSPI(0xaa);
}
}
void init_io(void){
PORTA=0x3f;
LATA=0x3f;
TRISA=0x00;
PORTB=0x00;
LATB=0x00;
TRISB=0xff;
PORTC=0x00;
LATC=0x00;
TRISC=0x10;
PORTD=0x00;
LATD=0x00;
TRISD=0x00;
PORTE=0x00;
LATE=0x00;
TRISE=0x00;
PORTF=0x00;
LATF=0x02;
TRISF=0xcd;
PORTG=0X00;
LATG=0x18;
TRISG=0X00;
PORTH=0X00;
LATH=0x0C;
TRISH=0X03;
PORTJ=0x00;
LATJ=0x00;
TRISJ=0x01;
}
void init_timer(void)
{
_asm
MOVLW 0x1f //B'00011111' //DISABLE PRIORITY LEVEL
MOVWF RCON,0
//bit 7 IPEN:0 = Disable priority levels on interrupts (PIC16CXXX Compatibility mode)
//bit 4 RI:1 = The RESET instruction was not executed
//bit 3 TO:1 = After power-up, CLRWDT instruction or SLEEP instruction
//bit 2 PD:1 = After power-up or by the CLRWDT instruction
//bit 1 POR:1 = A Power-on Reset has not occurred POR:0 A Power-on Reset occurred
//bit 0 BOR:1 = A Brown-out Reset has not occurred BOR:0 A Brown-out Reset occurred
MOVLW 0x80 //B'10000000' //DISABLE EXTERNAL BUS
MOVWF MEMCON,0
//bit 7 EBDIS:1 = External system bus disabled, all external bus drivers are mapped as I/O ports
MOVLW 0xe0 //B'11100000' //ENABLE UNMASKED PERIPHERAL INTERRUPT
MOVWF INTCON,0 //DEFAULT DISABLE ALL INTERRUPT
MOVLW 0xc0 //B'11000011'
MOVWF T0CON,0
MOVLW 0x0f //B'00001111' //A/D PORT CONFIG DIGITAL I/O
MOVWF ADCON1,0
MOVLW 0x07 //B'00000111' //COMPARATOR OFF
MOVWF CMCON,0
_endasm
}