1. Hardware Solution
This design can simulate the basic traffic control system, using red, green and yellow lights to indicate the occurrence of no-entry, pass and waiting signals, and can also display countdown. The buttons can control the no-entry, late night mode, reset, east-west passage, north-south passage, time addition, time subtraction, switching and other functions. There are four two-digit cathode digital tubes, one for each of the southeast, northwest and northeast to display the time. The cathodes of the four digital tubes are connected to the P1 port of the STC89C51, and the anodes are connected to the 74HC245 chip. The 74HC245 chip is controlled through the P0 port to play a driving and amplifying role.
Main hardware: 51 single-chip microcomputer + minimum system + digital tube display module + LED indicator module + button module;
2. Design function
(1) This design uses a four-directional digital tube to display time, which is more in line with the design of a real traffic light;
(2) 7 buttons: reset, night mode, emergency mode, set time, time increase, time decrease, and debug confirmation button;
(3) Night mode: After pressing the "Night mode" button, the yellow lights in the four directions flash;
(4) Emergency mode: When an ambulance or fire truck passes by, press the "Emergency mode" button and all red lights in the four directions will light up;
(5) The travel time in the east-west direction and the north-south direction can be set separately, which simulates the main roads and branch roads in actual traffic.
3. Design Schematic
(1) The schematic diagram is mainly designed using AD software, as shown in the figure:
(2) The Protues simulation diagram is as follows:
4. Software Design
(1) Program flow chart
(1) Main program source code:
//Main program
void main()
{
TMOD=0X11; //Timer setting
TH1=0X3C;
TL1=0XB0;
TH0=0X3C; //Timer 0 is initialized to 0.05S
TL0=0XB0;
EA=1; //Open the general interrupt
ET0=1; //Timer 0 interrupt is enabled
ET1=1; //Timer 1 interrupt is enabled
TR0=1; //Start timing 0
TR1=0; //Close timer 1
logo(); //Power on initialization
P2=0Xc3; //Start with default status, green light for east and west, yellow light for north and south
sec_nb=sec_dx+5; //The default north-south travel time is 5 seconds longer than the east-west travel time
while(1) //main loop
{
key(); //Call the key scanning program
display(); //Call the display program
}
}
//Function definition part
void key(void) //key scan subroutine
{
if(k1!=1) //When K1 (time plus) is pressed
{
display(); //Call display for delay and debounce
if(k1!=1) //If confirmed, press
{
TR0=0; //Turn off the timer
shanruo=0; //Blinking flag off
P2=0x00; //Display off
TR1=0; //Start timing 1
if(set==0) //Set key pressed
set_timedx++; //North and South plus 1S
else
set_timenb++; //add 1S to something
if(set_timenb==100)
set_timenb=1;
if( set_timedx == 100 )
set_timedx=1; // add to 100 and set to 1
sec_nb=set_timenb; //Assign the set value to the east, west, south, and north
sec_dx=set_timedx;
do
{
display(); //Call display for delay
}
while(k1!=1); //Wait for the button to be released
}
}
if(k2!=1) //When the K2 (time minus) button is pressed
{
display(); //Call display for delay and debounce
if(k2!=1) //If confirmed, press
{
TR0=0; //Turn off timer 0
shanruo=0; //Blinking flag off
P2=0x00; //Display off
TR1=0; //Turn off timer 1
if(set==0)
set_timedx--; //South-North minus 1S
else
set_timenb--; //subtract 1S from something
if(set_timenb==0)
set_timenb=99;
if( set_timedx==0 )
set_timedx=99; //decrease to 1 and reset to 99
sec_nb = set_timenb; // Assign the set value to the east, west, south, and north
sec_dx=set_timedx;
do
{
display(); //Call display for delay
}
while(k2!=1); //Wait for the button to be released
}
}
if(k3!=1) //When the K3 (confirm) key is pressed
{
display(); //Call display for delay and debounce
if(k3!=1) //If confirmed, press
{
TR0=1; //Start timer 0
sec_nb=set_timenb; //Resume from interruption, still display the set value
sec_dx=set_timedx; //Display the set time
TR1=0; //Turn off timer 1
if(set==0) //Time counts down to 0
{
P2=0X00; //Display off
Green_dx=1; //The green light is on
Red_nb=1; //North and South red lights are on
sec_nb=sec_dx+5; //Return to initial value
}
else
{
P2=0x00; //Green light for north and south, red light for east and west
Green_nb=1;
Red_dx=1;
sec_dx=sec_nb+5;
}
}
}
if(k4!=1) //When K4 (switch) key is pressed
{
display(); //Call display for delay and debounce
if(k4!=1) //If confirmed, press
{
TR0=0; //Turn off timer 0
set=!set; //Invert the set flag to switch the adjustment direction
TR1=0; //Turn off timer 1
dx_nb=set;
do
{
display(); //Call display for delay
}
while(k4!=1); //Wait for the button to be released
}
}
if(k5!=1) //When the K5 (disable) key is pressed
{
display(); //Call display for delay and debounce
if(k5!=1) //If confirmed, press
{
TR0=0; //Turn off the timer
P2=0x00; //Display off
Red_dx=1;
Red_nb=1; //Set all lights to red
TR1=0;
sec_dx=00; //The time in all four directions is 00
sec_nb=00;
do
{
display(); //Call display for delay
}
while(k5!=1); //Wait for the button to be released
}
}
if(k6!=1) //When K6 (night mode) is pressed
{
display(); //Call display for delay and debounce
if(k6!=1) //If confirmed, press
{
TR0=0; //Turn off the timer
P2=0x00;
TR1=1;
sec_dx=00; //The time in all four directions is 00
sec_nb=00;
do
{
display(); //Call display for delay
}
while(k6!=1); //Wait for the button to be released
}
}
}
Previous article:Design of electronic perpetual calendar based on 51 single chip microcomputer
Next article:Tetris based on 51 single chip microcomputer
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- EEWORLD University Hall----Electrical Engineering and Electronic Technology (China University of Mining and Technology)
- 【EasyARM-RT1052 Review】+ MQTTClient transplantation
- A set of common codes suitable for small projects
- The universal tool for impedance measurement
- Advice for beginners of DLP4500 light modulation.
- RC parallel circuit bandwidth problem - 3db bandwidth position problem, please help
- EEWORLD University - In-depth technical training on battery management
- 2-way ADC0808 measurement digital tube display assembly program
- CY8CKIT-149 PSoC 4100S Review (1)
- STM32F765@216MHz running NES emulator [code] [video]