请问有没有高手能帮我看看这个程序哪有错误啊,这个是关于I2C总线的一个程序,我的本意是发光二级管依次像流水灯一样亮个等,最后第五个灯保持亮,但是这个程序只有第一个灯一直亮,其他都没有反应
#include<reg52.h>
#include <intrins.h>
#define uint unsigned int
#define uchar unsigned char
sbit scl=P1^5;
sbit sda=P3^6;
void reply()
{
uchar i,j;
for(i=200;i>0;i--)
for(j=200;j>0;j--);
}
void delay()
{
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
}
void init()
{
sda=1;
scl=1;
}
void start()
{
sda=1;
delay();
scl=1;
delay();
sda=0;
delay();
scl=0;
delay();
}
void stop()
{
sda=0;
delay();
scl=1;
delay();
sda=1;
delay();
scl=0;
delay();
}
void write_byte(uchar byte)
{
uchar i, temp;
temp=byte;
for(i=1;i<9;i++)
{
scl=0;
delay();
temp=(temp<<1);
sda=CY;
delay();
scl=1;
delay();
}
sda=1;
delay();
}
uchar read_byte()
{
uchar i,z=0;
sda=1;
delay();
scl=0;
delay();
for(i=1;i<9;i++)
{
scl=1;
delay();
z=(z|sda);
z=(z<<1);
scl=0;
delay();
}
return(z);
}
void ack()
{
uchar j=0;
sda=1;
delay();
scl=0;
delay();
scl=1;
delay();
while((sda==1)&&(j<255))
j++;
}
void main()
{
uchar y,x=0,add0=0xa0,add1=0xa1;
init();
start();
write_byte(add0);
ack();
write_byte(0);
ack();
while(x<250)
{
write_byte(0);
ack();
x++;
}
stop();
delay();
start();
delay();
x=0;
write_byte(add0);
ack();
write_byte(0);
ack();
write_byte(add1);
ack();
while(x<250)
{
P0=read_byte();
ack();
x++;
}
stop();
reply();
reply();
reply();
reply();
reply();
start();
x=0;
write_byte(add0);
ack();
write_byte(0) ;
ack();
y=0xfe;
while(x<5)
{
write_byte(y);
ack();
x++;
y=_crol_(y,1);
}
stop();
delay();
start();
delay() ;
x=0;
write_byte(add0);
ack();
write_byte(0);
ack();
write_byte(add1);
ack();
while(x<5)
{
P0=read_byte();
reply();
x++;
}
stop();
while(1);
} |
|