Aiming at the purpose of realizing dual-mode control of the traffic light system. The software part of the circuit is designed by programming in C and the hardware part of the circuit is designed by taking the 89C52 single-chip microcomputer as the core, together with the infrared receiving module, the traffic light display module and other components. That is, the software part: write and verify the C program in the KEIL environment. The hardware part: control the display of the traffic light and the digital tube through the single-chip microcomputer, and the operation mode of the traffic light system can be switched by buttons or infrared remote control, that is, the normal mode and the rush hour mode. This system can ensure that vehicles and pedestrians have a longer time to cross the road in normal times. By switching the operation mode, this system can effectively prevent traffic jams and vehicle and personnel detention during rush hours. Compared with ordinary traffic light control systems, this system improves the efficiency of traffic control and ensures orderly traffic.
introduction
In real life, many traffic lights switch at a time interval. In this design, the traffic lights can switch the red-green light switching time according to the usual time or the rush hour. For example, the red light switching time is set to 40 seconds during the rush hour and 60 seconds during the usual time. This can effectively alleviate the phenomenon of running red lights in rush hours because the red light setting time is too long. At the same time, it can effectively alleviate traffic congestion.
1. Demonstration of traffic management plan
In 1968, the United Nations Agreement on Road Traffic and Road Signs and Signals defined the meaning of various signal lights: green light allows passage; red light prohibits passage; yellow light reminds people to pay attention to the red and green light status is about to switch. For the convenience of explanation, it is assumed that two main roads running east-west and north-south intersect at a crossroads. At the same time, in order to ensure the safety of pedestrians, four sidewalks A, B, C, and D are set up. As shown in Figure 1.
Figure 1. Schematic diagram of traffic lights at intersections
Intersection indicator light working conditions: When the east-west lane is red, vehicles are prohibited from passing through this lane, and pedestrians on the B and D sidewalks can cross the road; at the same time, the north-south lane is green, vehicles can pass through this lane, and pedestrians on the A and C sidewalks are prohibited from passing through for 60 seconds. The yellow light flashes for 5 seconds to warn vehicles and pedestrians that the red and green lights are about to switch. When the east-west lane is green, vehicles can pass through this lane, and pedestrians on the B and D sidewalks are prohibited from crossing the road; at the same time, the north-south lane is red, vehicles are prohibited from passing through this lane, and pedestrians on the A and C sidewalks are allowed to pass through for 60 seconds. In this cycle, vehicles can be guided to drive in an orderly manner and pedestrians can cross the road safely.
2 System Hardware Circuit Design
2.1 System Circuit Overview
This design is mainly composed of 89C52 single-chip microcomputer, traffic light display module, infrared receiving module, digital tube, buttons, etc.
The 89C52 single-chip microcomputer is the main controller of the system, controlling the coordinated work of other modules; the buttons and infrared receiving modules are used to switch the system working mode: normal mode or rush hour mode. That is, in normal mode, the red light is set for 60 seconds; in rush hour mode, the red light is set for 40 seconds. The traffic light display module is used to guide the passage of vehicles on each road. The digital tube is used to display the remaining switching time of the traffic lights, so that pedestrians can judge whether there is enough time to cross the road and whether to go or stop. Its main block diagram is shown in Figure 2.
Figure 2. System design block diagram [page]
2.2 Hardware Circuit Design
2.2.1 Controller selection
As the center of intelligent traffic control, the choice of controller is very important. The common ones we use are: (1) Field Programmable Gate Array FPGA; (2) Programmable Logic Controller PLC; (3) 51 series single-chip microcomputer, etc. This is a more practical system, so it is necessary to consider factors such as price and usage. The above three controllers can complete the intelligent control of traffic lights very well, while FPGA and PLC are simple to operate and complete, but the cost price is high and the cost performance is low. For this design, the 51 series single-chip microcomputer can fully realize its control, and it has good performance and low price. Therefore, the well-known 89C52 single-chip microcomputer is selected as the controller.
2.2.2 Principle of infrared transmission and reception
Figure 3 Schematic diagram of infrared transmission and reception
The universal infrared remote control system consists of two parts: the transmitting and receiving parts. It is controlled by the encoding/decoding special integrated circuit chip as shown in Figure 3. The working principle of the infrared receiving head: the built-in receiving tube converts the optical signal emitted by the infrared transmitting tube into a weak electrical signal, which is amplified by the internal amplifier of the IC, and then restored to the original code emitted by the remote control through automatic gain control, bandpass filtering, demodulation, and waveform shaping, and then input into the code recognition circuit on the appliance through the signal output pin of the receiving head.
2.2.3 Hardware circuit diagram
This design uses 89C52 single-chip microcomputer as the controller to control the normal operation of the system. This system has two operating modes, normal mode and rush hour mode. The system operation mode can be switched by button or infrared remote control. Button switching is suitable for on-duty personnel, while infrared remote control switching is suitable for traffic police patrol, which is convenient and fast. Now briefly introduce the working principle of the system: 89C52 single-chip microcomputer controls the digital tube to display the traffic light time through the latch, and the four groups of digital tubes in the east, west, north and south display the same time. P1^2~P1^7 controls the display of traffic lights. P1^2~P1^4 controls the display of the two groups of traffic lights in the east and west roads. These two groups of traffic lights display the same color indicator lights through the single-chip microcomputer control and the same switching time; and P1^5~P1^7 controls the display of the two groups of traffic lights in the north and south roads. These two groups of traffic lights also display the same color indicator lights through the single-chip microcomputer control and the same switching time. P3^5 is connected to button S1, which can control the system operation mode. P3^2 is connected to the infrared receiving module, and the system operation mode can be switched by infrared remote control through this interface. As shown in Figure 4:
Figure 4, Hardware circuit diagram
At this point, the hardware circuit is built.
3 System Software Design
In recent years, the development technology of single-chip microcomputer has been developing continuously, from the widespread use of assembly language to the gradual use of high-level language. The development software of single-chip microcomputer has also been developing continuously. Keil software is currently the most popular software for developing MCS-51 series single-chip microcomputer programs.
Keil provides a complete development solution including C compiler, macro assembler, linker, library management and a powerful simulation debugger, and connects these parts together through an integrated development environment (uVison).
Therefore, the software part of the system is programmed in the Keil environment. The following mainly introduces the main subroutines and some important parts of the program:
[page]
The initialization function is mainly used to set the initial values of the timer/counter and some parameters:
#include
#define uint unsigned int
#define uchar unsigned char
uint aa,num,MODEL1,numa,HMODE1;
uchar shi,ge,gtime,rtime;
… …
sbit dula=P1^0; // segment selection
sbit wela=P1^1; // bit selection
sbit LED1=P1^2; // East and West (red light)
sbit LED2=P1^5; // North-South (red light)
sbit LED3=P1^6; // North-South (yellow light)
sbit LED4=P1^3; // East and West (yellow light)
sbit LED5=P1^7; // North-South (green light)
sbit LED6=P1^4; // East and West (green light)
sbit KEY1=P3^5;
uchar code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
uchar table1[]={0xbf,0x7f};
void delay(uchar z) // delay function
{ uchar x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--); }
void init()
{ TMOD=0x01; //Select mode 1, 16-bit counter
TH0=15536/256;
TL0=15536%256; //Timer high and low bits, set initial value
EA=1; //Interrupt enable general control bit
ET0=1; //Timer 0 interrupt enable control bit
TR0=1; //Timer 0 running control bit
aa=0;
gtime=60;
rtime=40;
num=1;
numa=1;
MODEL1=1;
HMODE1=0;}
Timing function and principle:
When the microcontroller works in the timing state, the timer/counter counts the machine cycle. Each machine cycle includes 12 oscillation cycles. Taking the crystal oscillator frequency of 12MHZ as an example, then:
1 machine cycle = 12/crystal frequency = 12/12000000 = 0.001ms. The timing time is: TC = XTP. Among them, TP is the machine cycle and TC is the timing time.
The initial value to be loaded into the counter/timer is:
(Note: M=2n, TP is the machine cycle, TC is the timing time)
For mode 1, the maximum timing time is: T = (216-0) × 0.001 = 65.536ms. For the convenience of calculation, the maximum timing time is set to 50ms. The initial value to be loaded is calculated: N = 65536 − 50000 = 15536
Display subfunctions:
The microcontroller is used to control the bit selection and segment selection of the latch so that the digital tube displays the required numbers.
void display(shi,ge)
{ dula=1;
P0=table[shi];
dula=0;
wela=1;
P0=table1[0];
wela=0;
delay(5);
P0=0xff; // Clear the digital tube
dula=1;
P0=table[ge];
dula=0;
wela=1;
P0=table1[1];
wela=0;
delay(5);
P0=0xff;}
Mode 1 function:
void mod1()
{ if(num==1&>ime>5) // The east-west lane has a red light, the north-south lane has a green light, and the last 5 seconds it switches to a yellow light
{ LED5=0;
LED1=0; }
if(num==2) // The east-west road has a green light, and the north-south road has a red light
{ LED2=0;
LED6=0;
LED5=1;
LED3=1;
LED1=1; }
if(num==1&>ime==5) // The red light on the east-west lane is on, and the yellow light on the north-south lane is on for 5 seconds
{ LED5=1;
LED2=1;
LED3=0; }
shi=gtime/10;
ge=gtime%10;
if(aa==20) // 50ms×20=1s, i.e. after 1s, the digital tube number decreases by 1
{ aa=0;
gtime--; }
display(shi,ge);
if(gtime==0&&num!=2)
{ gtime=60;
num=2; }
if(gtime==0&&num==2)
{ num=1;
gtime=60;
LED2=1;
LED6=1; } }[page]
Mode 2 function:
Same as mode 1, only the parameters are changed, such as changing gtime=60 to rtime=40; num=1 to numa=1; that's all.
Main function:
void main()
{ init();
while(1)
/* Mode 1, normal mode, the traffic light switching time is 60 seconds*/
{ if(MODEL1==1||HMODE1==0) // Switch mode by key or infrared control
{ mod1(); }
/* Switch working mode by pressing buttons */
if(KEY1==0)
{ delay(5); //key debounce
while(KEY1==0)
{ MODEL1++;
rtime=40;
if(MODEL1==3)
{ MODEL1=1;
gtime=60; }
while(!KEY1); } }
… …
/*Mode 2, rush hour mode. The traffic light switching time is 40 seconds*/
if(MODEL1==2||HMODE1==1)
{ mod2(); }
} }
void timer0() interrupt 1
{ TH0=15536/256;
TL0=15536%256;
aa++; }
4 System Simulation
Combining software and hardware, through Proteus simulation, this system can run safely and reliably. A partial screenshot of the simulation diagram is shown in Figure 5.
Figure 5 Traffic light control system operation diagram
5 Conclusion
The system can fully meet the design requirements and has certain practical value. At the same time, the system has many development prospects and certain expansion capabilities, such as: judging whether the number of vehicles has increased based on image recognition, and thus judging which mode to run, which needs further development.
Previous article:Human body impedance measurement system based on single chip microcomputer
Next article:C++ STL concepts and examples
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
- ZTE's 7nm chip mass production still needs time to catch up with high-end chip track
- Comparison of Three Synchronous Designs in FPGA
- Looking for package SOT128-1
- 【Qinheng RISC-V core CH582】Timer PWM drive servo
- Selection and use of bypass capacitors
- CircuitPython Holiday Wreath
- Application and advantages of mica capacitors
- First Battlefield
- Infrared remote control LED dot matrix
- [Chuanglong TL570x-EVM] Install Prossessor SDK and create a development environment