|
程序片段如下:
unsigned char I2cSendByte(unsigned char dat)
{
unsigned char a=0,b=0;//最大255,一個(gè)機(jī)器周期為1us,最大延時(shí)
255us。
for(a=0;a<8;a++)//要發(fā)送8 位,從最高位開(kāi)始
{
SDA=dat>>7; //起始信號(hào)之后SCL=0,所以可以直接改變SDA 信
號(hào)
dat=dat<<1;
Delay10us();
SCL=1;
Delay10us();//建立時(shí)間>4.7us
SCL=0;
Delay10us();//時(shí)間大于4us
}
SDA=1;
Delay10us();
SCL=1;
while(SDA)//等待應(yīng)答,也就是等待從設(shè)備把SDA 拉低
{
b++;
if(b>200) //如果超過(guò)2000us 沒(méi)有應(yīng)答發(fā)送失敗,或者為非應(yīng)答,
表示接收結(jié)束
{
SCL=0;
Delay10us();
return 0;
}
}
SCL=0;
Delay10us();
return 1;
}
void At24c02Write(unsigned char addr,unsigned char dat)
{
I2cStart();
I2cSendByte(0xa0);//發(fā)送寫(xiě)器件地址
I2cSendByte(addr);//發(fā)送要寫(xiě)入內(nèi)存地址
I2cSendByte(dat); //發(fā)送數(shù)據(jù)
I2cStop();
}
請(qǐng)問(wèn)unsigned char I2cSendByte(unsigned char dat)函數(shù)中黃色背景標(biāo)注的return,整個(gè)程序中都沒(méi)有對(duì)此返回值做什么操作,加此返回值顯得沒(méi)什么意義,請(qǐng)問(wèn)此返回值有什么作用?
先謝了
|
|