(改自周立功软件包)
#include
#include
#define uchar unsigned char
#define uint unsigned int
extern void Delay1us(unsigned char );
sbit SDA=P1^6;
sbit SCL=P1^7;
bit ack;
void Start_I2c()
{
SDA=1;
Delay1us(1);
SCL=1;
Delay1us(5);
SDA=0;
Delay1us(5);
SCL=0;
Delay1us(2);
}
void Stop_I2c()
{
SDA=0;
Delay1us(1);
SCL=1;
Delay1us(5);
SDA=1;
Delay1us(4);
}
void SendByte(uchar c)
{
uchar BitCnt;
for(BitCnt=0;BitCnt<8;BitCnt++)
{
if((c<
else SDA=0;
Delay1us(1);
SCL=1;
Delay1us(5);
SCL=0;
}
Delay1us(2);