Mosaic
Well-Known Member
Hello:
This is working code for those who are interested. 16f886
This is working code for those who are interested. 16f886
Code:
EEpromWrite; write 'Tmp' number of GPR bytes into EEPROM address starting at 'wreg' value. FSR preloaded to GPR start addr.
;FSR set for bank0,1, ; bank 2,3 GPR requires 'bsf STATUS,IRP' for FSR to work on those GPR. Preset this b4 calling this code.
banksel EEADR
movwf EEADR ; store dest. eprom address
incf Tmp,f ; compensate for decfsz. Tmp is a multibank variable
EEWloop decfsz Tmp,f ; skip next if 0, else
goto Dowrite
clrf STATUS; bank0, irp clr etc.
return
Dowrite ; perform write of a gpr byte to eeprom. Costs 10ms!
movf INDF,w;get gpr data
movwf EEDAT ; data value to write
banksel EECON1
bcf EECON1,EEPGD; set to ee data mem
bsf EECON1,WREN; enable ee write
bcf INTCON,GIE; halt ISRs
btfsc INTCON,GIE
goto $-2 ; verify isr halts
movlw 0x55 ; required
movwf EECON2; required
movlw 0xAA; required
movwf EECON2 ; write AA
bsf EECON1,WR; begin write
btfsc EECON1,WR ;WAIT FOR
goto $-1 ;WRITE TO FINISH
bsf INTCON,GIE; enable isrs
bcf EECON1,WREN; disable write
banksel EEADR
incf FSR,f ; pt to next GPR byte
incfsz EEADR,f ; pt to next eeprom byte, skip if overflow
goto EEWloop
clrf STATUS; bank0, clr IRP
retlw 0xFF ;255 in wreg signifies an overflow happened!
Last edited: