RobertD
New Member
I have a problem with the EEPROM. When I turn the chip off, I get 0xFF in my EEPROM registers, and the NEW register now puts this value in the read sequence and returns 255 instead of the previously entered value. In other words, the data doesn't get written into EEPROM, can you spot the error?
Code:
read
LIST p=16F88
include "P16F88.inc"
__config _CONFIG1, _WDT_OFF & _INTRC_IO & _MCLR_ON & _LVP_OFF
errorlevel -302
NEW equ h'74' ;EEPROM locations
OLD equ h'75'
read
banksel EEADR ;Select Bank of EEADR
movf NEW, W
movwf EEADR ; Data Memory Address to
banksel EECON1 ; Select Bank of EECON1
bcf EECON1, EEPGD ; Point to Data memory
bsf EECON1, RD ; EE Read
banksel EEDATA ; Select Bank of EEDATA
movf EEADR, W
return
;_________________________________________________
write
banksel EECON1 ; Select Bank of EECON1
btfsc EECON1, WR ; Wait for write
goto $-1 ; to complete
banksel EEADR ; Select Bank of EEADR
movf NEW, W
movwf EEADR ;DATA Address to write
movf NEW, W ;
movwf EEDATA ; DATA Value to write
banksel EECON1 ; Select Bank of EECON1
bcf EECON1, EEPGD ; Point to DATA memory
bsf EECON1, WREN ; Enable writes
bcf INTCON, GIE ; Disable INTs.
movlw 55h
movwf EECON2 ; Write 55h
movlw h'AA'
movwf EECON2 ; Write AAh
bsf EECON1, WR ; Set WR bit to begin write
bsf INTCON, GIE ; Enable INTs.
bcf EECON1, WREN ; Disable writes
return