Traffic light program of 51 MCU + 8155 chip

Publisher:快乐兔子Latest update time:2020-09-11 Source: 51hei Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere


The microcontroller source program is as follows:

#include

# include


#define uchar unsigned char //Defined as uchar type

#define uint unsigned int //Defined as uint type

#define COM XBYTE[0XFE00] //Control word address (overall control, determines whether PA/B/C is writing or reading, etc.)

#define PA XBYTE[0XFE01] //Control PA address (when the total control is written to read, the value stored in it is the read value;

                                                           // When writing, the control value should be written in it)

#define PB XBYTE[0XFE02] //control PB address

#define PC XBYTE[0XFE03] //Control PC address


sbit g = P2^1;

sbit s = P2^2;

sbit eg = P2^3;

sbit ws = P2^4;

//sbit Key_N = P1^4; //Independent key

//sbit Key_S = P1^5;

//sbit Key_W = P1^6;

//sbit Key_E = P1^7;

sbit KEYA = P1^4;

sbit KEYB = P1^5;           

uint ge,shi; //define global variables

if m = 30;

uint n;

whether


/*Traffic light value*/

uchar lcd1 = 10; //The countdown initial value is 25 for changing

uchar lcd2 = 15; //The countdown initial value is 30 for changing

uchar lcd11; // countdown

uchar lcd22; // countdown

uchar change1; //LCD1 traffic light switch

uchar yellow1 = 3;


/*Declaration of some auxiliary flags*/

uchar code smguan[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90}; //digital tube displays 0~9

flying t=3;

volatile sign = 0;

uchar time_Count; //Counting


void delay(uint t)

{

          while(t--);

}


void Digital(uint ge,uint shi) //digital tube display

{         

                  PA = smguan[ge];

                s = 1;

                delay(500);

                s = 0;


                PA = smguan[shi];

                g = 1;

                delay(500);

                g = 0;


                PB = smguan[ge];

                eg = 1;

                delay(500);

                eg = 0;


                PB = smguan[shi];

                ws = 1;

                delay(500);

                ws = 0;                                                   

     }

                  

void Traffic_lights()

{

    if(t == 3)

      {

                  P1 = 0x01;

        if(m == 0)

          {

                m = 3;

                t = 2;

              }

           }


        if(t == 2)

        {

          P1 = 0x02;                        

      if(m == 0)

      {

            m = 30;

                t = 1;

          }

        }

               

        if(t == 1)

    {

     P1 = 0x04;

     if(m == 0)

      {

           m = 3;            

       t = 0;  

          }

        }


   if(t == 0)

        {

          P1 = 0x02;                        

      if(m == 0)

      {

            m = 30;

                t = 3;

          }

        }  

}        


void INIT()

{

  IT0=1;

  IT1=1;

  EX0=1;

  EX1=1;

  EA=1;

}


Reference address:Traffic light program of 51 MCU + 8155 chip

Previous article:Design of PWM speed regulation of DC motor based on single chip microcomputer
Next article:Design of automatic resistance furnace temperature controller based on single chip microcomputer PID control

Recommended ReadingLatest update time:2024-11-16 13:58

51 MCU Programming Section 6: Low Frequency Frequency Meter
Section 6: Low Frequency Frequency Meter Example purpose: learning timer, counter, interrupt application Description: Choose a 24MHz crystal, the main frequency can reach 2MHz. Use T1 to generate a 100us time scale, and T0 as a signal pulse counter. Assume that the crystal frequency has no error and is stable (actual
[Microcontroller]
Microcontroller Basics (IV): C51 Extensions to C Language
C51's extension of C language C51 differs from standard C language in terms of data structure, I/O processing, functions, etc. data structure sfr, sfr16 Special function register type variables Special Function Register (SFR) plays an important role in microcontrollers. Common SFR is 8-bit, so sfr16 is used to r
[Microcontroller]
Microcontroller Basics (IV): C51 Extensions to C Language
Introduction to 51 MCU timer settings (STC89C52RC)
Introduction to 51 MCU Timer Settings (STC89C52RC) STC MCU Timer Setting The use of STC MCU timer can be said to be very simple, as long as you understand the principle and have a basic understanding of C language. The key points are as follows: 1. You must know the original form of the English abbreviation, so
[Microcontroller]
51 single chip microcomputer realizes the dynamic scanning program of driving digital tube in the main function while loop
1. Use proteus to draw a simple circuit diagram for subsequent simulation 2. Programming /******************************************************************************************************************** ---- @Project: LED-74HC595 ---- @File: main.c ---- @Edit: ZHQ ---- @Version: V1.0 ---- @CreationTim
[Microcontroller]
51 single chip microcomputer realizes the dynamic scanning program of driving digital tube in the main function while loop
Complete solution to the difficult problems of 51 single-chip microcomputer crystal oscillator
Looking back, when I first learned about 51 single-chip microcomputers, I always encountered many problems related to crystal oscillators. In fact, the crystal oscillator is like the human heart, the blood and the pulse. Once the crystal oscillator problem of the single-chip microcomputer is understood, other problems
[Microcontroller]
Simulation of Motor Speed ​​Measurement System Based on AT89C51 Single Chip Microcomputer
The simulation system of the single-chip microcomputer motor speed measurement system uses the T1 counter in the single-chip microcomputer to count the speed pulses. Timer T1 works in the external event counting mode to count the speed pulses; T0 works in the timer mode. The count value is read once every 1 s. This va
[Microcontroller]
Simulation of Motor Speed ​​Measurement System Based on AT89C51 Single Chip Microcomputer
Briefly describe the structure and principle of 8051 microcontroller
The basic structure of the microcontroller includes six parts: central processing unit (CPU), memory, timer/counter, input and output interface, interrupt control system and clock circuit. 1. Basic composition Central processing unit (CPU) Including the arithmetic unit and the controller, it is the core of the mic
[Microcontroller]
Briefly describe the structure and principle of 8051 microcontroller
The microcontroller part of the program for serial communication between C51 microcontroller and PC
Note that the baud rate is 9600 Function: The computer sends a byte to the MCU through the serial port, and the MCU sends it back to the computer after receiving it. #include reg52.h #define uchar unsigned char #define uint unsigned int uint temp; bit flag; void init_ser1(); main() { init_ser1(); whil
[Microcontroller]
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号