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

T89C51RD2 can't rd/wr internal EEPROM

Hello all,
I wrote the following functions for reading and writing to the internal EEPROM but for some reason it not working.
Can some tell me what's wrong in this code?

void intEepromWr(void *pBuff,uint iEepromAddr,uint iBuffLen){
volatile uchar xdata *pIntEeprom = (uchar xdata *)iEepromAddr;

EECON = 0xFC; //Reset value
EETIM = 0x37; //5*11.0592MHz in normal mode
for (pSram=pBuff ; iBuffLen>0 ; iBuffLen--,pSram++,pIntEeprom++) {
while(EECON & 0x01);// Wait while eeprom busy
EECON = 0x02;// EEE=1 EEPROM mapped
*pIntEeprom = *pSram; // Write data to eeprom
EECON = 0x50;
EECON = 0xA0;
}
}

void intEepromRd(void *pBuff,uint iEepromAddr,uint iBuffLen){
volatile uchar xdata *pIntEeprom = (uchar xdata *)iEepromAddr;

EECON = 0xFC; //Reset value
EETIM = 0x37; //5*11.0592MHz in normal mode
EECON = 0x02; // EEE=1 EEPROM mapped
for (pSram=pBuff ; iBuffLen>0 ; iBuffLen--,pSram++,pIntEeprom++) {
while(EECON & 0x01); // Wait while eeprom busy
*pSram = *pIntEeprom; // Read data from EEPROM
}
EECON &= 0xFC;
}

Thanks a lot,
Roberto