51 single-chip traffic light system design (flow chart + hardware + source code)

Publisher:幸福时光Latest update time:2020-01-20 Source: 51hei Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

This is a project that the teacher asked me to do. Now it has been completed without any major problems.

1. Design requirements and scheme demonstration

1.1 Design requirements:

1.1.1 Basic requirements:

1. There are three types of traffic lights: red, yellow and green in both the east-west and north-south directions. The initial red light is 30 seconds, the yellow light flashes for 3 seconds, and the green light is 30 seconds. The east-west direction has a red light, the north-south direction has a green light, the north-south direction has a green light, and the east-west direction has a red light.

2. Button adjustment and control function. By pressing the button, you can control the green light in one direction to be on for a long time and the red light in another direction to be on for a long time. By pressing the button, you can control the length of the red light in a certain direction. For example, adjust the red light in the east-west direction to 40 seconds and the green light to 20 seconds. At the same time, the red light in the north-south direction is 20 seconds and the green light is 40 seconds.

3. Press the night mode button and the yellow light flashes in all directions

4. Real-time reminder of the remaining time of the light


1.1.2 Extension part:

Not yet expanded

1.2 System basic scheme selection and demonstration:

1.2.1 Selection and demonstration of single chip microcomputer:

8051 core produced by STC, CMOS technology;


1.2.2 Selection and demonstration of digital tube display module:

The digital tube selected is a common anode. The driving ability of the microcontroller is not very strong, so a common anode digital tube is selected;.



1.2.3 Selection and demonstration of LED lamps:

The current through an LED lamp is about 10ms.








1.3 Final circuit design solution

2.1 The table number is generated by timer T0

TH0=0xFC; TL0=0x67; Interrupt every 1ms and change the value of the marker of the entire project.


2.2 Omitted;







3.1 Circuit Design Block Diagram

3.2 System Hardware Description

The main hardware is the 89C51 chip for input and output control.


3.3 Design of main unit circuits

3.3.1 Design of MCU main control module


3.3.2 Design of digital tube module


3.3.3 Design of LED lamp module

3.3.4 Power supply voltage regulator module


4.1 Program flow chart

4.2 Digital tube module flow chart

4.3 Key adjustment module design block diagram


5.1 Test Equipment

The multimeter can be used to detect whether there is continuity or short circuit.


5.2 Software Testing Platform Keil C51


5.3 Hardware Testing

5.3.1 Display module test

  

5.4 Test results analysis and conclusion

5.4.1 Test results analysis

The above functions can already be realized.

5.4.2 Test Conclusion

The testing has been completed and the required functionality has been achieved.


Works Summary

During the production process of this work, I became more comfortable and proficient in the use of multimeter, C language, and Proteus.


Appendix 1: System Circuit Diagram



Appendix 2: System C Program

#include

#define              uint unsigned int;

#define  uchar unsigned char;


void DigitalTube(); //Digital tube display function

void InterruptT0(); //Internal interrupt 0


sbit P10 = P1^0; // Initialization of traffic light pins

sbit P11 = P1^1;

sbit P12 = P1^2;

sbit P13 = P1^3;

sbit P14 = P1^4;

sbit P15 = P1^5;


sbit P16 = P1^6; // Digital tube enable control

sbit P17 = P1^7;

sbit P20 = P2^0;

sbit P21 = P2^1;


sbit K22 = P2^2; //key 22

sbit K23 = P2^3;

sbit K24 = P2^4;

sbit dula = P2^5;


uint LedBuf[10] = {

                              0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,

                            0x80,0x90

}; //0~9 digital display common anode


uint Kflag = 1; //Flag of key 24

uint LedNumNS = 27; //digital display of north and south

uint LedNumEW = 30; //Digital display of things

uint i = 0;

uint j = 0;

uint j1 = 0;

uint k = 0;

uint g = 0;

uint z = 0; //Count and status variables


uint LedTime1 = 30;

uint LedTime2 = 27;

uint LedTime3 = 30;

uint LedTime4 = 27;


uint Kf22 = 1; //The value of the previous state of the key

uint Kf23 = 1;

uint Kf24 = 1;

uint KSta24 = 1; //Current value of the button

uint KSta23 = 1;

uint KSta22 = 1;  

uchar Kflag22 = 0; //switch function parameter for key 22


void main()

{

              EA = 1; // Enable general interrupt

              ET0 = 1; //Open internal interrupt 0

              TR0 = 1;

              TMOD = 0x01; // Mode 1

              TH0 = 0xFC;

              TL0= 0x67; //1ms interrupt

              P1 = 0xEE;                            //


              while(1)

              {

                            DigitalTube(); //Digital tube display

              }


}



void InterruptT0() interrupt 1

{

                                                        TH0 = 0xFC;

                                                        TL0 = 0x67; //1ms interrupt             

                                                        i++;             

                                                        k++;

                                         

                                                        KSta24 = K24; //Key K24 Night Mode

                                                        if(Kf24 != KSta24) //The key is activated

                                                        {

                                                                      if(Kf24 == 1) //button pressed

                                                                      {

                                                                                    Kflag = !Kflag;                           

                                                                      }

                                                                      Kf24 = KSta24;

                                                        }

                                         



                                          KSta23 = K23; // Press K23 to increase or decrease the duration

                                          if(Kf23 != KSta23) //The key is activated

                                          {

                                                        if(Kf23 == 1) //button pressed

                                                        {

                                                        //              LedTime = LedTime +2;

                                                                      LedTime1 = LedTime1 +5; //32 34 36 38 30

                                                                      LedTime2 = LedTime2 +5;              //25  23 21  19 17

                                                                      LedTime3 = LedTime3 +5;

                                                                      LedTime4 = LedTime4 +5;

                                                                      if(LedTime1 >=60)

                                                                                    {

                                                                                                  LedTime1 = 10;

                                                                                                  LedTime2 = 7;

                                                                                                  LedTime3 = 10;

                                                                                                  LedTime4 = 7;

                                                                                    }             

                                                                      LedNumEW = LedTime1;

                                                                      LedNumNS = LedTime2;

                                                        }

                                                        Kf23=KSta23;

                                          }

                           



                                          KSta22 = K22; // Press K22 to turn on the red light in a certain direction for a long time

                                          if(Kf22 != KSta22) //The key is activated

                                          {

                                                        if(Kf22 == 1) //button pressed

                                                        {

                                                                      Kflag22 ++;             

                                                                      if(Kflag22>= 3)             

                                                                                    {

                                                                                    Kflag22 = 0;

                                                                                    }


                                                                      switch(Kflag22)

                                                                      {

                                                                                    case 1:

                                                                                                  LedTime1 = 50;

                                                                              LedTime2 = 47;              //case2

                                                                                                  LedTime3 = 20;

                                                                                                  LedTime4 = 17; //case1


                                                                                                  LedNumEW = LedTime1;

                                                                                                  LedNumNS = LedTime2;



                                                                                        break;

                                                                                    case 2:             

                                                                                                  LedTime1 = 20;

                                                                              LedTime2 = 17;                //case2

                                                                                                  LedTime3 = 50;

[1] [2]
Reference address:51 single-chip traffic light system design (flow chart + hardware + source code)

Previous article:Design of natural gas leak alarm system based on single chip microcomputer
Next article:STC89C52RC MCU + Serial Port + Infrared Control 16-channel Servo Program

Latest Microcontroller Articles
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号