Functions implemented by the program:
1. After the experiment box is powered on, the two timers start timing, but no display is given.
2. If the "display seconds" command is sent to 8051, a specified countdown timer will display the seconds.
3. If the "hide seconds" command is sent to 8051, the specified countdown timer will be hidden for the specified number of seconds.
#include <STC89C5xRC.H>
#include unsigned char code DIG_CODE[10] = {0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f}; //The corresponding digital tube displays 0~9 char buf[30]; //Store the received command int tcount = 0; //Record the number of 5ms intervals passed int sec1 = 15, sec2 = 25; // countdown initial value int sec1_ = 0, sec2_ = 0; //Real-time changes int en1 = 0, en2 = 0; //Two timer seconds display flags, default is not displayed void T0_INT() interrupt 1 //timer0 interrupt, triggered every 5ms { TR0 = 0; // turn off timer0 TH0 = 0xEC; TL0 = 0x78; //65536 - 5000 = 60536 if(tcount % 4 == 0) { if(en1 == 1) { //Display the single digit (first countdown timer) P2 = 0; // P2 = 0 -> (P24, P23, P22) = (0, 0, 0) -> the first number from the right lights up P0 = DIG_CODE[sec1_ % 10]; } tcount++; } else if(tcount % 4 == 1) { if(en1 == 1) { //Display the ten digits (first countdown timer) P2 = 1 << 2; //P2 = 0000 0100 -> (P24, P23, P22) = (0, 0, 1) -> the second digit from the right lights up P0 = DIG_CODE[sec1_ / 10]; } tcount++; } else if(tcount % 4 == 2) { if(en2 == 1) { //Display the single digit (second countdown timer) P2 = 100 << 2; //P2 = 0001 0000 -> (P24, P23, P22) = (1, 0, 0) -> the fifth number from the right lights up P0 = DIG_CODE[sec2_ % 10]; } tcount++; } else if(tcount % 4 == 3) { if(en2 == 1) { //Display the tens digit (second countdown timer) P2 = 101 << 2; //P2 = 0001 0100 -> (P24, P23, P22) = (1, 0, 1) -> the sixth digit from the right lights up P0 = DIG_CODE[sec2_ / 10]; } tcount++; } if(tcount == 200) { tcount = 0; if(-- sec1_ == -1) { sec1_ = sec1; } if(-- sec2_ == -1) { sec2_ = sec2; } } TR0 = 1; //Restart timer0 } int main() { int i = 0; P2 = 111 << 2; //Select the first number from the left P0 = 0; // Digital tube off TMOD = 0x21; SCON = 0x50; //Set serial communication format TH0 = 0xEC; TL0 = 0x78; //65536 - 5000 = 60536 = EC78H TH1 = 0xE6; TL1 = 0xE6; IE = 0x82; TR0 = 1; // turn on timer0 TR1 = 1; // turn on timer1 while(1) { if(RI == 1) //If data is received { RI = 0; buf[i++] = SBUF; //Receive data from the serial port buf[i] = ''; //Manually add the end of string mark if(i == 29) //Prevent array access out of bounds { i = 0; } if(buf[i - 1] == 'E') // reach the end { i = 0; if(strcmp(buf, "Show countdown 1st.E") == 0) //Show countdown 1st.E command { en1 = 1; } else if(strcmp(buf, "Hide countdown 1st.E") == 0) //Hide countdown 1st.E command { en1 = 0; } else if(strcmp(buf, "Show countdown 2nd.E") == 0) //Show countdown 2nd.E command { en2 = 1; } else if(strcmp(buf, "Hide countdown 2nd.E") == 0) //Hide countdown 2nd.E command { en2 = 0; } } } } return 0; }
Previous article:Dual countdown timer based on 8051 (Version 1.0)
Next article:8051 MCU implements a single countdown timer with modifiable initial value (and command to start and stop)
- 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
- [National Competition Interview] “Three weaklings” won the first prize for question H, and the winners who won by luck are here! ?
- Kuyuan Electric Allegro video training
- What are the differences between precision op amps, instrument op amps, and general-purpose op amps?
- Detailed explanation of the principle of lora spread spectrum technology
- Questions about oscilloscope and USB flash drive
- EEWORLD University ---- Digital Circuit Design
- Disassembled a solar lamp
- Summary: About 2.4G NRF24L01 wireless module
- What is the difference between a chip's "data sheet" and "technical documentation"?
- Capacitive sensor measurement system module circuit design precision amplifier circuit