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.

EEPROM read/Write on T89C51RD2

Status
Not open for further replies.

john2020

Full Member level 5
Joined
Nov 13, 2005
Messages
292
Helped
12
Reputation
24
Reaction score
8
Trophy points
1,298
Activity points
4,911
Hi there,


I'm currently trying to read and write to the EEPROM on my T89C51RD2.

The read function seems to operate correctly but I'm not having so much luck with the write function. Here is my code:


/*-------------------------------------
Return EEPROM Byte at address 'adr'
-------------------------------------*/

unsigned char ReadEEPROM (unsigned int adr) {

unsigned char v;

EECON = 0x02; // enable EEPROM
v = XBYTE[adr]; // read value
EECON = 0x00; // disable EEPROM

return (v);

}


/*------------------------------------------
Write EEPROM Byte 'val' at address 'adr'
------------------------------------------*/

void WriteEEPROM (unsigned int adr, unsigned char val) {

int i;

EECON = 0x02;
// enable EEPROM and set write bit
EETIM = 0xC8;
// Set EETIM to 5x Fxtal (40 Mhz)

XBYTE[adr] = val; // write value
EECON = 0x52;
EECON = 0xA2;
while (EECON == 0xA3);
// wait until value programmed
EECON = 0x00; // disable EEPROM

}



In researching this problem I found the following link:

http://www.atmel.com/dyn/resources/prod_documents/doc4101.pdf

which says for the write sequence should be repeated 3 times for a succesful write. I attempted this by implimenting a simple for loop. But it had no effect.

The other annoying thing is seems to work in the code debugger, but not on the chip??

Has anyone got any suggestions as to what I'm doing wrong. Thank you for your time. Any other info needed just ask.

regards
john
 

Hi John,

Please tell me first why do you think that inside elektroda forum you'll receive better answers rather than keil forum ?
This question is not an offence for elektroda members but if the answer is positive it means we deserve to be granted.

I ask this because of : https://www.keil.com/discuss/docs/thread4210.htm

And it's not the only link posted by you from keil forum.

I mean why just copy and paste ?

And what's all about all those questions posted on elektroda ?

Do you really work on all those projects in the same time ?

Now back to the thread.

What is the Xtal frequency of your T89C51RD2 ? It's exactly 40 Mhz ?
Do you use 12 clocks / machine cycle or x2 multiplier ?
Just because 5x used for setting EETIM is 10x in x2 mode.

Small tips : Try to get use of the logic operators when you set or reset individual bits of the registers.
Thus you avoid changing others by pure assignments.

Thus, instead EECON = 0x02; try EECON |= 0x02; // Enable EEPROM memory space
or instead EECON = 0x00; try EECON &= 0xFD; // Disable EEPROM memory space

Why "while (EECON == 0xA3);" and not "while(EECON & 0x01);" // Wait for EEPROM write to finish

Please check if XBYTE[adr] = val; // write value
is replaced in the code with MOVX @DPTR,A where A = val
 

hi silvio

i work currently with three projects only.it's my friends who post about Eprom read/write on T89C51.I havenot copied and pasted anything here.Maybe it have had happened by coincidence.A lot people are benefited here,by various posts,also this forum helps people in many aspects.i don't want to just take information from some other forum and put here.I will see that this is not being repeated here anymore.all the questions posted here are based on microcontrollers.we are a group of people who work on various assignments here,so they post all their queries through my account.But i will make sure that questions are not repeated here anymore.


i am not sure about the xcrystal frequency T89c51RD2,but i think my friend has used x2 multiplier.i will query with my colleague and get back to you my friend.

regards
john
 

    V

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top