我是这样发送字节和等待应答的(附程序):
void SendByte(uchar c)
{
uchar BitCnt;
//the length of data to be send is 8 bits
for(BitCnt=0;BitCnt <8;BitCnt++)
{
if(c&0x80)
{
SDA=1; //judge the sending bit
}
else
{
SDA=0;
}
_Nop();
SCL=1; //Set clock, and notice the device to receive
_Nop();
_Nop(); //Be sure the clock holding time > 4,7us
_Nop();
SCL=0;
c = c < < 1;
}
_Nop();
_Nop();
SDA=1; //The sending action is over
_Nop(); //and release the data line
_Nop();
SCL=1;
_Nop();
_Nop();
_Nop();
ack = !SDA; //judge whether the ack bit is received
SCL=0;
_Nop();
_Nop();
}