大家帮忙看下代码,为什么写入的是数据是05,而读出来是别的数据?
下面是代码请大家帮忙看看!
void statr()
{
SDA=1;
delay1();
SCL=1;
delay1();
SDA=0;
delay1();
}
void stop()
{
SDA=0;
delay1();
SCL=1;
delay1();
SDA=1;
delay1();
}
void acknow()
{
SCL=1;
delay1();
if(SDA==0)
delay1();
SCL=0;
delay1();
}
void write1byte(unchar addr)
{
unchar run;
run=addr;
for(x=0;x<8;x++)
{
SCL=0;
delay1();
run=run<<1;
SDA=CY;
delay1();
SCL=1;
delay1();
}
SCL=0;
delay1();
SDA=1;
delay1();
}
unchar read1byte()
{
unchar com;
for(x=0;x<8;x++)
{
SCL=1;
delay1();
com=com<<1|SDA;
SCL=0;
delay1();
}
return(com);
}
main()
{
statr();
write1byte(0xa0);
acknow();
write1byte(0x00);
acknow();
write1byte(0x04);
acknow();
write1byte(0x05);
acknow();
stop();
delay(100);
statr();
write1byte(0xa0);
acknow();
write1byte(0x00);
acknow();
write1byte(0x04);
acknow();
statr();
write1byte(0xa1);
acknow();
aa=read1byte();
stop();
P2=0X01;
//P1=0XFD;
P37=1;
P0=tabol[aa];
P37=0;
delay(50);
while(1);
}