Other functions:
/****************************************************************************/
/* EEpromWrite(address, value) */
/****************************************************************************/
unsigned char EEpromWrite(unsigned int address, unsigned int value)
{
unsigned char err, LSB, MSB;
unsigned int b_addr;
b_addr = address * 2;
err = FALSE;
if (address > 0x03FF) err = TRUE; /* address out of range */
else
{
TR0 = 0; /* TR0: stop Counter T0 */
EA = 0; /* Disable All Interrups */
WMCON |= EEMEN; /* enable EEPROM accesses */
WMCON |= EEMWE; /* enable EEPROM writes */
LSB = value % 256; /* Calculate LSB byte */
XBYTE[b_addr] = LSB; /* Write LSB byte */
while (!(WMCON & WDTRST)); /* Wait for end of write EEPROM */
MSB = value / 256; /* Calculate MSB byte */
XBYTE[b_addr + 1] = MSB; /* Write MSB byte */
while (!(WMCON & WDTRST)); /* Wait for end of write EEPROM */
if (LSB != XBYTE[b_addr]) err = TRUE; /* Compare data */
if (MSB != XBYTE[b_addr + 1]) err = TRUE; /* Compare data */
WMCON ^= EEMWE; /* disable EEPROM writes */
WMCON ^= EEMEN; /* disable EEPROM accesses */
END_SAMP = 0; /* Seted after Nsamples reading */
sample_count = 0; /* Clear samples counter */
EA = 1; /* Enable All Interrups */
TR0 = 1; /* TR0: Run Counter T0 */
}
return(err);
}
/****************************************************************************/
/*EEpromRead(address) - Read 2 bytes from Internaal EEPROM */
/*Input: unsigned int address - addres of first byte to read */
/*Output: unsigned int value - value = MSB*256+LSB; */
/****************************************************************************/
unsigned int EEpromRead(unsigned int address)
{
unsigned int b_addr, value;
b_addr = address * 2;
EA = 0x00; /* Disable All Interrups */
WMCON |= EEMEN; /* enable EEPROM accesses */
value = XBYTE[b_addr + 1];
value *= 256;
value += XBYTE[b_addr];
WMCON ^= EEMEN; /* disable EEPROM accesses */
EA = 0x01; /* Enable All Interrups */
return value;
}