; SPItstS0.asm ; SLAVE Rev 0 ; Demonstrates SPI connection between 2 PICs ; Master sends data (a counter), Slave receives and outputs to LEDs ; on PORTB list p=16F876 #include "p16F876.inc" _CONFIG _CP_OFF _DEBUG_OFF _WRT_ENABLE_OFF _CPD_OFF _LVP_OFF _BODEN_OFF _PWRTE_ON _XT_OSC _WDT_OFF #define CS 0x20 ; PORTA,5 (HW SS pin) ORG 0X00 nop ; FOR ICD ; Set up the SPI Support BANKSEL TRISA ; BANK 1 movlw CS ; Chip Select pin movwf TRISA ; is in input mode movlw 0x06 ; Turn Off A/D mode for at least the movwf ADCON1 ; Chip Select pin (all Digital mode) ; Set up output port BANKSEL TRISB ; BANK 1 movlw 0x00 ; Configure all PORTB pins movwf TRISB ; to be in output mode ; Set up the SPI BANKSEL TRISC ; BANK 1 movlw 0x18 ; SCK is input (Slave), SDI is input, movwf TRISC ; SDO is output, all others output movlw 0x40 ; Mode 1,1 SPI with movwf SSPSTAT ; middle of output time sampling BANKSEL SSPCON ; BANK 0 movlw 0x34 ; Mode 1,1 SPI Slave Mode, /SS Required movwf SSPCON ; SSP is on ; Here is the SPI Slave Code. Again, it looks complex, but it is a complete example ; and not just a segment of code. Chk4Dat movlw SSPSTAT ; Indirectly test movwf FSR ; a register by loading FSR btfss INDF,BF ; Here is the test goto Skip_ND ; New data, do a transfer (below RX_Data BANKSEL SSPBUF ; BANK 0 movf SSPBUF,W ; put in SSPBUF into W BANKSEL PORTB ; BANK 0 movwf PORTB ; Show the results on PORTB DoAgain ; Optional customer code can go here goto Chk4Dat ; Receive Next Byte end