I have been trying to use the read data EEPROM feature of the 16F88, but can't get it to work.
I have used the sample code from Microchip's datasheet. Attached is the (entire) ASM file that I am using. It should (I had hoped) store the value h'BB' in the register count1. Then read it from the data EEPROM location (h'20') and store it into the register count2.
When I step through it in the simulator, the EEDATA register gets the value h'FF' instead of h'BB'. I can't figure this out and have spent many hours on it so would be very grateful if someone could help.
Code follows...
LIST N=90,ST=OFF,p=16F88 INCLUDE P16f88.INC ;Register definitions errorlevel 0,-302 __config _config1, _hs_osc & _wdt_off & _pwrte_on & _cp_off & _boden_off & _CCP1_RB0 & _WRT_PROTECT_OFF & _CPD_OFF & _LVP_OFF __config _config2, _IESO_ON & _FCMEN_ON
cblock h'20' ; count1 count2 ADDR endc
GOTO INITIALISE NOP NOP NOP
INITIALISE
banksel eedata ; Clearing these registers first to make it easier ; to see what's going on in Watch Window clrf eedata clrf eeadr
banksel count1 clrf count1 clrf count2 movlw h'BB' movwf count1
read_eeprom ; This section of code taken from 16F88 datasheet BANKSEL EEADR ; Select Bank of EEADR
; MOVF ADDR,W ; I replaced this line with the literal value h'20' movlw h'20' ; (which is the address of count1) for the purposes of ; troubleshooting
MOVWF EEADR ; Data Memory Address to read 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 EEDATA,W ; W = EEDATA
; check to see if data read successful banksel count2 movwf count2 ; move the data value to count2
goto $ end