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
| #include<lpc214x.h>
void i2c_start()
{
I2C0CONSET=1<<5; // start falg bit 1
}
void i2c_stop()
{
I2C0CONSET=1<<4; // stop falg bit 1
}
void i2c_init()
{
//for master transmitter mode
I2C0CONSET=1<<6; //i2c enble I2EN bit
I2C0SCLH=80;
I2C0SCLL=70;
}
int main()
{
PINSEL0=(1<<4) | (1<<6) ; //for SCL and SDA functiong
IODIR0= (1<<2) | (1<<3); // for making SDA and SCL output
I2C0CONCLR=0x6C;
i2c_init();
i2c_start();
while(I2C0STAT != 0x08);
I2C0DAT = 0xA0;
while(I2C0STAT != 0x28);
I2C0DAT = 0x00;
while(I2C0STAT != 0x28);
I2C0DAT = 0x00;
while(I2C0STAT != 0x28);
I2C0DAT = 12;
while(I2C0STAT != 0x28);
i2c_stop();
I2C0CONCLR=(1<<2) |(1<<3) |(1<<5)|(1<<6);
while(1);
} |
is there ant problem in this code? it cant run
Last edited by a moderator: