We still use STC's 8051 microcontroller. This code is used to make a timer, which is displayed in real time through a digital tube. Because there are 6 digital tubes on the board, you can set the hours, minutes, and seconds. It can also be simulated on Proteus. When the timing ends, you can use a buzzer or a relay interface connection.
An alarm clock. An electromagnetic alarm clock will do. Of course, a buzzer is a good choice.
The program does not set the hour unit. Friends who want to add it can use the method of displaying minutes and seconds to display it. However, you should pay attention to the delay time after adding it. Improper time setting may cause unclear display, digital jitter, or unselected digital tubes to glow faintly ("ghosting"). You can debug the specific size yourself, which is also very simple. The following is the source code:
#include #define uint unsigned int #define uchar unsigned char sbit we=P2^7; bit du=P2^6; uchar code table[]={0x3f,0x06,0x5B,0x4F,0x66, 0x6D,0x7D,0x07,0x7F,0x6F, 0x77,0x7C,0x39,0x5E,0x79, 0x71,0x76,0x38,0x37,0x3E, 0x73,0x5C,0x40,0x00,}; uchar num=0,aa,s,g,m,f,h; void delay(volatile x); void main() { TMOD=0x01; //Set the internal interrupt 0, 1 to work in mode 1 EA=1; //Open the general interrupt ET0=1; //Enable interrupt TR0=1; //Open interrupt 0 TH0=0x4c; TL0=0x00; while(1) { du = 1; P0 = 0; du = 0; we = 1; P0 = 0x3e; we = 0; du = 1; P0 = table[s]; //ten digit du = 0; delay(10); du = 1; P0 = 0; du = 0; we = 1; P0 = 0x3d; we = 0; du = 1; P0 = table[g]; //unit du = 0; delay(10); du = 1; P0 = 0; du = 0; we = 1; P0 = 0x1f; //Display minutes we = 0; du = 1; P0 = table[m]; du = 0; delay(10); du = 1; P0 = 0; du = 0; we = 1; P0 = 0x2f; we = 0; du = 1; P0 = table[h]; du = 0; delay(10); if(aa == 20) { aa = 0; if(num == 59) { num = 0; f++; } else num++; s = number/10; g = num%10; m = f%10; h = f/10; } if(h == 6) f = 0; } } void timer0() interrupt 1 //Internal interrupt 0 { TH0=0x4c; TL0=0x00; aa++; } void delay(fly x) { uchar y,z; for(y=x;y>0;y--) for(z=120;z>0;z--); }
Previous article:51 MCU simple timer
Next article:51 MCU timer
Recommended ReadingLatest update time:2024-11-16 13:04
- Popular Resources
- Popular amplifiers
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
- This piece of clothing generates energy through movement. Can it help solve the problem of a cell phone running out of battery?
- Current sampling in FOC
- TI designs next-generation industrial drive and control systems
- About LM5117 overcurrent protection --- from a provincial competition question in 2016
- Analyzing a USB PD decoy chip
- CCS installation package
- TI C600 Compile Feedback Output Related Options
- ST NUCLEO-L452RE development board evaluation report summary
- USB communication design example based on CH559 MCU Android AOA protocol
- Technical article | How to use J-Link to burn SPI Flash