EEPROM Read/Write Problem 16F84a

For C and ASSEMBLY users to post questions and code snippets for programming in C and ASSEMBLY. And for any other C or ASM course related questions.

Moderators: Benj, Mods

Post Reply
econnections
Posts: 35
Joined: Fri Dec 26, 2008 4:02 pm
Contact:

EEPROM Read/Write Problem 16F84a

Post by econnections »

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

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
Read 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 
	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

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: EEPROM Read/Write Problem 16F84a

Post by Benj »

Hello

If you are using PPP to program your device then once you have programmed the first file you will need to open the PPP configuration and click on Options -> Options and untick the following.

Erase PICmicro before programming
Check that the PICmicro gets erased ok

Then hopefully your EEPROM memory will not be overwritten with your new program

econnections
Posts: 35
Joined: Fri Dec 26, 2008 4:02 pm
Contact:

Re: EEPROM Read/Write Problem 16F84a

Post by econnections »

Hi Ben,

After unticking the options you mentioned my 'read eeprom' program appears to work, so many thanks for that.

I noticed that unticking these boxes are not saved after clicking OK so each time I run the program I have to go back and reset these options in PPPv3.

Q1) is this behaviour correct and if so is there a way to turn off memory erasing in one of the .cfg files?

Q2) alternatively, is there a _config word I can add that will do the same?

I notice in PPP v2.3 erase is turned off by default or a confuguration for this capability doesn't exist.

Thank you once again.

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: EEPROM Read/Write Problem 16F84a

Post by Benj »

Hello

PPP V2.3???? wow. you can get V3.9 from here if you wish.

http://www.matrixmultimedia.com/software/PPPv3.exe

If you load PPP from the start menu link eg not through Flowcode or other programming IDE then change the settings then they should be saved for the next time you run PPP as stand alone or as part of an programming IDE.

Post Reply