Application of interrupts and digital tubes - "9999" countdown table
#include unsigned char code LedChar[10]={//Numbers displayed by the digital tube 0~9 0XC0,0XF9,0XA4,0XB0,0X99,0X92,0X82,0XF8,0X80,0X90}; unsigned char LedBuff[4]={//The buffer area displayed by the digital tube 0XFF,0XFF,0XFF,0XFF}; sbit Tube1 = P1^0; sbit Tube2 = P1^1; sbit Tube3 = P1^2; sbit Tube4 = P1^3; unsigned char i = 0; unsigned int cnt = 0; //interrupt times unsigned long sec = 0; //Record the number of seconds that have passed void main() { // Enable T0 interrupt EA = 1; ET0 = 1; //Set T0 TMOD = 0X01; TH0 = 0XFFED; TL0 = 0XFFFF; TR0 = 1; while(1) { if(cnt>500) { cnt = 0; sec++; } LedBuff[0] = LedChar[9-sec%10]; LedBuff[1] = LedChar[9-sec/10%10]; LedBuff[2] = LedChar[9-sec/100%10]; LedBuff[3] = LedChar[9-sec/1000%10]; } } //Timer 0 interrupt service void InterruptTimer() interrupt 1 { TH0 = 0XFFED; TL0 = 0XFFFF; cnt++; switch(i) { case 0: P0 = LedBuff[0];Tube1=0;Tube2=1;Tube3=1;Tube4=1;i++;break; case 1: P0 = LedBuff[1];Tube1=1;Tube2=0;Tube3=1;Tube4=1;i++;break; case 2: P0 = LedBuff[2];Tube1=1;Tube2=1;Tube3=0;Tube4=1;i++;break; case 3: P0 = LedBuff[3];Tube1=1;Tube2=1;Tube3=1;Tube4=0;i=0;break; default:break; } }
Previous article:#51 MCU#button
Next article:#51 single chip microcomputer#Static and dynamic display of digital tube
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Analysis of the application of several common contact parts in high-voltage connectors of new energy vehicles
- Wiring harness durability test and contact voltage drop test method
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- Sn-doped CuO nanostructure-based ethanol gas sensor for real-time drunk driving detection in vehicles
- Design considerations for automotive battery wiring harness
- Do you know all the various motors commonly used in automotive electronics?
- What are the functions of the Internet of Vehicles? What are the uses and benefits of the Internet of Vehicles?
- Power Inverter - A critical safety system for electric vehicles
- Analysis of the information security mechanism of AUTOSAR, the automotive embedded software framework
- Showing off the goods + the board that got me into it
- EEWorld 15th Anniversary Tool DIY Event Summary
- I need help from the experts on a question about proteus8
- [Solved] How to start DSP on ARM
- Recruitment position in Xiamen IC design company: MCU product development engineer
- 【Running posture training shoes】No.006-Bluetooth communication program design
- Can STM32 use a timer to control PWM output
- As shown in the figure, the netlist is transferred to the PCB, and these four networks form GND_SIGNAL_20640, which is not connected to GND_SIGNAL.
- mpy implements partial PEP-498 (f-string) support
- IAR_msp430 built-in delay function