This article mainly introduces the self-increment function of the digital tube display based on the MCS-51 single-chip microcomputer, which displays from 1 to 999. The following is the hardware circuit diagram, function implementation diagram and source code. (Circuit: Use 74HC573 latch to control segment selection, 74H138 to control bit selection;)
Code to realize self-addition of digital tube:
#include
#define uchar unsigned char
#define uint unsigned int
uchar code table[16] = {0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,0x7f,
0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71}; //Display digital table
uchar flag,bai,shi,ge;
uint temp;
void xunhuan();
void delay(uint z);
void init();
void main()
{
init();
while(1)
{
if(flag==20)
{
flag=0;
temp++;
if(temp==1000)
{
temp=0;
}
}
bai=temp/100;
shi=temp%100/10;[page]
ge=temp%10;
xunhuan();
}
}
void xunhuan()
{
P2=0;
P0=table[bai];
delay(30);
P2=1;
P0=table[shi];
delay(30);
P2=2;
P0=table[ge];
delay(30);
}
void init()
{
TMOD=0x01; //Timer 0
TH0=(65536-50000)/256; //timing 50ms
TL0=(65536-50000)%256;
EA=1;
ET0=1;
TR0=1;
}
void timer0() interrupt 1
{
TH0=(65536-50000)/256; //timing 50ms, 1m=1000ms=20*50ms
TL0=(65536-50000)%256;
flag++;
}
void delay(uint z)
{
uchar x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
Previous article:Microcontroller Teaching Based on Keil C51 Integrated Development Environment
Next article:Design of serial communication based on AT89C51 single chip microcomputer application system
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- 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
- 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
- Eight practical ways to solve Spark data skew
- Will it damage the phone or battery if I play games while charging my phone after it is fully charged?
- [NXP Rapid IoT Review] + Experience of using Rapid IOT Studio
- My goodness, what kind of electronic component is this?
- Record errors encountered in CCS
- How to choose TVS tube for MSP430FR2633 touch chip
- 【RPi PICO】 Pi calculation test
- The sequel is here! Is it okay to have no reference? Let me explain it all at once!
- esp32
- Practical information delivery: Digital power technology literacy