这是电路图,这是从这个项目中获得的文件里边有电路图和仿真文件:http://www.51hei.com/bbs/dpj-22586-1.html
下面是 i2c.c文件:
#include
#include “i2c.h”
#include “delay_ms.h”
void delay()
{
;;
}
void i2cinit()//总线初始化
{
SDA = 1;
delay();
SCL = 1;
delay();
}
void start()//发动信号
{
SDA = 1;
SCL = 1;
delay();
SDA = 0;
delay();
}
void stop()//中止信号
{
SDA = 0;
delay();
SCL = 1;
delay();
SDA = 1;
delay();
}
void respons()//应对信号
{
unsigned char i = 0;
SCL = 1;
delay();
while(SDA == 1 && i < 255)//等候应对,过一段时间不应对退出循环
i++;
SCL = 0;
delay();
}