
/******************************************************************************
* NAME:        readAt                                                         *
* DESCRIPTION: This function reads a byte at a specified address              *
******************************************************************************/
unsigned char readAt(unsigned int address)
{
    unsigned char data1;
    i2c_Start();                    // make a start condition
    i2c_SendAddress(ROM, 0);        // 0 write 1 read
    i2c_ReadAcknowledge();          // wait for acknowledge from eeprom
    i2c_SendByte(address >> 8);     // send upper byte of address to eeprom
    i2c_ReadAcknowledge();          // wait for acknowledge from eeprom
    i2c_SendByte(address & 0xff);   // send lower byte of address to eeprom
    i2c_ReadAcknowledge();          // wait for acknowledge from eeprom
    i2c_Start();                    // make a start condition
    i2c_SendAddress(ROM, 1);        // issue read command
    i2c_ReadAcknowledge();          // wait for acknowledge from eeprom
    data1 = (char)i2c_ReadByte();   // get data out of eeprom
    i2c_Stop();                     // finish the process
    return(data1);                  // give data back to caller
}

/******************************************************************************
* NAME:        writeAt                                                        *
* DESCRIPTION: This function writes a byte to a specified address             *
******************************************************************************/
void writeAt(unsigned int addr, unsigned char data)
{
    i2c_Start();                // start condition
    i2c_SendAddress(ROM, 0);    // 0 = write, 1 = read, ROM is 0xA0 
    i2c_ReadAcknowledge();      // wait for acknowledge from EEPROM
    i2c_SendByte(addr >> 8);    // send upper address byte
    i2c_ReadAcknowledge();      // wait for acknowledge from EEPROM
    i2c_SendByte(addr & 0xff);  // send lower address byte
    i2c_ReadAcknowledge();      // wait for acknowledge from EEPROM
    i2c_SendByte(data);         // write the data to EEPROM
    i2c_ReadAcknowledge();      // wait for acknowledge from eeprom
    i2c_Stop();                 // stop
}
