任一地址写入数据格式
uchar readbyte()
//读一个字节
{
uchar i,j,k;
SCL=0;
delay();
SDA=1;
for(i=0;i<8;i++)
{
SCL=1;
delay();
if(SDA==1)
j=1;
else
j=0;
k=(k<<1)|j;
SCL=0;
delay();
}
delay();
return k;
}
Void write_add(uchar address,
uchar info)
//指定地址写一个字节数据
{
start();
writebyte(0xa0);
respons();
writebyte(address);
respons();
writebyte(info);
respons();
stop();
}
uchar read_add(uchar address)
//指定地址读一个字节数据
{
uchar dd;
start();
writebyte(0xa0);
respons();
writebyte(address);
respons();
start();
writebyte(0xa1);
respons();
dd=readbyte();
stop();
return dd;
} |