Current location - Education and Training Encyclopedia - Graduation thesis - Design of traffic light control based on 5 1 single chip microcomputer
Design of traffic light control based on 5 1 single chip microcomputer
# include & ltreg 5 1 . h & gt;

# Define uchar unsigned characters

# Define uint unsigned integer

sbit red_a=p0^0; //East-west light

sbit yellow_a=p0^ 1;

sbit green_a=p0^2;

sbit red_b=p0^3; //North-South light

sbit yellow_b=p0^4;

sbit green_b=p0^5;

uchar Flash_Count=0,Operation _ Type = 1; //Flash times, operation type variable

100 cases of single-chip computer C language programming training-based on 805 1 and PROTEUS simulation.

five

Ni Jifeng, School of Information and Electromechanical Engineering, Shanghai Normal University

//delay

Invalid delay (uint x)

{

Ucal I;

And (x-) for (I = 0; I< 120; i++);

}

//Traffic light switching

Void traffic lights ()

{

Switch (operation type)

{

Case 1: // East-west green light, north-south red light.

RED _ A = 1; YELLOW _ A = 1; GREEN _ A = 0;

RED _ B = 0; YELLOW _ B = 1; GREEN _ B = 1;

Delems (2000);

operation _ Type = 2;

Break;

Situation 2://Things flash yellow and the green light goes out.

Delems (300);

Yellow _ A = ~ yellow _ a; GREEN _ A = 1;

if(++Flash_Count! = 10) returns; //Flashes 5 times

flash _ Count = 0;

operation _ Type = 3;

Break;

Case 3://East-west red light, north-south green light.

RED _ A = 0; YELLOW _ A = 1; GREEN _ A = 1;

RED _ B = 1; YELLOW _ B = 1; GREEN _ B = 0;

Delems (2000);

operation _ Type = 4;

Break;

Situation 4://The north and south yellow lights flash 5 times.

Delems (300);

YELLOW _ B = ~ YELLOW _ BGREEN _ B = 1;

if(++Flash_Count! = 10) returns;

flash _ Count = 0;

operation _ Type = 1;

}

}

//main program

void main()

{

while( 1)Traffic _ Light();

}