阅读以下代码,需具备以下条件:
1. Keil与Proteus联调。
单一主程序如下,不需其他头、库文件。
#include <reg51.h>
#include <intrins.h>
sbit SCL = P3^3;
sbit SDA = P3^4;
/*
void Delay() //5us,标准51单片机适用,@12.000MHz
{
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
}
void Delay6ms() //标准51单片机适用,@12.000MHz
{
unsigned char i, j;
i = 12;
j = 169;
do
{
while (--j);
} while (--i);
}
*/
void Delay() //5微秒,STC15W单片机适用,@12.000MHz
{
unsigned char i;
_nop_();
_nop_();
i = 12;
while (--i);
}
void Delay6ms() //STC15W 单片机适用@12.000MHz
{
unsigned char i, j;
i = 71; //71
j = 6;
do
{
while (--j);
} while (--i);
}
void IIC_Start()
{
SDA=1;
SCL=1;
Delay();
SDA=0;
Delay();
SCL=0;
}
bit IIC_Get_Ack()
{
bit ackOK;
SDA=1;//释放