| ??? 12/18/08 16:50 Read: times |
#161032 - Much more complicated Responding to: ???'s previous message |
Writing to EEPROM is much more complicated, as you need to check that the EEPROM isn't busy. If it's any help, here are the C functions I wrote.
/***************************************************************************
* NAME: api_wr_eeprom_byte
*----------------------------------------------------------------------------
* PARAMS:
* Uchar xdata * const address : address to read
* Uchar value : data to write
* return:
*----------------------------------------------------------------------------
* PURPOSE:
* This function allows to program a byte in Eeprom. Don't use raw, see
* changeEepromByte()
*----------------------------------------------------------------------------
* REQUIREMENTS: The EEPROM mustn't be busy to perform the write access.
* Check using __api_eeprom_busy() API
*
*****************************************************************************/
void __api_wr_eeprom_byte (xdata Uchar * const address, const Uchar value)
{
bit ea_save;
while(__api_eeprom_busy ()) giveTheDogABone();
ea_save = EA;
EA = 0;
EECON = 0x02;
*address = value;/* addr is a pointer to external data mem */
EECON = 0x50;
EECON = 0xA0;
EA = ea_save;
}
/***************************************************************************
* NAME: api_eeprom_busy
*----------------------------------------------------------------------------
* PARAMS:
* return: 0 (false) for not busy, 1 (true) for busy
*----------------------------------------------------------------------------
* PURPOSE:
* This function allows to check if eeprom is busy or not.
*****************************************************************************/
Bool __api_eeprom_busy (void)
{
return(EECON & 0x01);
}
/***************************************************************************
* NAME: api_rd_eeprom
*----------------------------------------------------------------------------
* PARAMS:
* Uchar xdata *address : address to read
* return:
*----------------------------------------------------------------------------
* PURPOSE:
* This function allows to read a byte in Eeprom.
*----------------------------------------------------------------------------
* REQUIREMENTS: The EEPROM mustn't be busy to perform the read access.
* Check using __api_eeprom_busy() API
*****************************************************************************/
Uchar __api_rd_eeprom_byte(const xdata Uchar *address)
{
Uchar val;
bit ea_save;
while(__api_eeprom_busy ()) giveTheDogABone();
ea_save = EA;
EA = 0;
EECON = 0x02;
val = *address;
EECON = 0x00;
EA = ea_save;
return (val);
}
The giveTheDogABone() function services the watchdog, so you wont need it if you're not using the watchdog. |
| Topic | Author | Date |
| 89C5131 | 01/01/70 00:00 | |
| see | 01/01/70 00:00 | |
| Much more complicated | 01/01/70 00:00 | |
| 89c5131 EEPROM | 01/01/70 00:00 | |
| From the data sheet | 01/01/70 00:00 | |
89c5131 | 01/01/70 00:00 |



