This is the traffic light program I wrote a few days ago, which is realized on 51 single chip microcomputer. The basic timing of the traffic light conversion is achieved, according to the time to change the traffic light conversion. Can download down to see the circuit diagram and the original program, the code to download it. I don’t put them all on.

The simulation schematic diagram is as follows:

Traffic light program based on 51 single chip microcomputer

MCU source program:

#include

sbit beiR=P1^0;

sbit beiY=P1^1;

sbit beiG=P1^2;

sbit nanR=P1^3;

sbit nanY=P1^4;

sbit nanG=P1^5;

uint a,b,c,type,j,i;

Void delay (uint x) / / delay

{

uchar i;

while(x–)for(i=0;i《120;i++);

}

void delay_ MS (uint q) / / delay

{

uint i,j;

for(i=q;i》0;i–)

for(j=141;j》0;j–);

}

Void shumaguan (uint K) / / nixie tube display

{

b=k/10;

c=k%10;

P3=11111101;

P2=smg_ DW; / / segment code

delay_ MS (20); / / delay 5ms

P3=11111110;

P2=smg_ DW [C]; / / segment selection code

delay_ MS (20); / / delay 5ms

}

main()

{

Tmod = 0x01; / / set timer T0 to work mode 1

TH0=(65536-50000)/256;

TL0=(65536-50000)%256;

Tr0 = 1; / / start t0 counting

ET0 = 1; / / t0 interrupt allowed

Ex0 = 1; / / allow external interrupt 0 interrupt

EA = 1; / / interrupt

It0 = 1; / / external interrupt 0 is allowed as edge trigger mode

A = 10; / / countdown 10s

type=1;

while(1){

switch(type)

{

Case 1: East West green light and South North red light

beiR=0;beiY=1;beiG=1;

nanR=1;nanY=1;nanG=0;

shumaguan(a);

break;

Case 2: the yellow light flashes in the east-west direction and the green light turns off

if(a%2! =0)

{

beiR=1;beiY=0;beiG=1;

}

if(a%2==0)

{

beiR=1;beiY=1;beiG=1;

}

shumaguan(a);

break;

The red light is east-west, and the green light is north-south

beiR=1;beiY=1;beiG=0;

nanR=0;nanY=1;nanG=1;

shumaguan(a);

break;

Case 4: / / the North-South yellow light flashes three times

if(a%2! =0)

{

nanR=1;nanY=0;nanG=1;

}

if(a%2==0)

{

nanR=1;nanY=1;nanG=1;

}

shumaguan(a);

break;

}

}

}

Leave a Reply

Your email address will not be published. Required fields are marked *