51單片機(jī)i2c存儲器24c02驅(qū)動程序
這是電路圖,這是從這個項(xiàng)目中取得的文件里面有電路圖和仿真文件: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()//應(yīng)答信號
{
unsigned char i = 0;
SCL = 1;
delay();
while(SDA == 1 && i < 255)//等待應(yīng)答,過一段時間不應(yīng)答退出循環(huán)
i++;
SCL = 0;
delay();
}
評論