LIST P=18F4550 ;directive to define processor
#include <P18F4550.INC> ;processor specific variable definitions
cblock 0x20
d1
d2
d3
RxData
endc
CONFIG FOSC=HS ; HS oscillator, HS used by USB
CONFIG PWRT=ON ; Power on timer
CONFIG BOR=OFF ; Brown out off
CONFIG WDT=OFF ; Watch dog off
CONFIG PBADEN=OFF ; Port B en digital IO
CONFIG LVP=OFF ; Pas de prog single supply
CONFIG ICPRT=OFF ; Port de debug off
CONFIG DEBUG=OFF ; Debug off
org 0x00
goto main
org 0x10
main
bcf INTCON, GIE
movlw b'10000000' ; Fosc/64
movwf SSPSTAT
movlw 0x22 ; 0001 0110
movwf SSPCON1
movlw 0x00
movwf LATB
movwf LATC
movwf LATD
movwf TRISC ; RC7 is SDO
movwf TRISD
movlw b'00000001' ; RB0 is SDI, RB1 is SCLK
movwf TRISB
bsf LATD,2 ; bring chip_select high
call Delay
bcf LATD,2 ; bring chip_select low to start A to D conversion
bsf LATD,0 ; Green LED- This LED lights up
start_conversion
btfss SSPSTAT, 0
bra start_conversion
movf SSPBUF, 0
movwf RxData
bsf LATD,1 ; Red LED - This does not light up
movlw 0x0A
movwf EEADR
movlw RxData
movwf EEDATA
bcf EECON1, EEPGD
bcf EECON1, CFGS
bsf EECON1, WREN
bcf INTCON, GIE
movlw 55h
movwf EECON2
movlw 0AAh
movwf EECON2
bsf EECON1, WR
bcf EECON1, WREN
loop_1
nop
bra loop_1
;---------------------------------------------------------------------
Delay ;0.5 s, 20MHz
movlw 0x01
movwf d1
movlw 0x01
movwf d2
movlw 0x02
movwf d3
Delay_0
decfsz d1, f
bra $+4
decfsz d2, f
bra $+4
decfsz d3, f
bra Delay_0
bra $+2
bra $+2
return
end