Single chip microcomputer realizes dual mode of traffic light control system

Publisher:心灵的旅程Latest update time:2011-09-06 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

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

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

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

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

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

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.

Reference address:Single chip microcomputer realizes dual mode of traffic light control system

Previous article:Human body impedance measurement system based on single chip microcomputer
Next article:C++ STL concepts and examples

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号