仿真图如上,由于时间关系没有加数码管做倒数显示,仿真内容,绿灯20s,黄灯5s,红灯60s,绿灯逆时针顺序逐渐点亮,每次只能一条车道行驶,就是一绿三红,在两灯变化时,最后5秒都会闪烁,然后改变。
代码
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit red1=P1^0;
sbit yellow1=P1^1;
sbit green1=P1^2;
sbit red2=P1^3;
sbit yellow2=P1^4;
sbit green2=P1^5;
sbit red3=P1^6;
sbit yellow3=P1^7;
sbit green3=P3^1;
sbit red4=P3^5;
sbit yellow4=P3^6;
sbit green4=P3^7;
uchar table[]={
0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
uint x,y;
uchar i,j;
void delay(uint time)
{
for(x=time;x>0;x--)
for(y=110;y>0;y--);
}
void deng()
{
red1=1;yellow1=1;green1=0;
red2=0;yellow2=1;green2=1;
red3=0;yellow3=1;green3=1;
red4=0;yellow4=1;green4=1;
delay(15000);
for(i=5;i>0;i--)
{
red1=1;yellow1=1;green1=0;
red2=1;yellow2=1;green2=1;
red3=0;yellow3=1;green3=1;
red4=0;yellow4=1