AD Package Library Component Library Collection:Package Library
Resource Directory:
This design
is based on the 51 microcontroller traffic light controller, with control, start, and yellow light flashing (Proteus simulation + program).
Simulation: Proteus 7.8
Program Compiler: Keil 4/Keil 5
Programming Language: C Language
Number J012
Function Description:
Timing control of LED lights; display and flashing of digital tubes; reading and judging independent keys; setting and application of timers.
The microcontroller controls the traffic light LEDs for A and B directions, while displaying the remaining time on the digital tube. When the remaining time is less than 5 seconds, the digital tube flashes at a rate of 2 times per second, and the yellow light flashes for 5 seconds.
1. When the “Pause” button is pressed, the traffic light pauses changing; pressing it again resumes the changes;
2. When the A key is pressed, the A direction light is fully green, and the B direction is fully red;
3. When the B key is pressed, the B direction light is fully green, and the A direction is fully red;
4. Specific seconds can be modified in the program.
Simulation images (source files provided):
Program (source files provided):
The following is part of the program; the complete program can be obtained from the download link:
void main(){ EA=1; //Enable global interrupt InintTimer0(); //Initialize Timer0 while(1) { LEDScan(); //Digital tube and LED scanning KeyDriver(); //Keyboard driver scanning if(flag1s)//Execute once every 1S { flag1s=0; NS_time--; //Countdown for red and green lights decreases WE_time--; } }}void InintTimer0(){ TMOD |=0X01; TH0=0X4C; TL0=0X00; ET0=1; TR0=1;//Enable timer interrupt}void Timer0() interrupt 1{ TH0=0XBB; TL0=0X00; KeyScan(); if(++count500ms<12){ }else{ count500ms = 0; if(FilteFlag){//Flashing flag FilteFlag = 0; }else{ FilteFlag =1; } } if(++count1s<50) return; count1s=0; if(StaSysterm==NormalRun) flag1s=1; //During abnormal operation, the countdown does not decrease all_mode_flag1s =1;}
Material List:
Download Link for Materials:
Note: The simulation program and other source files need to be opened on a computer. Download to the computer and then use the decompression password to extract! Do not use a mobile phone to extract! For more resources, scan the QR code at the top of the article to search for related designs.