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 }