Traffic light control system based on STC89C52 microcontroller

Table of Contents
Chinese Abstract 1
ABSTRACT 2
Chapter 1 Design Background and Significance 4
1.1 Background of Traffic Light 4
1.1.1 History of Traffic Light 4
1.1.2 Emergence of Traffic Light 4
1.2 Significance of Traffic Light 5
Chapter 2 System Scheme Design and Requirements 5
2.1 Passage scheme design of single-chip traffic light control system 5
2.2 Functional requirements of single-chip traffic control system 7
2.2.1 Display module function 7
2.2.2 Button module function 7
2.3 Basic composition and principle of single-chip traffic control system 7
Chapter 3 System Hardware circuit design 8
3.1 System hardware total circuit composition 8
3.2 Single-chip microcomputer system 9
3.2.1 Single-chip microcomputer pin introduction 9
Main features of single-chip microcomputer: 10
3.2.2 The minimum system of single-chip microcomputer 12
3.3 Display system 13
3.3.1 LED display 13
3.3.2 Digital Tube display 14
3.4 Signal display driving circuit 14
3.5 Keyboard input circuit 15
Chapter 4 System software program design 16
4.1 Program main design process 16
4.2 Subprogram module design 17
4.3 Application of KEIL51 18
4.4 Application of protel99se
18 Chapter Five Problems and Solutions 20
Chapter 6 Summary and Outlook 21
Appendix A 23
Appendix B 23
Acknowledgments 24
Chapter 2 Design and Requirements of System Scheme
2.1 Traffic light control system traffic scheme design of single-chip microcomputer
is set at the intersection, which is divided into east-west and north-south directions, and there is only one at any time Passage in one direction, prohibition in the other direction, lasts for a certain period of time, after a short transition time, the direction of passage and prohibition is reversed. Its specific status is shown in the figure below. Note: Black means on, white means off. The traffic state changes from state 1 until state 6 and then cycle to state 1, and it goes round and round, as shown in the figure (Figure 2-1): until state 6 and then cycle to state 1, through the demonstration and analysis of the state of the traffic light at the specific intersection We can summarize these four states as follows:
insert image description here

insert image description here

Figure 2-1 Traffic status
The red lights in the east-west direction are off, and the green lights are on at the same time, the yellow lights in the north-south direction are off, and the red lights are on at the same time, and the countdown is 20 seconds. In this state, east-west traffic is prohibited, and north-south traffic is allowed.
The green lights are off in the east-west direction, and the yellow lights are on at the same time, and the red lights are on in the north-south direction, and the countdown is 5 seconds. In this state, all vehicles except those already in transit need to wait for the state transition.
The red light in the north-south direction is off, and the green light is on at the same time, the yellow light in the east-west direction is off, and the red light is on at the same time, and the countdown is 30 seconds. In this state, traffic is allowed in the east-west direction and prohibited in the north-south direction.
The green light in the north-south direction is off, the yellow light is on at the same time, the red light in the east-west direction is on, and the countdown is 5 seconds. In this state, all vehicles except those already in transit need to wait for the state transition.

#include <reg51.h>				//头文件
#define uchar unsigned char
#define uint  unsigned int		//宏定义

uchar data buf[4];					//秒显示的变量
uchar data sec_dx=20;  			//东西数默认
uchar data sec_nb=30;			//南北默认值
uchar data set_timedx=20;		//设置东西方向的时间
uchar data set_timenb=30;		//设置南北方向的时间
int n;
uchar data countt0,countt1;//定时器0中断次数
//定义6组开关
sbit  k4=P3^7;      //切换方向
sbit  k1=P3^5;		//时间加
sbit  k2=P3^6;		//时间减
sbit  k3=P3^4;		//确认
sbit  k5=P3^1;		//禁止
sbit  k6=P1^5;		//夜间模式


sbit Red_nb=P2^6;		//南北红灯标志
sbit Yellow_nb=P2^5;	//南北黄灯标志
sbit Green_nb=P2^4;     //南北绿灯标志

sbit Red_dx=P2^3;		//东西红灯标志
sbit Yellow_dx=P2^2;	//东西黄灯标志
sbit Green_dx=P2^1;		//东西绿灯标志
	
sbit Buzz=P3^0;		
bit set=0;				//调时方向切换键标志 =1时,南北,=0时,东西
bit dx_nb=0;			//东西南北控制位
bit shanruo=0;			//闪烁标志位
bit yejian=0;			//夜间黄灯闪烁标志位

uchar code table[11]={	//共阴极字型码
	0x3f,  //--0
	0x06,  //--1
	0x5b,  //--2
	0x4f,  //--3
	0x66,  //--4
	0x6d,  //--5
	0x7d,  //--6
	0x07,  //--7
	0x7f,  //--8
	0x6f,  //--9
	0x00   //--NULL
};

insert image description here
insert image description here
insert image description here
insert image description here
insert image description here
insert image description here
insert image description here
insert image description here
insert image description here
insert image description here
insert image description here
insert image description here
insert image description here
insert image description here
insert image description here
insert image description here
insert image description here

Guess you like

Origin blog.csdn.net/sheziqiong/article/details/131060275