LIST P=18F4550
include "p18f4550.inc"
errorlevel -302, -203, -205, -206
CONFIG FOSC= HS
cblock 0x000
temp1
d1
d2
d3
endc
org 0x000
bra slave
slave
call DelayHalfsec
clrf LATA
clrf LATB
clrf LATC
clrf LATD
clrf LATE
movlw 0xFF
movwf ADCON1
movlw 0x00
movwf TRISA
movwf TRISB
movwf TRISC ; RC7 is SDO
movwf TRISE
movlw b'00000100' ;right pic slave, RD2 chip select
movwf TRISD
movlw b'00000001' ; RB0 is SDI, RB1 is SCK
movwf TRISB
movlw b'00000000';cke bit 6
movwf SSPSTAT
movlw b'00100010';ckp bit 4
movwf SSPCON1
Receive_DT
btfss SSPSTAT, BF ; test BUFFER FULL bit
bra Receive_DT ; if not full, wait
movff SSPBUF, temp1
movlw b'00000110' ; this is the value expected from master
xorwf temp1, w
btfsc STATUS, Z
bsf PORTD, 1 ; if expected data matches with actual data, turn ON LED
bra Receive_DT ; else, loop forever
;---------------------------
DelayHalfsec ; 20MHz
movlw 0x15
movwf d1
movlw 0x74
movwf d2
movlw 0x06
movwf d3
DelayHalfsec_0
decfsz d1, f
bra $+4
decfsz d2, f
bra $+4
decfsz d3, f
bra DelayHalfsec_0
bra $+2
bra $+2
return
;----
END