At the crossroads of city streets, various indicator patterns composed of red and green high-brightness LEDs are placed to manage motor vehicles, non-motor vehicles and pedestrians so that they can pass through their respective intersections safely and smoothly. These traffic light patterns are varied. The author takes the control of one of the traffic light patterns at the crossroads as an example to illustrate the application of PIC microcontroller C language in urban traffic light management.
FIG55a is a palm-shaped indicator pattern composed of red high-brightness LEDs, which is displayed at the intersection. It indicates that pedestrians are prohibited from passing in this direction at this time. FIG55b and FIG55c are respectively human-shaped and bicycle-shaped indicator patterns composed of green high-brightness LEDs. When the patterns are displayed at the intersection, it indicates that people are allowed to pass at this time. FIG56 is a circular indicator pattern composed of red and green high-brightness LEDs (red and green are displayed in time-sharing mode) to indicate whether motor vehicles are allowed to pass. The above-mentioned indicator patterns are all set on the traffic road 13 and are displayed alternately in a time-sharing manner. The length of time for each indicator pattern to be displayed is set according to the actual situation of the traffic and pedestrian flow on different roads 13, generally between 80 seconds and 140 seconds (special intersections can be up to 180 seconds, or even longer).
Fig.55
Fig.56
By using the 121 bit of the PIC16F877 or PIC16F876 microcontroller and the corresponding driving circuit, the high-brightness red and green LEDs that make up the indication patterns shown in Figures 55 and 56 can be driven to display according to the required timing, thus realizing the above functions. By installing them in a box and at a designated location at a traffic intersection, traffic management at the intersection can be performed. [page]
1. Hardware circuit and function
(1) Hardware circuit
According to the above-mentioned traffic intersection traffic light indication pattern display requirements, the hardware circuit designed by PIC16F877 is shown in Figure 57.
Fig.57
As can be seen from Figure 57, PIC16F877 has 40 pins and more I/O ports than PIC16F84A, which can fully meet the requirements of time-sharing display of the above traffic sign pattern.
It should be noted that when we introduced C language programs in the previous serial articles, we used the 18-pin PIC16F84A microcontroller as an example. Through this example, you will see that as long as you are familiar with PIC16F84A, it will be easy to master the use of other multi-pin PIC microcontrollers.
Since the output current of each bit of the 1:3 I/O terminal of the PIC microcontroller is limited, that is, ≤ 20mA, and the total output current of PORTA, PORTB and PORTE shall not be greater than 200mA, and the total output current of PORTC and PORTD shall not be greater than 200mA, and it can be seen from Figure 57 that the number of high-brightness LEDs connected to the PB0~PB7 ports and PC0 and PC1 ports of PORTB of the PIC16F877 microcontroller ranges from more than ten to dozens, so for all I/O ports with external high-brightness LEDs, we have added a power tube output drive connection 1:3 circuit, and the driving circuit is different depending on the number of external high-brightness LEDs (that is, different current sizes).
(2) PIC16F877 port function bit allocation
① Manage the port position of the palm-shaped red highlighted LED indicator.
Using the RB0 position of PIC16F877, a unidirectional thyristor SCR1 (2A) and multiple red high-brightness LEDs are connected externally (multiple LEDs are wired to form a hand pattern as shown in Figure 55a), and a static display mode is adopted. Usually, the hand pattern of a traffic light requires about 60 to 70 LEDs. In our design, the SCR1 circuit connected to the RB0 port can connect up to 100 high-brightness LEDs. It is enough to meet the design requirements. The RB1 position is connected to a PNP power transistor V1 (2A) and a current limiting resistor R0 and a bias resistor R1 to form a +24V switch circuit. The C program controls the RB0 port and RB1 to work synchronously and timingly in a 1:3 ratio. The conduction or cutoff of V1 controls whether to provide a +24V working voltage to SCR1, thereby achieving the purpose of timing the red high-brightness LED in the SCR1 circuit to light up or turn off.
② Manage the end 13 of the humanoid green high-brightness LED indicator light.
Using the RB2 bit of PIC16F877, a unidirectional thyristor SCR2 (2A) and multiple red high-brightness LEDs are connected externally (multiple LEDs are wired to form a human-like figure as shown in Figure 55b), and a static display mode is adopted. It takes about 70 LEDs to form this figure. The RB3 bit is connected externally to a PNP power transistor V2 (2A) and resistors R2 and R3 to form a +24V switch circuit.
The working mode of this circuit is exactly the same as the palm-shaped indicator light introduced earlier, so it will not be described here.
③ Manage the port position of the bicycle-shaped green high-brightness LED indicator light.
By using RC0, RC1~RC7, externally connected NPN power transistors V5~V12 and several green high-brightness LEDs (through wiring to form a graphic that can control the dynamic display of a bicycle as shown in Figure 55c). When the circuit is working, by controlling the LEDs arranged on the bicycle wheels to light up and off in time, people can see an image that seems to be a bicycle rotating, so as to prompt people or non-motor vehicles to pass.
④ Manage the port position of the circular green highlighted LED.
The one-way thyristor SCR3 and related circuits such as V3 connected to RB4 and RB5 are used to control the green high-brightness LED circular indicator light as shown in Figure 56 to prompt the passage of motor vehicles.
⑤ Manage the port position of the circular red highlighted LED.
The one-way thyristor SCR4 and related circuits such as V4 connected to RB6 and RB7 are used to control the red high-brightness LED circular indicator light as shown in Figure 56 to indicate that motor vehicles are prohibited from passing.
It should be noted that the circular pattern in Figure 56 is common to both red and green lights. When wiring, the red and green highlight LEDs should be arranged alternately, and the red and green LEDs can be controlled to display in time using a C language program.
The operation of the above I/O ports is all controlled by software (C language program). The program controls the time-sharing operation of each high-brightness LED indicator pattern according to the specifications of each traffic intersection, so that pedestrians and vehicles at the traffic intersection can pass safely and orderly.
2. C language program flow chart and C program
According to the circuit shown in Figure 57, we can draw the C language program flow of the red and green lights in the straight direction of the urban traffic intersection as shown in Figure 58. The C language program flow of the red and green lights in the horizontal direction is the same. This flowchart can provide ideas for everyone to edit C language programs.
Fig.58
[page]
The C program list for traffic light management at traffic intersections edited according to the process shown in Figure 58 is as follows (program name pic08.C):
[page]
Note: The above traffic road 1:3 red and green light C program is the pattern of traffic lights observed by the author at the traffic intersection. The purpose of editing this program is to help everyone learn C language programming. For the delay function value in the program, readers can adjust it as needed to use it in other C programs as a delay function value that can change the time arbitrarily.
It should be noted that the actual red and green light management system at traffic intersections is a red, green and yellow light engineering management system based on multiple intersections, which considers more and more complex issues than the procedures in this article.
Previous article:PIC microcontroller C language programming (14)
Next article:PIC microcontroller C language programming (12)
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
- [SAMR21 new gameplay] 35. HCSR04 ultrasonic sensor
- The evaluation plan for the current probe and signal generator winners is open! The instruments have been distributed, and we look forward to the sharing of the 6 little ones
- How to use stm to make lcd12864 display
- Thank you + my son, my daughter, and my wife
- How to set breakpoints when debugging a program in keil4?
- 【Qinheng Trial】3. System clock and TIMER0
- [SAMR21 New Gameplay] 32. CPU-related functions
- C2000 Power-on Boot Mode Analysis
- EEWORLD University Hall----Electromagnetic Compatibility Principles and Design
- MSP430 realizes access card function (RFID) through RC522