整个程序结构问题:
1、没有程序说明
2、定义没有注释(I/O分配)
3、主程序结构体还是偏大
#include<reg52.h>
sbit RED1=P0^0;
sbit YELLOW1=P0^1;
sbit GREEN1=P0^2;
sbit RED2=P0^4;
sbit YELLOW2=P0^5;
sbit GREEN2=P0^6;
void delay(long dly)
{
while(dly--);
}
void main()
{
signed int i,x,y,z;
while(1)
{
RED1=0;YELLOW1=1;GREEN1=1;//???
RED2=1;YELLOW2=1;GREEN2=0;//???
x=10,y=7,z=3;
for(i=0;i<10;i++)
{
P2=((x/10)<<4)+x%10; //nanbeihong
x--;
if(y>0)
{
P1=((y/10)<<4)+y%10; //dongxilv
y--;
delay(15000);
}
else
{
RED2=1;YELLOW2=0;GREEN2=1; //dongxihuang
P1=((z/10)<<4)+z%10;
RED2=1;YELLOW2=0;GREEN2=1;
delay(7500);
RED2=1;YELLOW2=1;GREEN2=1;
delay(7500);
z--;
}
}
RED1=1;YELLOW1=1;GREEN1=0;//???
RED2=0;YELLOW2=1;GREEN2=1;//???
x=18,y=15,z=3;
for(i=0;i<18;i++) //dongxihong
{
P1=((x/10)<<4)+x%10;
x--;
if(y>0)
{
P2=((y/10)<<4)+y%10; //nanbeilv
y--;
delay(15000);
}
//nanbeihuang
else
{
RED1=1;YELLOW1=0;GREEN1=1;
P2=((z/10)<<4)+z%10;
RED1=1;YELLOW1=0;GREEN1=1;
delay(7500);
RED1=1;YELLOW1=1;GREEN1=1;
delay(7500);
z--;
}
}
}
}