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 C-code for T89C51CC01/02

Dear,

I'm not able to communicate with the internal EEPROM from the CC01 device.

Has anybody any C-sample code that helps me get started?

I'm not able to port the asm-code to C-code.

Help needed.


Parents
  • #define EEE 0x02
    #define EEE_reset 0xFD
    #define EEBUSY 0x01

    void WaitUntilReady(void)
    {
    while ((EECON & EEBUSY) == EEBUSY);
    }

    char ReadEEPROM (unsigned int EEPROMAddress)
    {
    char xdata *p_eeprom;
    char ReadOut;
    WaitUntilReady();
    EECON |= EEE;
    p_eeprom = (char xdata*) EEPROMAddress;
    ReadOut = *p_eeprom;
    EECON &= EEE_reset;
    return (ReadOut);
    }

    void CommitEEPROM (void)
    {
    WaitUntilReady();
    EECON = 0x50;
    EECON = 0xA0;
    }

    void WriteEEPROM (unsigned int EEPROMAddress,unsigned char EepromData)
    {
    char xdata *p_eeprom;
    WaitUntilReady();
    EECON |= EEE;
    p_eeprom = (char xdata*) EEPROMAddress;
    *p_eeprom = EepromData;
    EECON &= EEE_reset;
    CommitEEPROM();
    }


    void main (void)
    {
    // SIMPLE WRITE & READ COMMAND
    WriteEEPROM (0x0001,0xAA);
    WriteEEPROM (0x0002,0x55);
    ReadEEPROM (0x0001);
    ReadEEPROM (0x0002);
    }

Reply
  • #define EEE 0x02
    #define EEE_reset 0xFD
    #define EEBUSY 0x01

    void WaitUntilReady(void)
    {
    while ((EECON & EEBUSY) == EEBUSY);
    }

    char ReadEEPROM (unsigned int EEPROMAddress)
    {
    char xdata *p_eeprom;
    char ReadOut;
    WaitUntilReady();
    EECON |= EEE;
    p_eeprom = (char xdata*) EEPROMAddress;
    ReadOut = *p_eeprom;
    EECON &= EEE_reset;
    return (ReadOut);
    }

    void CommitEEPROM (void)
    {
    WaitUntilReady();
    EECON = 0x50;
    EECON = 0xA0;
    }

    void WriteEEPROM (unsigned int EEPROMAddress,unsigned char EepromData)
    {
    char xdata *p_eeprom;
    WaitUntilReady();
    EECON |= EEE;
    p_eeprom = (char xdata*) EEPROMAddress;
    *p_eeprom = EepromData;
    EECON &= EEE_reset;
    CommitEEPROM();
    }


    void main (void)
    {
    // SIMPLE WRITE & READ COMMAND
    WriteEEPROM (0x0001,0xAA);
    WriteEEPROM (0x0002,0x55);
    ReadEEPROM (0x0001);
    ReadEEPROM (0x0002);
    }

Children
No data