Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Problem Write and read EEPROM of 16F877A

Status
Not open for further replies.

vin2403

Newbie level 4
Joined
May 19, 2009
Messages
6
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,308
16f877 eeprom

example ,
write 22 into address 0xFF
write 44 into address 0xFE
write 88 into address 0xFC

when i read
adress 0xFF store 88
address 0xFE store 44
address 0xFC store 22

Why this happening ?Can any pro HElp
 

writing to eeprom with 16f877

Can you post the code you are using to write that data?
 

memory write eeprom 16f877

void saveData()
{
if(RB1==0||RB2==0)
{
delay(250);

EEADR=0xFF;
EEDATA=hCount;
WREN=1;
EECON2=0x55;
EECON2=0xAA;
WR=1;
while(WR==1) continue;

WREN=0;


EEADR=0xFE;
EEDATA=lCount;
WREN=1;
EECON2=0x55;
EECON2=0xAA;
WR=1;
while(WR==1) continue;

WREN=0;


EEADR=0xFC;
EEDATA=powCount;
WREN=1;
EECON2=0x55;
EECON2=0xAA;
WR=1;
while(WR==1) continue;

WREN=0;
}



}

void readData()
{

EEADR=0xFF;
powCount=EEDATA;
RD=1;


EEADR=0xFE;
hCount=EEDATA;
RD=1;



EEADR=0xFC;
lCount=EEDATA;
RD=1;

}
if i put like tis , i get my desired result , but why , y the data ned read from different address .
 

write and read eeprom

One thing I notice straight away is that you're not Setting/Re-Setting EECON1 bit 7 that determines whether you are writing to EEPROM or Program data memory. EEPGD bit of EECON1 register needs to be '0' to access the data memory.

In the "read" function, you seem to be assigning value of EEDATA before setting the "RD" flag to 1. That means the "old" value is transferred. In other words, the first read you attempt actually feeds the last data you attempted to write. The read function should look like this:

Code:
void readData()
{
	EEADR=0xFF;
	RD=1;
	powCount=EEDATA;
	
	
	EEADR=0xFE;
	RD=1;
	hCount=EEDATA;
	
	
	
	EEADR=0xFC;
	RD=1;
	lCount=EEDATA;
}

Also, I don't know about the rest of your code (main) but you should disable interrupts (GIE bit) before starting the write/read sequence and re-enable it before returning. Also, there is no initialization of lCount, hCount or powCount visible, so I'm not sure what values are stored in those variables. Don't forget that all of the variables MUST be initialized (or directly assigned a value/result) since the values on startup aren't guaranteed to be zero or anything else. If you just tried to increment hCount without first setting it to zero you can't be sure what you'll get.
 
eeadr eedata

yes , it work , thank you helping , i will be careful next time i using.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top