这是程序代码 求帮忙 指出错误!
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
void delay()
{ ; ; }
bit write=0;
sbit sda=P2^0;
sbit scl=P2^1;
void init()
{
scl=1;
sda=1;
}
void start()
{
sda=1;
delay();
scl=1;
delay();
sda=0;
delay();
}
void stop()
{
sda=0;
delay();
scl=1;
delay();
sda=1;
delay();
}
void respons()
{
uchar i=0;
scl=1;
delay();
while((sda==1)&&(i<255))
i++;
scl=0;
delay();
}
void delay1(uint xsm)
{
uint i,j;
for(i=xsm;i>0;i--)
for(j=110;j>0;j--);
}
void write_byte(uchar date)
{
uchar i,temp;
temp=date;
for(i=0;i<8;i++)
{
temp=temp<<1;
sda=CY;
scl=1;
delay();
scl=0;
delay();
}
scl=0;
delay();
sda=1;
delay();
}
uchar read_byte()
{
uchar i,k;
for(i=0;i<8;i++)
{
k=(k<<1)|sda;
delay();
scl=1;
delay();
scl=0;
delay();
}
delay();
return k;
}
void main()
{ uchar a;
init();
start();
write_byte(0xa0);
respons();
write_byte(0xaa);
respons();
write_byte(0xaa);
respons();
stop();
delay1(100);
start();
write_byte(0xa0);
respons();
write_byte(0xaa);
respons();
start();
write_byte(0xa1);
respons();
write_byte(0xaa);
a=read_byte();
a=P1;
stop();
while(1);
} |