Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Writing to the EEPROM in a PIC16F77A

Status
Not open for further replies.

si2030

Member
Hi all,

So I have the program reading the EEPROM but unfortunately the routine I am using to write to the EEPROM is not working.

I got the routine from the PIC16F877A datasheet on page 45 - EXAMPLE 4-2. However I found that I had to swap back to BANK0 to load my variables ADDR and VALUE. I did this and it works loading these up and also loads then into EEADR and EEDATA. Thats where my good luck stops. it fails to load these into the EEPROM... that is, after the routine completes I still have all locations with "FF" in them....

I have added to this post the .asm file with just the write routine in it and have been using this to test the write to EEPROM routine...

Hope you can help.

Simon
 

Attachments

  • EEPROM.asm
    3.1 KB · Views: 264
There are a few things wrong with your asm file,

No return at the end of WRITE_EEPROM.
You are enabling interrupts even though you have no interrupt routine.
in READ_EEPROM
EECON1 is in bank 3
EEDATA is in bank 2

If you are using MPLAB to check the contents of the EEPROM you must do Read EEDATA before you will see any changes.

Mike.
 
hi si2030,
WHY have you started another thread on same EEProm program I helped you sort out the READ subr, only yesterday.??:)
 
Last edited:
I did get the read part working and I was treating the two in separate areas of my main program so thought I would start a new thread in view of this... perhaps I was being a little to pedantic... will now have a go on this and then fix up the main program which has now developed new errors :(

By the way thanks for having a look :)

Simon
 
Hi there,

I have just had a closer look at this and I think I am selecting the correct BANK for each required action. I have selected BANK 3 to start with to change "WR" in EECON1 and then selected BANK 0 to load the address ADDR then selected BANK 2 to load this into EEADR. I then move back to BANK 0, load up VALUE into W, move back to BANK 2 and load this into EEDATA. Then I select BANK 3 and work with EECON1 again. I can manage to get this far in the debugger without any issue and also to load the 0X55 and 0XAA as well... it doesnt do anything when I perform the following line

Code:
bsf 	EECON1, WR 	;START WRITE OPERATION

and therefore no affect on the address in the EEPROM...

I stripped this down for the thread and this routine will go into my larger program which does have interrupts... although I disabled then in the ASM file I have added into this thread.

Kind Regards

Simon
 

Attachments

  • EEPROM.asm
    3.2 KB · Views: 173
I did get the read part working and I was treating the two in separate areas of my main program so thought I would start a new thread in view of this... perhaps I was being a little to pedantic... will now have a go on this and then fix up the main program which has now developed new errors :(

By the way thanks for having a look :)

Simon

hi Simon,
If you continue using the same thread its easier to keep the continuity when answering the various problems that you have in your program.
When you start a new thread it dosnt show what problems and answers you have had update.

I would suggest that you write your programs as modules, debug each module until it runs smoothly.
For example, write and debug a EEProm write/read outside of the main program.

Do you use the Oshonsoft IDE simulator.??
 
I was referring to these,
Code:
READ_EPROM		 
		bcf	STATUS,RP0
		bsf	STATUS,RP1	;BANK 2    [COLOR="red"]<<should be bank 3[/COLOR]
		bsf	EECON1,RD	;EEPROM READ
		bcf	STATUS,RP0	;BANK 0    [COLOR="red"]<<should be bank 2[/COLOR]
		bcf	STATUS,RP1
		movf	EEDATA, W
		return
 
Yes your right... I did screw that up.. wondering if you could have look at the WRITE_EEPROM routine as this is still mucking me around... does everything until the actual writing..

Eric, I tried Oshensoft IDE and thought it a great product but I could'nt work out how to create my schematic in the IDE. In particular setting up the LCD connections and keyboard connections. It was too late to change anything as I had already build the development board. It would be nice as this shows the whole system working and you can clearly debug with greater precision. As for the Debugging process you are absolutely right in saying break it down into smaller more manageable programs and then piece them together... I was rolling along reasonably well until I hit this section and so created a project called EEPROM just to get the read and write working... just cant get the write working yet.. I have since fixed the errors in the main program. I inadvertently dropped the initial setting of FSR and that caused all manner of problems its fixed now but I devolved the whole system stripping out the recent code I wrote.. about to put it back one routine at a time...
 
Try changing the end of your write routine to,
Code:
		movlw	0x55		;WRITE 55H TO
		movwf	EECON2		;EECON2
		movlw	0xAA		;WRITE AAH TO
		movwf	EECON2		;EECON2
		bsf	EECON1,WR	;START WRITE OPERATION
					;ONLY ENABLE INTERRUPTS 
[COLOR="red"]		btfsc	EECON1,WR	;WAIT FOR
		goto	$-1		;WRITE TO FINISH[/COLOR]
		bsf	INTCON,GIE	;IF USING INTERRUPTS,
					;OTHERWISE DISCARD 
		bcf	EECON1,WREN	;DISABLE WRITES
		return

I suspect that trying to read it before it's finished writing is the problem.

Mike.
 
I believe that worked.. :) I tried to run through stepping one line at a time and it got caught on the "btfsc EECON1, WR" line but when I played it it worked.. :) great very much appreciated.... Simon
 
hey budy, i have this kind of code' its work,.. but i'm having problem with that RED one co'z it stuck there and never come out. i've write 4 digits and put some indication of 4th digit and my indicator not works ( just glowing LED at any port pins);
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top