hi
I am using keil and lpc2138 interface with 24lc512 eeprom by using i2c protocol but i am facing a problem below is my program
Code C - [expand] |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
| #include<lpc213x.h>
#define RS 16
#define RW 17
#define EN 18
void delay(unsigned int j)
{ unsigned int q,w;
for(q=0;q<j;q++)
for(w=0;w<j;w++);
}
void cmd(unsigned char a)
{
IOCLR1=0xffffffff;
IOCLR0=0xff<<8;
IOSET0=a<<8;
IOSET1=1<<18;
delay(5);
IOCLR1=1<<18;
}
void data(unsigned char b)
{
IOCLR1=0xffffffff;
IOSET1=1<<16;
IOCLR0=0xff<<8;
IOSET0=b<<8;
IOSET1=1<<18;
delay(5);
IOCLR1=1<<18;
}
void wrte(unsigned int adr,unsigned char dat)
{
I2C0CONCLR=0x000000ff;
I2C0CONSET=1<<6;
I2C0CONSET=0x20;
while(I2C0STAT!=0x08);
I2C0CONCLR=0x28;
I2C0DAT=0xA0;
I2C0CONCLR=0x08;
while(I2C0STAT!=0x18);
I2C0DAT=(adr&0xff00)>>8;
I2C0CONCLR=0x08;
while(I2C0STAT!=0x28);
I2C0DAT=(adr&0x00ff);
I2C0CONCLR=0x08;
while(I2C0STAT!=0x28);
I2C0DAT=dat;
I2C0CONCLR=0x08;
while(I2C0STAT!=0x28);
I2C0CONCLR=0x08;
I2C0CONSET=1<<4;
delay(10);
}
lcd_init()
{
cmd(0x38);
cmd(0x0E);
}
void main()
{ unsigned int l;
IODIR0=0xffffffff;
IODIR1=0xffffffff;
PINSEL0=((1<<4)|(1<<6));
lcd_init();
cmd(0x80);
data(0x39);
VPBDIV=0x01;
I2C0SCLL=80;
I2C0SCLH=70;
wrte(0,10); cmd(0x94);data(0x38);
while(1)
{
I2C0CONCLR = 0x000000ff;
I2C0CONSET=1<<6;
I2C0CONSET=1<<5;
while(I2C0STAT!=0x08);
I2C0CONCLR=0x08;
I2C0DAT=0xA0;
while(I2C0STAT!=0x18);
I2C0CONCLR=0x08;
I2C0DAT=(0x00&0xff00)>>8;
while(I2C0STAT!=0x28);
I2C0CONCLR=0x08;
I2C0DAT=0x00&0x00ff;
while(I2C0STAT!=0x28);
I2C0CONCLR=0x08;
//I2C0CONSET=1<<5;
//while(I2C0STAT!=0x10);
I2C0DAT=0xA1;
while(I2C0STAT!=0x18);
I2C0CONCLR=0x08;
l=I2C0DAT;
while(I2C0STAT!=0x58);
I2C0CONCLR=0x08;
I2C0CONSET=1<<4;
cmd(0xc0);
data(48+((l/10)%10));
data(48+(l%10));
}
} |
is there any mistake in the above program
Last edited by a moderator: