char E_Write(int addr, unsigned char* ch, char len)
{
I2C_Start(); // Send a start condition
I2C_Write(WRITE); // chip write address
if(!I2C_nack()) return 0; // wait for ack
if(WRITE == 0xA0)
{
I2C_Write((unsigned char)( addr >> 8 & 0xff));// Not used if out if single byte address
if(!I2C_nack()) return 0; // wait for ack
}
if(!(WRITE==0x90))
{
I2C_Write((unsigned char) addr & 0xff); // low address (ADC not used)
if(!I2C_nack()) return 0; // wait for ack
}
if(len == 1)
{
I2C_Write(*ch);
if(!I2C_nack()) return 0;
}
else if(len > 1)
{
while(len--)
{
I2C_Write(*ch++); // Write values to Eeprom
if(!I2C_nack()) return 0;
}
}
else
{
while(*ch != 0)
{
I2C_Write(*ch++); // Write values to Eeprom
if(!I2C_nack()) return 0;
}
I2C_Write(0); // Write values to Eeprom
if(!I2C_nack()) return 0;
}
I2C_Stop(); // Send a stop.
return 1; // All went well
}