This program is modified from the source program of Huang Ying, and runs successfully on the MCU board. Here is the hardware information of the board http://www.51hei.com/mcu/1019.html. The digital tube is a four-bit common anode tube. The program has not been simulated.
Reference address:Traffic light control
#include#define uint unsigned int #define uchar unsigned char uint temp,temp1,temp2,num,shi,ge,i,j; uchar code table[]= {0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90}; sbit WX1=P0^0; sbit WX2=P0^1; sbit WX3=P0^2; sbit WX4=P0^3; sbit NBL=P2^2; sbit NBY=P2^1; sbit NBR=P2^0; sbit DXL=P2^5; sbit DXY=P2^4; sbit DXR=P2^3; void init() { P0=0xff; P2=0xff; temp=0; temp1=0; temp2=0; it=0; ge=0; TMOD=0x21; TH0=0x3c; //50ms TL0=0xb0; EA=1; ET0=1; TF0=0; TR0=1; } void delay(float z) { fly x,y; for(x=110;x>0;x--) for(y=z;y>0;y--); } void display() { shi=num/10; ge=num%10; P1=table[ge]; WX3=1; WX2=0;WX1=0;WX4=0; delay(10); WX2=1; P1=table[shi]; WX2=1; WX3=0;WX1=0;WX4=0; delay(10); WX3=1; } void time0() interrupt 1 using 1 { temp++; temp1++; TH0=0x3c; TL0=0xb0; TR0=1; } void main() { heat(); while(1) { if(temp==0) { DXR=1; NBY=1; DXL=0; NBR=0; num=21; temp1=0; for(i=20;i>0;i--) { num--; while(temp1!=20) { display(); } temp1=0; } } if(temp==400) { DXY=1; NBR=0; DXL=0; num=3; j=0; for(i=7;i>0;i--) { j++; if(j%2==0) { num--; } temp2=temp; DXL=!DXL; //The light flashes while(temp-temp2!=10) { display(); }; } } if(temp==470) { DXL=1; DXY=0; NBR=0; num=3; temp1=0; for(i=3;i>0;i--) { num--; while(temp1!=20) { display(); } temp1=0; } if(temp==530) { DXY=1; DXR=0; NBR=1; NBL=0; num=26; temp1=0; for(i=25;i>0;i--) { num--; while(temp1!=20) { display(); } temp1=0; } } if(temp==1030) { DXY=1; DXR=0; NBL=0; num=3; j=0; for(i=7;i>0;i--) { j++; if(j%2==0) { num--; } temp2=temp; NBL=!NBL; //The light flashes while(temp-temp2!=10) { display(); }; } } if(temp==1100) { DXL=1; DXR=0; NBY=0; num=3; temp1=0; for(i=3;i>0;i--) { num--; while(temp1!=20) { display(); } temp1=0; } temp=0; } } } }
Previous article:Making Month Calculator with Single Chip Microcomputer
Next article:Digital tube dynamic display program
- Popular Resources
- Popular amplifiers
Recommended Content
Latest Microcontroller Articles
He Limin Column
Microcontroller and Embedded Systems Bible
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
MoreSelected Circuit Diagrams
MorePopular Articles
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
MoreDaily News
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
Guess you like
- Understanding Thermal Analysis of GaN
- [Repost] Direct current is more suitable for home use, so why is civilian electricity alternating current?
- EEWORLD University Hall----Live Replay: Wireless Technology Changes Smart Life
- EEWORLD University ---- Yunlong 51 MCU video tutorial
- Several LM386 audio amplifier circuits shared
- MSP430G2553 button interrupt configuration
- Thank you for being my confidant
- Suspicious signal from outer space
- Download gift: USB Type C related development and test materials, read it when you have nothing to do, and you will become a master by accident
- Qorvo explains WIFI and 5G clearly