EmbeddedRelated.com
Forums

Problems reading data Eeprom using Pic16F88

Started by izzy_w_2004 November 13, 2004


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,ST=OFF,pF88
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





I dont understand where you are writing BBh into the EEPROM. Given
your code, I would expect you to get FFh when you read because you
aren't writing to EEPROM. Maybe you've got the register space and
eeprom address space confused? They are seperate spaces and no
locations are reserved so you can start at 0.

You need to copy the write code from the datasheet and call that
first, then call the read code. By the way, you can display the
EEPROM contents in the simulator so you can immediately see the
results of your actions. You could manually write BB into location 20
of the EEPROM to see if the read code works.

--- In , izzy_w_2004 <no_reply@y...> wrote:
>
>
> 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,ST=OFF,pF88
> 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