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

C and 89C51RD2's internal EEPROM

Hi,
Anyone successfully access Temic 89C51RD2's internal EEPROM? I have this

unsigned char xdata * data pEEAddr = 1;

void WriteOne(unsigned char val) {
unsigned char data dVal = val;

DisableGlobalInterrupt();
MapEE();
*pEEAddr = dVal;
UnMapEE();
EnableGlobalInterrupt();
}

Somehow that did not work reliably. I examined the assembler output and it looked ok (one movx instructure between the MapEE() and UnMapEE() macros).

Thanks for any insight.

Andy

  • I've had no problems at all with it. My basic routines (which definitely work) are as follow:

    // To read a single byte from a location in EEPROM.

    char ReadEEPROM(int addr)
    {
    char EEdata;

    EECON |= 0x02; // Enable EEPROM memory space
    EEdata = XBYTE[addr];
    EECON &= 0xFB; // Disable EEPROM memory space
    return(EEdata);
    }

    // To write a single byte to a location in EEPROM.

    void WriteEEPROM(int addr, char EEdata)
    {
    EECON |= 0x02; // Enable EEPROM memory space
    XBYTE[addr] = EEdata;
    EETIM = 0xB8; // Set timing register: 10*Fclk(MHz) = 10*18.432 = 184 = 0xB8
    EECON = 0x52; // Send sequence to start EEPROM write...
    EECON = 0xA2;
    while(EECON & 0x01); // Wait for EEPROM write to finish
    EECON &= 0xFB; // Disable EEPROM memory space
    }

    Note that in the write routine you must send the special codes to EECON to make the write happen - perhaps you missed this. You also need to tweak the timing register to suit your particular clock speed.

    Chris

  • 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?