EEPROM Read/Write Problem 16F84a
Posted: Mon Feb 09, 2009 2:10 am
I have carefull read the data sheet for the 16F84a on reading/writing to the EEPROM memory and it appears straight forward. I also read tutorial 33 in ASM for PICMicro v2 and ran tutorial 34 on my v2 development board. I iniated an alarm in zone 3 then read the alarm activation time saved in the EEPROM memory so I know everthing does work correctly.
I copied the write subroutine into a short test program shown below and attempted to save 0x03 to eeprom address 0x01. Next I copied the read subroutine into another test program and attempted to read the data saved in the eeprom and display it on portb. However, I also get the value 0xff and not 0x03.
Not knowing which test program is not working I tried saving alarm activation times with tutorial 34 and then using my test program to read eeprom addresses 0 - 7 where the zone times are stored, however, each location is showing as having the value 0xff leading me to believe there is a problem with my read program but I'm not 100% sure.
I am totally confussed, everything looks correct and I can't find the error. I would appreciate any help with this.
Write Program
Read Program
I copied the write subroutine into a short test program shown below and attempted to save 0x03 to eeprom address 0x01. Next I copied the read subroutine into another test program and attempted to read the data saved in the eeprom and display it on portb. However, I also get the value 0xff and not 0x03.
Not knowing which test program is not working I tried saving alarm activation times with tutorial 34 and then using my test program to read eeprom addresses 0 - 7 where the zone times are stored, however, each location is showing as having the value 0xff leading me to believe there is a problem with my read program but I'm not 100% sure.
I am totally confussed, everything looks correct and I can't find the error. I would appreciate any help with this.
Write Program
Code: Select all
; The following line embeds configuration data into the PICmicro
__CONFIG H'3FF9' ; XT mode
; __CONFIG H'3FFB' ; RC mode
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
include "C:\PROGRA~1\MPLAB\P16F84a.INC"
#DEFINE PAGE0 BCF STATUS,5
#DEFINE PAGE1 BSF STATUS,5
W EQU H'0'
F EQU H'1'
; Program Start:
ORG 0
GOTO 005
NOP
NOP
NOP
NOP
PAGE0
CLRF PORTB
PAGE1
CLRF TRISB ;SET-UP PORTB AS OUTPUTS
BCF EECON1,EEIF ;CLEAR WRITE OPERATION FLAG
BCF INTCON,GIE ;DISABLE INTERRUPTS
MOVLW H'1' ;address where data will be written in EEPROM
SETPRM MOVWF EEADR ;Copy W into EEADR to set eeprom address
PAGE1
BSF EECON1,WREN ;enable write flag
PAGE0
MOVLW H'3' ;data to be stored in EEPROM
MOVWF EEDATA ;copy W into eeprom byte
MANUAL PAGE1 ;these next 12 lines are according to
MOVLW H'55' ;Microchip manual dictated factors
MOVWF EECON2 ;they cause the action required by
MOVLW H'AA' ;by the eeprom to store the data
MOVWF EECON2
BSF EECON1,WR ;set the "perform write" flag
CHKWRT BTFSS EECON1,4 ;wait until bit 4 of EECON1 is set
GOTO CHKWRT
BCF EECON1,WREN ;disable write
BCF EECON1,4 ;clear bit 4 of EECON1
PAGE0
BCF INTCON,6 ;clear bit 6 of INTCON
BSF INTCON,GIE ;ENABLE GLOBAL INTERRUPTS
BSF PORTB,7 ;LIGHT RB7 TO SHOW PROGRAM FINISHED
FINISH NOP
GOTO FINISH
END
Code: Select all
; The following line embeds configuration data into the PICmicro
__CONFIG H'3FF9' ; XT mode
; __CONFIG H'3FFB' ; RC mode
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
include "C:\PROGRA~1\MPLAB\P16F84a.INC"
#DEFINE PAGE0 BCF STATUS,5
#DEFINE PAGE1 BSF STATUS,5
W EQU H'0'
F EQU H'1'
; Program Start:
ORG 0
GOTO 005
NOP
NOP
NOP
NOP
PAGE1
CLRF TRISB ;SET-UP PORTB AS OUTPUTS
PAGE0
CLRF PORTB
MOVLW H'3' ;START OF READ EEPROM ROUTINE
MOVWF EEADR ;SET ADDRESS FROM WHERE DATA IS TO BE READ
PAGE1
BSF EECON1,RD ;ENABLE READ FROM EEPROM
PAGE0
MOVF EEDATA,W ;TRANSFER DATA TO WREG
MOVWF PORTB ;DISPLAY CONTENTS OF WREG
FINISH NOP
GOTO FINISH
END