The following simulation effect diagram can be made according to the above circuit
/** //Imitate the stopwatch timing function, and the independent button can control the "pause/move" of the timing numbers. (The program does not consider the timing accuracy control) /*P2.2~P2.4 are connected to the 138 decoder input port /*P1.0 connects to independent button /*P0 port output data ***/ #includecode unsigned char tab[]={0x3f,0x06,0x5b,0x4f,0x66, 0x6d,0x7d,0x07,0x7f,0x6f,0x40}; // Common cathode digital tube 0-9 '-' 'off' table unsigned int count,a,b,sec,min,hour; bit c_flag; // Pause/timing flag /*****T1 initialization*****/ void timer_1(void) { TH1=0x0ec; TL1=0x078; TR1=1; } /*****Data Count******/ void time_count(viod) { if(hour==60){sec=0,min=0,hour=0;} else if(sec!=59) sec++; else if(min!=59) {sec=0,min++;} else {min=0,hour++;} } /******Digital Adjustment*******/ void get_count(unsigned int x) { a=x/10; b=x%10; } /*******Key detection********/ void key_tach(void) { int i,j; j=P1&0x01; if(j==0){ for(i=0;i<=200;i++); j=P1&0x01; if(j==0) {if(c_flag==1) c_flag=0; else c_flag=1;} } } /*******Display program********/ void display(viod) { int flag; P0=0x00; flag=count%8; switch(flag){ case 0:P2=flag*4; get_count(hour); P0=tab[a]; break; case 1:P2=flag*4; P0=tab[b]; break; case 2:P2=flag*4; P0=tab[10]; break; case 3:P2=flag*4; get_count(min); P0=tab[a]; break; case 4:P2=flag*4; P0=tab[b]; break; case 5:P2=flag*4; P0=tab[10]; break; case 6:P2=flag*4; get_count(sec); P0=tab[a]; break; case 7:P2=flag*4; P0=tab[b]; break; default:return; } } /*******Interrupt service routine********/ void int1() interrupt 3 { key_tach(); if(c_flag==0) { if(count==7) {count=0;time_count();} else count++;} else { if(count==7) {count=0;} else count++;} display(); timer_1(); } /******Main program*****/ void main() { c_flag=0; count=0; sec=0; min=0; hour=0; TMOD=0x10; EA=1; ET1=1; timer_1(); while(1); }
Previous article:Program for microcontroller to control the on and off of three LED lights
Next article:Slide type digital tube display
- 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
- TE Live | How to effectively respond to the challenges in the current test and measurement field? Hot recruitment
- stm32 pwm fails after eight cycles
- A preliminary study on STEVAL-MKI109V3 debugging and logic construction
- SS805 base current setting upper limit problem
- An article to understand the commonly used microwave transmission lines (I)
- [Q&A] About the selection of C2000
- Summary of MCU delay methods
- Who can teach me?
- Understanding the Q and D values of capacitors
- Raspberry Pi Pico User Guide - by dcexpert