SDA=0;
SCL=1;
temp=Data<<1; //左移
Data=temp;
BitCounter--;
}while(BitCounter);
SCL=0;
}
//读一个字节的数据,并返回该字节值
uchar Read(void)
{
uchar temp=0;
uchar temp1=0;
uchar BitCounter=8;
SDA=1;
do{
SCL=0;
NOP;
SCL=1;
NOP;
if(SDA) //如果SDA=1
temp=temp|0x01;
else
temp=temp&0xfe;
if(BitCounter-1)
{
temp1=temp<<1;
temp=temp1;
}
BitCounter--;
}while(BitCounter);
return(temp);
}?
4 结束语
由于该系统可通过单片机给MAX517发送0-255的数字量,并且可用数码管显示,同时,用示波器还可观测相应的电压变化,直观性非常好。同样,该程序对单片机与MAX518、MAX519等的通信都具有参考价值。