//--------------------------------------------------------------------------------------------------
// 函数名称: IICSendByte
// 入口参数: ch
// 函数功能: 发送一个字节
//--------------------------------------------------------------------------------------------------
void IICSendByte(unsigned char ch)
{
unsigned char idata n=8; // 向SDA上发送一位数据字节,共八位
while(n--)
{
if((ch&0x80) == 0x80) // 若要发送的数据最高位为1则发送位1
{
SDA = 1; // 传送位1
SCL = 1;
delayNOP();
SDA = 0;
SCL = 0;
}
else
{
SDA = 0; // 否则传送位0
SCL = 1;
delayNOP();
SCL = 0;
}
ch = ch<<1; // 数据左移一位 ,step to lowwer data bit
}
}
原来 IIC 通讯发送数据是一位位的方式,而且从高位到低位依次发送
只是还不大明白为什么需要 delayNOP();呢 ?