#define value4 0x0004
#define value5 0x0005
main(){
unsigned char testarr1[] = "String 1";
unsigned char testarr2[] = "String 2";
unsigned char disarr1[9]; // array 1
unsigned char disarr2[9]; // array 2
Write_String_EEPROMx(8,testarr1,value4); // writing to EEPROM
Write_String_EEPROMx(8,testarr2,value5);
Read_String_EEPROMx(8,disarr1,value4); // Read from EEPROM
Read_String_EEPROMx(8,disarr2,value5);
XLCDCommand(0x94);
XLCDPutRamString((const char)disarr1); // display on LCD.
XLCDCommand(0xD4);
XLCDPutRamString((const char)disarr2);
}
void Write_String_EEPROMx(unsigned char length, unsigned char *arr,unsigned int Address)
{
EEPROM_WP_Disable;
WaitI2C(10000); // Inital delay
add.value = Address;
IdleI2C();
StartI2C();
IdleI2C();
MasterWriteI2C(EEPROM_WRITE_ID); // Write Control byte
IdleI2C();
while(I2CSTATbits.ACKSTAT);
MasterWriteI2C(add.msb); // write MSB Address
IdleI2C();
while(I2CSTATbits.ACKSTAT);
MasterWriteI2C(add.lsb); // write LSB Address
IdleI2C();
while(I2CSTATbits.ACKSTAT);
while(length--)
{
MasterWriteI2C(*arr++); // Write data byte
IdleI2C();
while(I2CSTATbits.ACKSTAT);
} // write string
while(I2CSTATbits.ACKSTAT);
StopI2C();
IdleI2C();
EEPROM_WP_Enable;
}
unsigned char Read_String_EEPROMx(unsigned int length, unsigned char *arr, unsigned int Address)
{
WaitI2C(10000);
add.value = Address;
IdleI2C();
StartI2C();
IdleI2C();
MasterWriteI2C(EEPROM_WRITE_ID); // Write Control byte
IdleI2C();
MasterWriteI2C(add.msb); // write MSB Address
IdleI2C();
MasterWriteI2C(add.lsb); // write LSB Address
IdleI2C();
RestartI2C();
IdleI2C();
MasterWriteI2C(EEPROM_READ_ID); // Read Control byte
IdleI2C();
while( length > 1 )
{
*arr++ = MasterReadI2C();
IdleI2C();
Nop();
AckI2C();
IdleI2C();
length--;
*arr = '\0';
}
*arr++ = MasterReadI2C();
*arr = '\0';
IdleI2C();
NotAckI2C();
IdleI2C();
StopI2C();
IdleI2C();
return 1;
}