本帖最后由 yxdbc2008 于 2017-7-5 15:05 编辑
void write_add(uchar address,uchar date)
{
start();
write_byte(0xa0);
respons();
write_byte(address);
respons();
write_byte(date);
respons();
stop();
}
char read_add(uchar address)
uchar date;
start();
write_byte(0xa0);
respons();
write_byte(address);
respons();
start();
write_byte(0xa1);
respons();
date=read_byte();
stop();
return date;
}
原代码如上,分别是指定一个地址写一个字节,和指定地址读取一个字节。其中write_byte和read_byte是读写一个字节的子函数。如下
void write_byte(uchar date)
{
uchar i,temp;
temp=date;
for(i=0;i<8;i++)
{
temp=temp<<1;
scl=0;
delay0();
sda=CY;
delay0();
scl=1;
delay0();
}
scl=0;
delay0();
sda=1;
delay0();
}
uchar read_byte()
{
uchar i,k;
scl=0;
delay0();
sda=1;
delay0();
for(i=0;i<8;i++)
{
scl=1;
delay0();
k=(k<<1)|sda;
scl=0;
delay0();
}
return k;
}
但我看不懂实现原理,求指导
|