RobertD
New Member
Hi folks, I've been trying to get a value to write and read into EEPROM, but the ADDRess of the write register doesn't get read as an address, but as the value in it, and the NEW value I'm trying to put in doesn't go in. Same thing when I read, the ADDRess reads the content instead of the location.
I tried to move some of the commands around a bit to see if that was the problem, but nothing works so far.
I tried to move some of the commands around a bit to see if that was the problem, but nothing works so far.
Code:
LIST p=16F88
include "P16F88.inc"
__config _CONFIG1, _WDT_OFF & _INTRC_IO & _MCLR_ON & _LVP_OFF
ERRORLEVEL 0, -302
ADDR equ 0x110
cblock 0x20
OLD, NEW,
endc
;WRITE TO EEPROM__________________________
org 0x00
movlw h'ab'
movwf NEW
movlw h'02'
movwf OLD
banksel TRISA ;bank 1
movlw 0x72 ;8MHz clock
movwf OSCCON
banksel EEADR ;Bank 2
movf ADDR,W ;Address to write to
movwf EEADR
movf NEW, W ;Data to write
movwf EEDATA
banksel EECON1 ;Bank 3
bcf EECON1, EEPGD ;Point to Data memory
bsf EECON1, WREN ;Enable writes
movlw 0x55 ;Write 55h to
movwf EECON2 ;EECON2
movlw 0xAA ;Write AAh to
movwf EECON2 ;EECON2
bsf EECON1, WR ;Start write operation
btfsc EECON1, WR ;Wait for write to finish
goto $-1
bcf EECON1, WREN ;Disable writes
;_____________________________________________________________________________________
;READ EEPROM
banksel EEADR
movf ADDR, W ;address to read from
movwf EEADR
banksel EECON1 ;Bank 3
bcf EECON1, EEPGD ;Point to Data memory
bsf EECON1, RD ;Start read operation
banksel EEADR ;Bank 2
movf EEDATA, W ; W=DATA from EEPROM
movwf OLD
end
Last edited: