Dummy write operation
So once your done with writing data into the EEPROM,you would want to read from the location where you have written into.
The diagram above clearly shows the steps how it needs to be done.
CODE:
#include<lpc214x.h> // standard header file
#include”appdef.h” // defining bits,example:#define BIT0 0x01<<0
#include”armlcd.h” // initialisations for lcd
#define led_port BIT0+BIT1+BIT8+BIT9+BIT25+BIT15+BIT12+BIT28
int c=0;
int r=0,dw=1,ss=0,rs=0,j;
char ch;
__irq void led(void)
{
switch(I2C0STAT)
{
case 0x08 : //lcd(‘s’); // 1.start
I2C0CONCLR=BIT3;
I2C0DAT=0xa0; // dummy write
break;
case 0x10 :// lcd(‘b’); // 4. repeated start condition status
I2C0CONCLR=BIT3+BIT5;
I2C0DAT=0xa1; // read
break;
case 0x18 : //lcd(‘a’); // 2. write ack
I2C0CONCLR=BIT3+BIT5;
I2C0DAT=0x00; // memory address
break;
case 0x28 : //lcd(‘k’); // 3. ack
I2C0CONCLR=BIT3;
I2C0CONSET|=BIT5; // repeated start bit
break;
case 0x40 : //lcd(‘r’); // 5.read ack
I2C0CONCLR=BIT3;
I2C0CONSET=BIT2; // aa flag
break;
case 0x48 : lcd(‘l’);
I2C0CONCLR=BIT3;
break;
case 0x50 : I2C0CONCLR=BIT3; // 6.start receiving data
ch=I2C0DAT;
lcd(ch);
if(dw==9)
{
I2C0CONCLR=BIT2; // sending a no ack after reading 10 bytes
}
dw++;
break;
case 0x58 ://lcd(‘n’); // 7.stop bit
I2C0CONCLR=BIT3;
I2C0CONSET=BIT4;
break;
default:lcd(‘f’);
I2C0CONCLR=BIT3;
break;
}
VICVectAddr=0x00;
}
int main()
{
rs_clr();
en_clr();
lcd_init();
rs_set();
en_clr();
//lcd(‘i’);
PINSEL0=BIT4+BIT6;
VICVectCntl0=0x29;
VICVectAddr0=(unsigned) led;
VICIntEnable=BIT9;
I2C0CONSET=BIT6;
I2C0CONCLR=BIT3;
I2C0SCLH=0x4B;
I2C0SCLL=0x4B;
I2C0CONSET|=BIT5; //start
while(1);
}
void lcd_init()
{
unsigned int i;
PINSEL0 = 0x00000000;
lcd_dir_write(); // output port
for (i=0;i<1000;i++);
lcd(0x33);
lcd(0x32);
lcd(0x28);
lcd(0x0e);
lcd(0x01);
lcd(0x06);
lcd(0x80);
for (i=0;i<1000000;i++);
}
void lcd(unsigned char val)
{
lcd1(val>>4);
lcd1(val);
}
void lcd1(unsigned char c)
{
unsigned int i;
IOCLR0 = 0x00f00000;
IOSET0 = (c<<20); // d4 connected to 20th port pin
en_set();
for (i=0;i<1000000;i++);
en_clr();
}