#include #include "./delay/delay.h" sbit seg_select = P2^1; sbit bit_select = P2^0; sbit key1 = P1^0; #define SEGPORT P0 unsigned char segdata[10] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f}; unsigned char bitdata[8] = {0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f}; unsigned char TempData[2]; void display(void) { /*eliminate ghosting*/ static unsigned char i = 0; SEGPORT = 0x0; seg_select = 1; seg_select = 0; SEGPORT = 0xff; bit_select = 1; bit_select = 0; SEGPORT = TempData[i]; seg_select = 1; seg_select = 0; SEGPORT = bitdata[i]; bit_select = 1; bit_select = 0; i++; if(2 == i) { i = 0; } } void timer0_init(void) { EA = 1; // Enable general interrupt TMOD |= 0x01; //Select interrupt mode TH0 = (65536 - 2000) / 256; TL0 = (65536 - 2000) % 256; ET0 = 1; TR0 = 1; } void timer0_isr(void) interrupt 1 { TH0 = (65536 - 2000) / 256; TL0 = (65536 - 2000) % 256; display(); } void main() { unsigned char disdata = 0; timer0_init(); while(1) { /*Debounce*/ if(0 == key1) //A key is pressed { delay_ms(10); if(0 == key1) //A key is pressed { while(!key1); //A key is lifted delay_ms(10); while(!key1); //A key is actually lifted } disdata++; if(100 == disdata) { disdata = 0; } } TempData[0] = segdata[disdata / 10]; TempData[1] = segdata[disdata % 10]; } } /************************************/ /*delay.h*/ #define _DELAY_H_ extern void delay_us(unsigned char t); extern void delay_ms(unsigned char t); extern void delay_s(unsigned char t); #endif /***************************************/ /*delay.c*/ { while(--t); } void delay_ms(unsigned char t) { while(t--) { delay_us(245); delay_us(245); } } void delay_s(unsigned char t) { while(t--) { delay_ms(200); delay_ms(200); delay_ms(200); delay_ms(200); delay_ms(200); } } #ifndef _DELAY_H_
void delay_us(unsigned char t)
Previous article:Matrix keyboard driver for single chip microcomputer
Next article:Using the digital tube of the single chip computer to simulate the clock to display time
- 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
- APWM
- Industrial computer case
- EEWORLD University Hall----Live Replay: Datang NXP-DNS Battery Management Chip Solution
- 5G Network Slicing
- Static Electricity Protection Measures in Circuits
- Portable energy storage power supply-Nanxin Semiconductor enters the market with strength
- Summary of the characteristics of 5 wireless transmission protocols for the Internet of Things
- Can dual 12V power supplies be used in parallel?
- MSP-FET430UIF driver cannot be installed in Windows 7
- Use GD32 to make a music spectrum to practice