iic底层驱动
#include "iic.h"
void Delay10us() //@11.0592MHz
{
unsigned char i;
_nop_();
i = 25;
while (--i);
}
//总线启动条件
void IIC_Start(void)
{
sda = 1;
scl = 1;
// IIC_Delay(DELAY_TIME);
Delay10us() ;
sda = 0;
Delay10us() ;
scl = 0;
}
//总线停止条件
void IIC_Stop(void)
{
sda = 0;
scl = 1;
Delay10us() ;
sda = 1;
Delay10us() ;
}
//发送应答
void IIC_SendAck(bit ackbit)
{
scl = 0;
sda = ackbit; // 0:应答,1:非应答
Delay10us() ;
scl = 1;
Delay10us() ;
scl = 0;
sda = 1;
Delay10us() ;
}
//等待应答
bit IIC_WaitAck(void)
{
bit ackbit;
scl = 1;
Delay10us() ;
ackbit = sda;
scl = 0;
Delay10us() ;
return ackbit;
}
//通过I2C总线发送数据
void IIC_SendByte(unsigned char byt)
{
unsigned char i;
for(i=0; i<8; i++)
{
scl = 0;
Delay10us() ;
if(byt &am