This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

EEPROM read/Write on T89C51RD2

Hi there,

I'm new to all this so bare with my ignorance...

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.

Matt.

Parents Reply Children
  • oh,I have the same problem.And in http://www.keil.com/forum/docs/thread477.asp
    EECON &= 0xFB; // Disable EEPROM memory space
    I think it should be:
    EECON &= 0xFD;
    And the value of EETIM in my system:
    EETIM = 0x7D; //5*25MHz
    And In my simulator debug,it will endless in:
    while(EECON & 0x01); // Wait for EEPROM write to finish
    so I must put the microcontrol to the board, but can't get right eeprom data operation,what't wrong about it?

  • My emulator micetek Easypack/E II 8052F can't support EEPROM data RD/WR function,so I must download my code to the cpu and run it in board?
    The cpu is ATMEL 89C51RD2-CM,is it the T89C51RD2? And the programmer is lab tool-48,its software vertion is V4.67,the device of T89C51RD2 for selecting is only TEMIC,I don't know whether they are the same device?
    I can't get right EEPROM data RD/WR using your means,so could you give me some advice?