Traffic light design based on microcontroller control
The design of this course is to comprehensively use the learned knowledge of microcontrollers to complete the design of a microcontroller application system and implement it in the laboratory after learning the principles and courses of microcontrollers. The main task of this course design is to consolidate and deepen the theoretical knowledge and experimental abilities learned in the "Principles and Applications of Microcontrollers" course by solving one or two practical problems, basically master the general design methods of microcontroller application circuits, and improve the quality of electronic circuits. Design and experimental capabilities, deepen the understanding of the soft and hard knowledge of microcontrollers, gain preliminary application experience, and lay a certain foundation for future work.
Today, traffic lights are installed at various intersections and have become the most common and effective means of diverting traffic vehicles. But this technology has already appeared in the 19th century. The emergence of traffic lights enables effective traffic control, which has a significant effect on diverting traffic flow, improving road capacity, and reducing traffic accidents. After three weeks of study, I have a preliminary understanding and understanding of the structure and functions of microcontrollers. The single-chip microcomputer plays a decisive role in traffic control. Mastering the working principle of the single-chip microcomputer will basically understand the operating principle of the traffic light. As a student, in order to better grasp the structure and functions of microcontrollers and to further strengthen my practical ability, I designed the following traffic light.
1. Project Introduction
This design is a traffic light control experiment, and we must first understand the changing rules of the actual traffic lights. Suppose an intersection runs east-west, north-south, that is, a crossroads. The initial state is zero when the lights in the east-west, north-south directions are all off. Then change the status to a green light for east-west traffic and a red light for north-south traffic. After a while, it changes to state 2. The east and west lights flash green several times and turn to yellow. There is a delay of a few seconds. The north and south lights are still red. Then change to state three, the north-south green light is open to traffic, and the east-west light is red. After a while, it changes to state 4. The north and south lights flash green several times and turn to yellow. After a delay of a few seconds, the east and west lights are still red. Finally, it loops to state one. The design of the traffic light simulation control system uses the timer timing of the microcontroller to control the intersection traffic lights to turn on and off alternately, and uses an LED digital tube to display the time, but due to insufficient time and level, it is not displayed in this experiment. An experimental design was performed using twelve light-emitting diodes instead of traffic lights.
This design is a comprehensive training for the "Microcomputer Interface and Control Technology" course. We consolidate the knowledge we have learned and improve the application level through theoretical study, topic selection, data review, software and hardware design, system debugging, etc. Here we need to learn the scientific method from asking questions, observing and analyzing problems, to finally solving the problems. To improve our thinking and practical abilities, gain some practical experience in design, and also to cultivate our work style and attitude. This will lay a solid foundation for future graduation projects and the design and maintenance of microcomputer control systems.
The significance of this project design is to master the general methods of microcomputer control system design and problem-solving ideas, especially some commonly used technical means, through the design of specific control systems. This enables us to accumulate design experience in a practical teaching environment, expand our thinking space, and comprehensively improve our personal comprehensive abilities.
(2) Process flow chart
Because this experiment is a traffic light control experiment, it is necessary to first understand the changing rules of the actual traffic lights. Suppose an intersection runs east-west, north-south. The initial state 0 is that the lights in the east, west, north and south are all off. Then switch to state 1, the east-west green light is open to traffic, and the north-south light is red. After a period of time, it changes to state 2, the east and west lights flash green several times and then turn on to yellow, with a delay of a few seconds, and the north and south lights remain red. Then transfer to state 3, the north and south lights are green and the east and west lights are red. After a period of time, it changes to state 4. The green light in the north and south flashes several times and turns to yellow. After a delay of a few seconds, the north and south lights remain red. Finally loop to state 1. The design of the traffic light simulation control system uses the timer of the microcontroller to make the traffic lights at the intersection light up and go out alternately, and uses LED digital tubes to display the time, but due to time and level limitations, the time is not displayed. Use twelve light-emitting diodes to burn and extinguish to simulate traffic light management. The specific interface is shown in Figure 1 below.
2. Engineering design
(1) Determination of control plan
The principle of the traffic light control system is mainly composed of controller, timer, decoder and second pulse signal generator. The second pulse generator is the standard clock signal source for the timer and controller in the system. The decoder outputs the control signals of the two sets of signal lights, which drive the signal lights through the drive circuit. The controller is the main part of the system, which controls the timing. The work of the converter and decoder. The complete circuit board is shown in Figure 2.
Figure 2 Complete circuit board
(2) Hardware part
(1) Hardware design of traffic light control system:
The hardware design of the traffic light control system includes: memory expansion (62256), I/O port expansion (8255), address latch (74LS373 or 74LS273), and inverter (7407).
It consists of data buffer, I/O control logic, control and timing registers and timing and control circuits, scan counter, reply buffer, FIFO/sensor RAM and its status register, display RAM and display address register, etc.
(2) The design of the hardware system follows the following principles:
1. Meet the design requirements of the system and be easy to operate and maintain.
2. The system has flexible functions and is easy to expand.
3. With automatic diagnosis function.
(3), hardware structure block diagram (shown in Figure 3).
The role of the hardware system in this system is mainly to transmit data, calculate related logic, provide display, manually modify data, start and stop the system, etc. In addition, the safety and reliability of system operation depend on the hardware system.
(4) Principle block diagram of the traffic light control system (shown in Figure 4).
Figure 4 Principle block diagram of traffic light control system
In the picture:
TL: Indicates that the time interval between lane A or lane B’s green light is 25 seconds, which is the time interval for vehicles to pass normally. When the timing time is up, TL=1, otherwise, TL=0.
TY: Indicates that the time interval between yellow lights is 5 seconds. When the timing time is up, TY=1, otherwise, TY=0.
ST: Indicates that after the timer reaches the specified time, the controller sends a state transition signal. It controls the timing of the timer to start the next working state.
The timer is composed of a counter that is synchronized with the system second pulse (provided by the clock pulse generator). The counter is required to be cleared first under the action of the status signal ST, and then under the action of the rising edge of the clock pulse, the counter starts counting by 1 from zero. , providing the controller with a modulo 5 timing signal TY and a modulo 25 timing signal TL. (The circuit diagram is shown in Figure 5)
Figure 5 Timer circuit diagram
The controller is the core of traffic management. It should be able to control the switching of the working status of the signal lights according to traffic management rules. The state transition table of the controller can be listed from the ASM diagram, as shown in Table 1. Two D flip-flops FF1 and FFO are selected as timing registers to generate 4 states. The conditions for controller state transition are TL and TY. When the controller is in the Q1n+1Q0n+1= 00 state, if TL= 0, the controller Maintain in 00 state; if, the controller switches to Q1n+1Q0n+1= 01 state. These two situations have nothing to do with the condition TY, so they are represented by the irrelevant item "X". (The controller logic diagram is shown in Figure 6)
According to Table 1, the state equation and conversion signal equation can be derived. The method is: AND the input or state transition condition variables corresponding to the items Q1n+1, Q0n+1 and ST are 1, where "1" is the original variable. "0" is represented by an inverse variable, and then the AND terms are ORed to get the following equation:
Controller logic diagram (shown in Figure 6)
The 74LS138 decoder has 3 input terminals, which constitute 8 input states, and 8 output terminals. Each output terminal corresponds to one of the 8 input states, and is active at low level. In addition, there are three enable terminals E3, E2, and E1. These three enable terminals must input valid levels at the same time for the decoder to work, that is, E3=1, E2=0, and E1=0.
The main task of the decoder is to translate the four working states of the controller's output Q1 and Q0 into the working states of the six signal lights on lanes A and B. The relationship between the controller's status code and the signal light control signal is shown in Tables 12 and 4. Readers are asked to design the decoding circuit to realize the above relationship.
4. Traffic light drive circuit (shown in Figure 7)
5.Circuit diagram (such as Appendix B) and circuit diagram description
Circuit diagram description
1. This LED dynamic display circuit uses an I/O port P0 of a microcontroller.
2. The lower four bits of the P0 port output the BCD code of the digital display, and the output BCD code is sent to the 74LS138 for decoding. Then the output segment code is pulled up by the pull-up resistor and sent to the pins of each display segment of the display.
3. The three ports P03, P04 and P05 output bit selection signals. The bit selection signal is sent to the 74LS138 and decoded to generate the bit selection signal of the display.
4. When the short code is output, the low-level port will pull the level of this port low. Therefore, the light-emitting diode will not emit light at this time, and the high-level port will provide a high level to the anode of the light-emitting diode. As long as this bit is selected, the light-emitting diode will light up. Find it in the segment code table. Numbers that can respond. Each bit selection circuit consists of a PNP transistor. When the bit selection port emits a low level, then the triode of this bit will be saturated and conductive. Since the display has a common cathode internal structure, when the triode is saturated and conductive, it is equivalent to grounding the display.
5. When the pulse reaches the MCS-51 microcontroller, the LED 8-bit display receives the signal and stores the signal in the extended register. When the lower four bits of the P0 port output the BCD code of the displayed number, the output BCD code is sent to the 74LS138 for decoding. decode by the computer, and then query the display number in the display prompt segment code.
6. The first four digits display the main road passage time, and the last four digits display the branch road time. The LED display is used to control the release and prohibition of vehicles.
(5), 8279 structure and pin functions:
The internal structure of 8279 consists of data buffer, I/O control logic, control and timer and timing control circuit, scan counter, reply buffer, FIFO/sensor RAM and its status register, display RAM and display address register, etc.
(a) Data buffer and I/O control logic The data buffer is a bidirectional buffer that connects the internal bus and the external bus and is used to transmit commands, data and status between the CPU and 8279. The I/O control logic is completed Read and write control of the chip, chip selection and port selection.
(b) Control and timers and timing are used to register operation command words.
(c) Scan counter The scan counter has two working modes. One is the external decoding mode. The counter counts in binary mode, and the 4-bit counting status is output from the scan lines SL0-SL3. After being decoded by the external decoder, it forms 16 bit scan signal; the other is the internal decoding mode. In this mode, the lower two bits of the scan counter are output from SL0-SL3 after being internally decoded, forming a 4-bit scan signal.
(d) Reply buffer, the reply buffer buffers and latches the reply signals from the eight reply lines SL0-SL7.
(e) FIFO/sensor RAM and its status register FIFO/sensor RAM is a dual-function 8*8RAM.
(f) Display RAM and display address register Display RAM is used to store display data, with a capacity of 16*8 bits. During the display process, the stored display data is output from the display register in turn.
In the light control experiment, its chip selection signal line is connected to Q0, and its data selection input line is connected to Q1, so its control port address is FF82H, its data port address is FF80H, and the interrupt is left floating.
8051 minimum application system
8051 is a supply status chip without on-chip program memory. Therefore, its minimum application system must expand the EPROM off-chip. The address lines A8-A15 of the external program memory are provided by the P2 port; A0-A7 are provided by the P0 port through the address latch. Provided. The latch signal of the address latch is ALE. The instruction data is read in from the P0 port. The instruction fetch signal of the program memory is /ALE. Its chip select line is directly connected to the ground. At the same time, there must be a unit and clock circuit.
8255 programmable interface chip
Three parallel I/O ports - port A, port B, and port C. In this design, ports A and B are used.
1) Working mode control circuit;
2) Read and write control logic circuit;
data bus buffer;
(3) Software part
(1) Calculation of delay subroutine:
Registers R0, R1, and R2 are used as count values, 1 is temporarily stored in R2, and 0 is stored in R1. When decremented by 1, it becomes 255, which is the number 256 stored in R1. The number #0B2H stored in R0 is 178. The total number of instruction cycles occupied by each instruction is (see the figure attached after the delay program)
DELAY2 delay is:
A total of 9164 instruction cycles, while the system crystal oscillator is 11.0592. So T=12/11.0592=1.085 (microseconds)
The delay DELAY2 is:
Approximately equal to 0.1 (second)
The number of seconds of delay can be changed by changing the value of R2.
(2), flow chart (shown in Figure 8)
First, all the lights at the four intersections are turned off. When the east and west green lights are on, the north and south red lights are on with a delay of 20 seconds. The green light flashes three times, and then turns to yellow for 2 seconds. When the north and south green lights are on, the east and west red lights are on with a delay of 20 seconds. The green light flashes three times. down, it turns to yellow light for 3 seconds and turns on for 2 seconds, and so on.
(3), source program (such as Appendix A)
(4) Expression of program execution (such as Table 2)State duration/S East-West direction North-South direction Green Yellow Red Green Yellow Red 1 50 On Off Off Off Off Off 2 3 Flashing Off Off Off Off 3 2 Off On Off Off Off 4 50 Off Off On Off Off 5 3 Off Off, flash, off, 6 2, off, light, off, off, cycle
3. System commissioning and operation
(1) Hardware debugging
Use the DVCC experiment and development system and basic test instruments (multimeter, oscilloscope, etc.) to check faults in the user system hardware. Hardware debugging can be divided into two steps: static debugging and dynamic debugging.
(1), static debugging
It is a hardware detection when the user system is not working.
Step one: Visual inspection. Check whether there are any breakpoints in various external components or circuits.
Step 2: Test with a multimeter. First use a multimeter to review the questionable connection points in the visual inspection, and then check whether there is a short circuit between the various power lines and the ground wire.
Step 3: Power on and test.Power up the board and check whether all sockets or device power terminals meet the required values.
The fourth step: is online inspection. Because only by using a microcontroller to develop the system can the debugging of the user system be completed.
(2) Dynamic debugging
It is a hardware inspection that discovers and eliminates device internal faults, device connection logic errors, etc. that exist in the user system hardware when the user system is working. The general method of dynamic debugging is from near to far, from separation to closing. From dividing to closing means first dividing the user system hardware circuit into several blocks according to logical functions. When debugging the circuit, all devices unrelated to the component are removed from the user system, so that the fault scope can be limited to a certain local circuit. superior. When each circuit is fault-free, each circuit is added to the system one by one, and the functions of each circuit and the possible interconnections between the circuits are debugged. The debugging from point to point is completed. From near to far, each device through which the signal flows is layered from near to far according to the logical distance from the microcontroller, and then debugged layer by layer. When debugging, the method of removing irrelevant components is still used, and by debugging layer by layer, the faulty component will be located.
4. System design and summary features
Through this course design, I have benefited a lot, and it has also allowed me to understand and master some programming ideas, thinking about the use and application conditions of I/O ports, and understanding and mastering the functions of each pin of the microcontroller. An effective combination of software and hardware is achieved, and both are indispensable. Design allows me to use the theoretical knowledge of microcontrollers in practice, and realizes the combination of theory and practice. From it, I can better understand the theory, which is the basis of practice. Practice can test the correctness of the theory, which further stimulates my thirst for professional knowledge. These will be of great help and influence for me to work or continue studying in the future.
This course design also taught me how to write a paper and understand the elements of a paper, which will be of great help to me in writing my graduation thesis in the future, and will also be of great benefit to me in my future work. Writing the thesis also made me take a big step forward in mastering the basic principles of microcontrollers, the development process of microcontroller application systems, and common programming design ideas, laying a good foundation for becoming a qualified application-oriented talent in the future. Foundation.
As a student, when designing traffic lights, due to lack of knowledge and experience, I can only complete the design by imitating other programming ideas and adding some of my own ideas, so there will be some deficiencies in all aspects. , please correct me. But I will gradually improve and consolidate my knowledge of microcontrollers in my future studies.
Review Editor: Liu Qing
#Traffic #light #design #based #microcontroller #control
- New product launch | Xianji Semiconductor joins hands with VeriSilicon to break through multimedia MCU performance and create a new generation of digital instruments
- Innovative expanded beam fibre optic connector technology
- Key Trends in Gas and Particulate Sensor Technology
- What is the pipeline of a superscalar processor? What are the characteristics of superscalar processors?
- Current situation and development under accelerated increase in N-type penetration rate
- How to solve the frame loss phenomenon of industrial cameras?
- New MOSFET product family for automotive and industrial solutions
- The integration of generative artificial intelligence and the real economy promotes the development of new productivity
- TSMC rose by more than 5% and hit a record high. The demand for AI is strong and is expected to grow by 50% year by year.
- Implement the migration and application process of AI models on MPU