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.

16f877a Eeprom Data Corruption

Status
Not open for further replies.

andyy07

New Member
Hi.
I have a little problem with eeprom on a 16F877A. When I turn the power on and off and then back on a few tmes the eeprom data is corrupting. When I read it back I find that it's really messed up.
Do someone have a solution for this ?
Thanks in advance.
 
Bad eeprom write code.
Post your entire code.
 
Could be bad reading code as well. Have you tried replacing the suspect IC with a couple of others? Have you been succesful with the EEPROM using this same code before?
 
I don't think is the code...I filled all the eeprom with 0s in ICPROG an I turned the power on and off a few times without writing or reading it with my code and it got messed up....anyway here's the code of read and write:
; EEPROM READ

ee_read

movf ee_adr,W
bsf STATUS, RP1
bcf STATUS, RP0
movwf EEADR
bsf STATUS, RP0
bcf EECON1, EEPGD
bsf EECON1,RD
bcf STATUS,RP0
movf EEDATA,W
bcf STATUS, RP1
bcf STATUS, RP0
movwf read_result

return

; EEPROM WRITE

ee_write

bsf STATUS, RP1
bsf STATUS, RP0
btfsc EECON1, WR
goto $-1
bcf STATUS, RP1
bcf STATUS, RP0
movf ee_adr,W
bsf STATUS, RP1
movwf EEADR
bcf STATUS, RP1
bcf STATUS, RP0
movf write_data,W
bsf STATUS, RP1
movwf EEDATA
bsf STATUS, RP0
bcf EECON1, EEPGD
bsf EECON1, WREN

movlw 0x55
movwf EECON2
movlw 0xAA
movwf EECON2
bsf EECON1, WR

bcf EECON1, WREN

bcf STATUS, RP1
bcf STATUS, RP0

btfss PIR2,EEIF
goto $-1
bcf PIR2, EEIF

return
 
This sounds more like ICPROG being inconsistent when reading the EEPROM. If you simply read the EEPROM a few times, do you get consistent results? Have you tried different software such as WinPic (available from this page.).

Mike.
 
It sees like I've resolved the thing, I've activated PWRT an the bad thing did not happen no more...anyway I got to make more tests to be sure....I don't think ICPROG has problems but who knows....
 
I suggest adding BCF INTCON, GIE at the top of your ee_write routine. This will prevent interrupts from interfering.
 
andyy07 said:
It sees like I've resolved the thing, I've activated PWRT an the bad thing did not happen no more...anyway I got to make more tests to be sure....I don't think ICPROG has problems but who knows....
It is easy to tell if the problem is the harware or software.

Blank the FLASH.
If the EEPROM gets corrupted with blanked flash then it is a hardware problem because there is no code.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top