Design of traffic light system based on single chip microcomputer

Publisher:平和的心态Latest update time:2022-04-02 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

#include

#define uchar unsigned char

#define uint unsigned int

 

sbit FMQ=P3^4;

sbit QR=P2^7;

sbit QY=P2^6;

sbit QG=P2^5;

sbit HR=P2^7;

sbit HY=P2^6;

sbit HG=P2^5;

sbit ZR=P2^4;

sbit ZY=P2^3;

sbit ZG=P2^2;

sbit YR=P2^4;

sbit YY=P2^3;

sbit YG=P2^2;

sbit SWITCH1=P1^0;

sbit SWITCH2=P1^1;

sbit SWITCH3=P1^2;

sbit SWITCH4=P1^3;

sbit P3_2=P3^2;

sbit P3_3=P3^3;

uchar DAT1, DAT2;    //display time variable

uchar DISP1[2]={0,0};    //Display buffer 1, north and south

uchar DISP2[2]={0,0};    //Display buffer 2, things

uchar code table[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,0xFF};

 

void DISPCLK1(volatile i);

void DISPCLK2(volatile i);

 

void DEL1MS(uint z)

{

    uint x,y;

for(x=0;x    for(y=0;y<123;y++);

}

 

void main()

{

     flying i,j;

TCON=0x5;

PX1=1;

EX0=1;

EX1=1;

EA=1;

 

P0=0xFF;

P1=0xFF;

P2=0xFF;

P3=0xFF;

while(1)

{

    P1=0xFF;

P2=0xFF;

DAT1=25;

DAT2=25;

QG=0;

HG=0;

ZR=0;

YR=0;

 

for(i=0;i<20;i++)

{

   for(j=0;j<200;j++)

   {

        DISPCLK1(DAT1);

DISPCLK2(DAT2);

DEL1MS(25); //delay 5 milliseconds

   }

   FMQ=1;

   DAT1=DAT1-1;

   DAT2=DAT2-1;

}

P1=0xFF;

P2=0xFF;

ZY=0;

YY=0;

QY=0;

HE=0;

 

for(i = 0; i < 5; i++)

{

for(j = 0; j < 200; j++)

{

DISPCLK1(DAT1); //display

DISPCLK2(DAT2); //display

DEL1MS(25); //Delay 3 milliseconds

}

QY = ~QY; //The yellow light is on in the north-south direction

HE = ~HE;

ZY = ~ZY; //The yellow light is on in the east-west direction

YY = ~YY;  

FMQ = ~FMQ; //Buzzer beeps when the light turns yellow

DAT1 = DAT1 - 1; //Complete the digital subtraction operation, and send the adjusted digital to the video memory  

DAT2 = DAT2 - 1; //Complete the digital subtraction operation, and send the adjusted digital to the video memory  

P1 = 0xff;

P2 = 0xff;  

DAT1 = 15; //Assembly 0x20

DAT2 = 15; //Assembly 0x20

ZG = 0; //The green light is on in the east-west direction

YG = 0;

QR = 0; //Red light on in north-south direction

HR = 0;

 

for(i = 0; i < 10; i++) //Execute for 15 seconds

{

for(j = 0; j < 200; j++)

{

DISPCLK1(DAT1); //display

DISPCLK2(DAT2); //display

DEL1MS(25); //Delay 3 milliseconds  

}

FMQ = 1; //Buzzer sounds

DAT1 = DAT1 - 1; //Complete the digital subtraction operation, and send the adjusted digital to the video memory 

DAT2 = DAT2 - 1; //Complete the digital subtraction operation, and send the adjusted digital to the video memory 

}

 

//The yellow light flashes in the last 5 seconds

P1 = 0xff;

P2 = 0xff; // Turn off all lights

ZY = 0; //yellow light on

YY = 0;

QY = 0;

HE = 0;

 

for(i = 0; i < 5; i++)

{

for(j = 0; j < 200; j++)

{

DISPCLK1(DAT1); //display

DISPCLK2(DAT2); //display

DEL1MS(25); //Delay 3 milliseconds    

}

QY = ~QY; //The yellow light is on in the north-south direction

HE = ~HE;

ZY = ~ZY; //The yellow light is on in the east-west direction

YY = ~YY;  

FMQ = ~FMQ; //Buzzer beeps when the light turns yellow

DAT1 = DAT1 - 1; //Complete the digital subtraction operation, and send the adjusted digital to the video memory  

DAT2 = DAT2 - 1; //Complete the digital subtraction operation, and send the adjusted digital to the video memory  

}

}

 

void D_X() interrupt 0 using 0

{

    fly i,j,temp0,temp1,temp2,temp3;

EA=0;

P3_2=1;

while(!P3_2);

temp0=DAT1;

temp1=DAT2;

temp2=P1;

temp3=P2;

 

DAT1=60;

DAT2=60;

P1=0xff;

P2=0xff;

ZG=0;

YG=0;

QR=0;

HR=0;

 

for(i=0;i<60;i++)

{

    for(j=0;j<200;j++)

{

    DISPCLK1(DAT1);

DISPCLK2(DAT2);

DEL1MS(25);

}

DAT1=DAT1-1;

DAT2=DAT2-1;

}

DAT1=temp0;

DAT2=temp1;

P1=temp2;

P2=temp3;

 

EA=1;

}

 

void N_B() interrupt 2 using 0

{

    fly i,j,temp0,temp1,temp2,temp3;

EA=0;

P3_3=1;

while(!P3_3);

temp0=DAT1;

temp1=DAT2;

temp2=P1;

temp3=P2;

 

DAT1=60;

DAT2=60;

P1=0xff;

P2=0xff;

ZR=0;

YR=0;

QG=0;

HG=0;

for(i=0;i<60;i++)

{

    for(j=0;j<200;j++)

{

    DISPCLK1(DAT1);

DISPCLK2(DAT2);

DEL1MS(25);

}

DAT1=DAT1-1;

DAT2=DAT2-1;

}

DAT1=temp0;

DAT2=temp1;

P1=temp2;

P2=temp3;

 

EA=1;

}

 

void DISPCLK1(volatile i)

{

    DISP1[0]=i%10;

DISP1[1]=i/10;

P0=table[DISP1[0]];

SWITCH2=0;

DEL1MS(2);

SWITCH2=1;

 

P0=table[DISP1[1]];

SWITCH1=0;

DEL1MS(2);

SWITCH1=1;

}

 

void DISPCLK2(float i)

{

    DISP2[0]=i%10;

DISP2[1]=i/10;

P0=table[DISP2[0]];

SWITCH4=0;

DEL1MS(2);

SWITCH4=1;

 

P0=table[DISP2[1]];

SWITCH3=0;

DEL1MS(2);

SWITCH3=1;

}

Reference address:Design of traffic light system based on single chip microcomputer

Previous article:Temperature and humidity detection system based on single chip microcomputer
Next article:Design of intelligent lighting control system based on single chip microcomputer

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号