#include
#define uchar unsigned char
#define uint unsigned int
sbit K1=P3^7;
fly
i,Second_Counts,Key_Flag_Idx;
bit Key_State;
fly
DSY_CODE[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
//Delay
void DelayMS(uint ms)
{
flying t;
while(ms--) for(t=0;t<120;t );
}
//Handle key events
void Key_Event_Handle()
{
if(Key_State==0)
{
Key_Flag_Idx=(Key_Flag_Idx 1)%3;
switch(Key_Flag_Idx)
{
case 1:EA=1;ET0=1;TR0=1;break;
case 2:EA=0;ET0=0;TR0=0;break;
case 0:P0=0x3f;P2=0x3f;i=0;Second_Counts=0;
}
}
}
//Main program
void main()
{
P0=0x3f; //display 00
P2=0x3f;
i=0;
Second_Counts=0;
Key_Flag_Idx=0; //Number of key presses (values 0, 1, 2, 3)
Key_State=1; //Key status
TMOD=0x01; //Timer 0 mode 1
TH0=(65536-50000)/256; //Timer 0: 15ms
TL0=(65536-50000)%6;
while(1)
{
if(Key_State!=K1)
{
DelayMS(10);
Key_State=K1;
Key_Event_Handle();
}
}
}
/T0 interrupt function
void DSY_Refresh() interrupt 1
{
TH0=(65536-50000)/256; //Restore the initial value of timer 0
TL0=(65536-50000)%6;
if( i==2)
{
i=0;
Second_Counts; //50ms*2=0.1s conversion state
P0=DSY_CODE[Second_Counts/10];
P2=DSY_CODE[Second_Counts];
if(Second_Counts==100) Second_Counts=0; //Display 00 after reaching 100 (10s)
}
}
Previous article:Have you ever thought about the issue of program efficiency?
Next article:A brief comparison between 89C51 and STM8
Recommended ReadingLatest update time:2024-11-16 14:57
- Popular Resources
- Popular amplifiers
- Wireless Sensor Network Technology and Applications (Edited by Mou Si, Yin Hong, and Su Xing)
- Modern Electronic Technology Training Course (Edited by Yao Youfeng)
- Modern arc welding power supply and its control
- Small AC Servo Motor Control Circuit Design (by Masaru Ishijima; translated by Xue Liang and Zhu Jianjun, by Masaru Ishijima, Xue Liang, and Zhu Jianjun)
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
- Fundamentals of Analog Electronics Technology (Lectured by Hua Chengying)
- Is this kind of isolation useful for external signal interference?
- Building a BLE development environment
- EEWORLD University Hall----Live Replay: 5G and Edge Computing Development and Technology Application
- EEWORLD University Hall----Enabling JTAG Communication on UCD3138 Series
- MSP430G2755 Main Memory Bootloader UART Porting Guide
- EEWORLD University Hall - A vivid introduction: What is Fourier transform
- Advanced attitude solution: complementary filtering (gyroscope, accelerometer, magnetometer data fusion)
- Quartus simulation software cannot be opened
- 【Recruitment】Ability, Dream, and FUTURE