/*
Program effect: running seconds, displaying four digital tubes at the same time
Copyright: http://www.51hei.com Please keep it when reprinting.
P1 controls the bit of the digital tube, P2 controls the segment
Note: If you cannot compile in Keil, please delete all leading blanks in each line,
*/
#include
#define uchar unsigned char //Macro definition
#define uint unsigned int
void display(); //Function declaration
uchar code table[]={0x3f,0x06,0x5b,//Number displayed by the digital tube
0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
void delay(uchar x) //Delay function, I can't calculate the time
{
uchar i,j;
for(i=x;i>0;i--)
for(j=110;j>0;j--);
}
void main() //Main function
{
while(1)
{
display(); //Display subfunction
}
}
void display()
{
uchar i,j,k,l; //Define local variables
P1=0xff; //Light up the rightmost digital tube
P2=table[i]; //Send value, display each digit
delay(10); //Delay
i++; //Increase by one, as a reference for the next display
if(i==10)
{
i=0; //When i value reaches 10, clear
j++;
P1=0xfe; //Light up the next digital tube
P2=table[j];
delay(10);
}
if(j==10)
{
j=0;
k++;
P1=0xfd;
P2=table[k];
delay(10);
}
if(k==10)
{
k=0;
l++;
P1=0xfc;
P2=table[l];
delay(10);
if(l==10)
l=0;
}
//The following statement is indispensable
P1=0xfe; //Display tens digit
P2=table[j];
delay(10);
P1=0xfd; //display hundreds digit
P2=table[k];
delay(10);
P1=0xfc; //display thousands digit
P2=table[l];
delay(10);
}
Note: If you cannot compile in Keil, please delete all leading spaces in each line.
Previous article:Keyboard interface programming: addition and subtraction operations
Next article:Method of Accurate Delay (Timing) Using C Language of Single Chip Microcomputer
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
- [Help] What kind of software is this that can implement this host computer monitoring system?
- How to make the CLK of tms320c6678 SPI output 8 clock cycles each time
- What is the effect of connecting the SW pin of the switching power supply to the capacitor and resistor in series to GND?
- EEWORLD University ----TI LED Driver
- Doorbell program + circuit made by AVR microcontroller timer
- AR1021X series WiFi module selection reference and driver discussion in the field of wireless image transmission
- 2812 TxPR register write failure caused by TxCON highest bit
- Fabrication process of fiber-embedded microfluidic chip
- TMS320F28335 general purpose input/output port GPIO related register introduction
- On-line debugging method for embedded processors