/* The 8-digit digital tube displays the time in the format of 05-50-00, indicating 05:50:00 S1 is used for hour plus 1 operation S2 is used for hour minus 1 operation S3 is used for minute plus 1 operation S4 is used for minute minus 1 operation */ #includesbit KEY1=P3^0; //Define port parameters sbit KEY2=P3^1; sbit KEY3=P3^2; sbit KEY4=P3^3; sbit LED=P1^2; //Define indicator light parameters code unsigned char tab[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f}; //Common cathode digital tube 0-9 unsigned char StrTab[8]; //define buffer unsigned char minute=19,hour=23,second; //define and initialize to 12:30:00 void delay(unsigned int cnt) { while(--cnt); } /******************************************************************/ /* Display processing function */ /******************************************************************/ void Displaypro(void) { StrTab[0]=tab[hour/10]; //Display hour StrTab[1]=tab[hour%10]; StrTab[2]=0x40; //display "-" StrTab[3]=tab[minute/10]; //Display minutes StrTab[4]=tab[minute%10]; StrTab[5]=0x40; //display "-" StrTab[6]=tab[second/10]; //Display seconds StrTab[7]=tab[second%10]; } main() { TMOD |= 0x01; //Timer 0 10ms inM crystal for timing TH0=0xd8; //initial value TL0=0xf0; ET0=1; TR0=1; TMOD |= 0x10; //Timer 1 is used for dynamic scanning TH1=0xF8; //initial value TL1=0xf0; ET1=1; TR1=1; EA = 1; Displaypro(); //Call display processing function while(1) { if(!KEY1) //key 1 debounce and action { delay(10000); if(!KEY1) { hour++; if(hour==24) hour=0; //normal time hour plus 1 Displaypro(); } } if(!KEY2) //Key 2 debounce and action { delay(10000); if(!KEY2) { hour--; if(hour==255) hour=23; //Normal time hour minus 1 Displaypro(); } } if(!KEY3) //key debounce and action { delay(10000); if(!KEY3) { minute++; if(minute==60) minute=0; //minute plus 1 Displaypro(); } } if(!KEY4) //key debounce and action { delay(10000); if(!KEY4) { minute--; if(minute==255) minute=59; //minus 1 Displaypro(); } } } } /******************************************************************/ /* Timer 1 interrupt */ /******************************************************************/ void time1_isr(void) interrupt 3 using 0 //Timer 1 is used for dynamic scanning { static unsigned char num; TH1=0xF8; //Re-enter initial value TL1=0xf0; switch (num) { case 0:P2=0;P0=StrTab[num];break; //Call the buffer values for scanning case 1:P2=1;P0=StrTab[num];break; case 2:P2=2;P0=StrTab[num];break; case 3:P2=3;P0=StrTab[num];break; case 4:P2=4;P0=StrTab[num];break; case 5:P2=5;P0=StrTab[num];break; case 6:P2=6;P0=StrTab[num];break; case 7:P2=7;P0=StrTab[num];break; default:break; } num++; //Scan 8 times, using 8 digital tubes if(num==8) num=0; } /******************************************************************/ /* Timer 0 interrupt */ /******************************************************************/ void tim(void) interrupt 1 using 1 { static unsigned char count; //define internal local variables TH0=0xd8; //Reassign value TL0=0xf0; count++; switch (count) { case 0: case 20: case 40: case 60: case 80:Displaypro();break; //Call display processing at regular intervals case 50:P1=~P1;break; //LED flashes for half a second default:break; } if (count==100) { count=0; second++; //second plus 1 if(second==60) { second=0; minute++; // add 1 to the minute if(minute==60) { minute=0; hour++; // add 1 to the hour if(hour==24) hour=0; } } } }
Previous article:Read the matrix keyboard and use the digital tube to display the corresponding key value
Next article:Advertising running light assembler
Recommended Content
Latest Microcontroller Articles
He Limin Column
Microcontroller and Embedded Systems Bible
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
MoreSelected Circuit Diagrams
MorePopular Articles
- 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
MoreDaily News
- 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
Guess you like
- Prize live broadcast: TI takes you to learn mobile robots. This Friday at 10 am, make an appointment to watch and there will be a surprise~
- Altium Designer AD special-shaped plate layout skills
- Download Win Gift | Artesyn PMBus Interface Non-Isolated Digital DC-DC Converter
- TO92S enclosed 3-pin direct plug-in components have a pin spacing of only 0.45mm, and occasionally a short circuit will occur between the two pins after soldering
- [Erha Image Recognition Artificial Intelligence Vision Sensor] 3: Erha Image Recognition Vision Sensor and STM32 Communication to Realize Color Recognition Experiment
- The actual circuit does not match the simulation circuit. I don't know why. Please tell me. Thank you. The actual op amp is OP297.
- ADI or TI blood glucose meter solution
- How should the size of the drone be determined?
- Medical beauty industry, ultrasonic transducer
- Introduction to the Internet of Things Protocol Coap Protocol