Traffic light system 51 microcontroller design (with Proteus simulation, C program, schematic diagram, PCB, thesis and other full set of materials)

Design requirements
(1) Design a traffic light control system by using 51 single-chip microcomputer to realize the purpose of diverting pedestrians and vehicles. The system is mainly used at intersections, with the main road in the vertical direction and the branch road in the horizontal direction;
(2) The main road and the branch road pass alternately, and the traffic lights on the two main roads work at the same time. The main road is released for 10 seconds each time, and the release time can be changed by pressing the button; (
3) Each time the green light turns red, the yellow light flashes for 3 seconds. At this time, the red light remains on the other main road;
Crossroad traffic control function;
(5) Provide the structure diagram, software and hardware flow chart of the whole system;

Design Overview The
east-west main road and the north-south branch road are controlled by a set of three-color traffic lights, which are red, yellow, and green in the direction of the main road and red, yellow, and green in the direction of the branch road.

The logic analysis shows that when the main road is green, the branch road must be blocked by the red light; after the green light ends, the main road enters the yellow light flashing waiting state, and the branch road is red; after the yellow light ends, the main road turns red. When the traffic is prohibited, the branch road turns into a green light for traffic; after the green light on the branch road ends, the branch road enters the yellow light blinking waiting state, and the main road has a red light, and so on.

It can be seen from this process that the traffic light control is divided into 4 states, namely: S1 state, the direction of the main road is green, and the direction of the branch road is red; S2 state, the direction of the main road is the yellow light flashing, and the branch road is red. Light; in S3 state, the direction of the main road is red, and the direction of the branch road is green; in the S4 state, the direction of the branch road is flashing yellow, and the direction of the main road is red. These four states cycle continuously. From this we can make a list of 4 states and make a flow chart of 4 states.
insert image description here

insert image description here
There are 4 buttons in the system settings, namely setting button, plus button, minus button and traffic control button. The setting key is to start and confirm the setting, the plus and minus keys are to adjust the passing time, and the traffic control key is to force the setting of the traffic light system.

When the system is powered on or manually reset, the default mode will run according to the parameters recorded in the program before power off. If the setting key is pressed at this time, it will enter the transit time setting state, and the original recorded time will be displayed on the digital tube and flash. The Set key saves the new parameter.

The traffic control button is used to control the traffic at the intersection. There are five modes: east-west, north-south main road red light; east-west red light, north-south green light; east-west green light, north-south red light; east-west green light, north-south green light; east-west yellow light, north-south yellow light.

Simulation circuit diagram
insert image description here
insert image description here
schematic diagram and PCB
insert image description here
insert image description here
hole board physical diagram
insert image description here
simulation results analysis
In the real traffic light, it is operated vertically, and the vertical direction is north and south; in the simulation circuit diagram, the vertical direction is east and west when viewed from the front, and it is the same as the real thing when viewed obliquely from the left of. Therefore, there is a one-to-one correspondence between real objects and simulations!

Load the "traffic light design based on Graduation 51 microcontroller.hex" file to the microcontroller, click to run, the traffic light starts to work (the diode displays red, yellow, and green lights, and the LED displays countdown).

In the program, we set that the green light traffic time of the east-west main road is 15S, and the traffic time of the north-south branch road is 10S. The system automatically enters state S1: the east-west trunk road is green, and the north-south branch road is red.
insert image description here
It can be seen that the green light traffic time of the east-west main road is 15S, and the red light waiting time of the north-south branch road is 15S. After the LED countdown on the east-west and north-south trunk roads is 12S, the system enters the S2 state: the yellow light on the east-west trunk road flashes for 3S, and the north-south branch trunk road has a red light.
insert image description here
After 3 seconds, the system enters the S3 state: the east-west main road is red, the north-south green road is green, and the traffic time is 10 seconds. The simulation results are shown below.
insert image description here
After 7 seconds, the system enters the S4 state: the yellow light on the north-south main road flashes for 3 seconds, and the east-west main road is still red. Then enter the S1 state, and loop continuously.
insert image description here
After pressing the "Setting" key, the system enters the setting mode, and the "plus" and "minus" keys are used to set the green light traffic time of the east-west trunk road. Press the "Set" button again to set the transit time of the north-south trunk road. After the transit time is set, press the "set" button again, and the system will return to the running state.
insert image description here
insert image description here
As can be seen from the above figure, the passage time of the east-west main road is set from the original 15S to 16S. The traffic light system can be controlled through the "traffic control" button.
insert image description here
Part of the C code

u8 Key_Scan()
{    
    static u8 key_up=1;//按键按松开标志
    if(key_up&&(Key1==0||Key2==0||Key3==0||Key4==0))
    {
        delay_1ms(10);//去抖动 
        key_up=0;
        if(Key1==0)         return 1;
        else if(Key2==0)return 2;
        else if(Key3==0)return 3;
        else if(Key4==0)return 4;
    }
    else if(Key1==1&&Key2==1&&Key3==1&&Key4==1)
        key_up=1;       
    return 0;// 无按键按下
}


uchar flag_s;
uchar menu_1;//纵横加减标示


/********************设置函数*****************/
void key_with()
{
    if(key_can == 4)   //交通管制按键
    {
        flag_jdgz ++;
        if(flag_jdgz > 5)
            flag_jdgz = 0;  
        if(flag_jdgz == 1)   //  全部亮红灯 
        {
            dx_red    = 0;  //亮 
            nb_red    = 0;  //亮 
            dx_green  = 1;  //灭
            dx_yellow = 1;  //灭
            nb_green  = 1;  //灭
            nb_yellow = 1;  //灭         
        }
        if(flag_jdgz == 2)   //  东西绿灯  南北红灯
        {
            dx_red    = 0;  //亮 
            nb_green  = 0;  //亮
            dx_green  = 1;  //灭
            dx_yellow = 1;  //灭
            nb_red    = 1;  //灭 
            nb_yellow = 1;  //灭         
        }
        if(flag_jdgz == 3)   //  南北绿灯  东西红灯
        {
            dx_green  = 0;  //亮
            nb_red    = 0;  //亮 
            dx_red    = 1;  //灭 
            dx_yellow = 1;  //灭
            nb_green  = 1;  //灭
            nb_yellow = 1;  //灭         
        }
        if(flag_jdgz == 4)   //  南北绿灯  东西绿灯
        {
            dx_green  = 0;  //亮
            nb_green  = 0;  //亮
            dx_red    = 1;  //灭 
            dx_yellow = 1;  //灭
            nb_red    = 1;  //灭 
            nb_yellow = 1;  //灭         
        }
        if(flag_jdgz == 5)   //  南北黄灯  东西黄灯
        {
            dx_red    = 1;  //灭 
            dx_green  = 1;  //灭
            nb_red    = 1;  //灭 
            nb_green  = 1;  //灭
            nb_yellow = 0;  //亮         
            dx_yellow = 0;  //亮
        }
    }
    if(key_can == 1)      //设置键
    {
        menu_1 ++;
        if(menu_1 >= 3)
        {
            menu_1  = 0;
        }
    }

    if(menu_1 == 1)    //设置东西的时间
    {
        if(key_can == 2)
        {
            dx_time ++ ;        //加1
            if(dx_time > 99)//时间最大值为99s
                dx_time = 99;
        }
        if(key_can == 3)
        {
            dx_time -- ;        //减1
            if(dx_time <= 5)//时间最小值为5s
                dx_time = 5;
        }
        dis_smg[0] = DisplayOther[2] ;  //显示为B
        dis_smg[1] = DisplayOther[2] ;  //显示为B
        dis_smg[2] = smg_du[(dx_time-1) % 10] ;     //显示东西设置的时候
        dis_smg[3] = smg_du[(dx_time-1) / 10] ; 
    }

    if(menu_1 == 2)    //设置南北的时间
    {
        if(key_can == 2)
        {
            nb_time ++ ;        //加1
            if(nb_time > 99)    //时间最大值为99s
                nb_time = 99;
        }
        if(key_can == 3)
        {
            nb_time -- ;        //减1
            if(nb_time <= 5)//时间最小值为5s
                nb_time = 5;
        }
        dis_smg[0] = smg_du[(nb_time-1) % 10] ; //显示为A
        dis_smg[1] = smg_du[(nb_time-1) / 10] ; //显示为A
        dis_smg[2] = DisplayOther[2] ;      //显示东西设置的时候
        dis_smg[3] = DisplayOther[2] ;  
    }   

}

The resources shared are
(1) full version of graduation design thesis for traffic light system based on 51 MCU;
(2) Proteus simulation file;
(3) Keil C program file;
(4) Reference materials;
(5) Visio flow chart;
(6 ) ) PCB file and schematic diagram;
(7) Component introduction and list;
(8) Reference design 1: Traffic light design based on microcontroller (another set of traffic light design)

The screenshots of the resources are as follows
insert image description here
insert image description here
insert image description here
insert image description here
insert image description here
insert image description here
. Obtain a complete set of information such as traffic light system design papers, Proteus simulation, C programs, PCB and schematic diagrams, Visio flowcharts, and component lists.
Please search on WeChat and pay attention to the public number: Jiao Xiaozhi

Related Posts