Electronic stopwatch clock digital tube display can set time can be used to stopwatch pause, reset buzzer button tone
The microcontroller source program is as follows:
#include #include "delay.h" #include "intrins.h" unsigned char code LED[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x40}; //Define the common cathode LED 7-segment display code unsigned char dispbit[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f}; //Define the digital tube bit code unsigned char hour=23,min=58,sec=52,week=1; //Define the initial time as 23 hours, 58 minutes and 52 seconds unsigned char tcount; //define 50ms counting variable unsigned char flag=0; sbit KEY1=P1^0; sbit KEY2=P1^1; sbit KEY3=P1^2; sbit key1=P1^3; sbit key2=P3^6; sbit key3=P3^7; sbit LED1=P1^7; sbit LED2=P1^6; sbit LED3=P1^5; sbit LED4=P1^4; sbit BEEP=P3^0; void display(unsigned char,unsigned char,unsigned char,unsigned char); void delay(unsigned int time)//define delay function { unsigned int j = 0; for(;time>0;time--) for(j=0;j<125;j++); } void Delay100us() //@11.0592MHz { unsigned char i, j; _nop_(); _nop_(); i = 2; j = 100; do { while (--j); } while (--i); } void main(void) { TMOD=0x01; //Timer/Counter 0 is set to mode 1 TH0=(65536-50000)/256; //The high eight bits of the initial value of the timing 50ms are sent to TH0 TL0=(65536-50000)%256; //The lower eight bits of the initial value of the timing 50ms are sent to TL0 EA=1; //Open CPU interrupt ET0=1; //Open the interrupt of timer/counter 0 TR0=1; //Start timer 0 while(1) { if(key1==0) { BEEP=0;Delay100us();BEEP=1; hour=0;min=0;sec=0; } if(key2==0) { BEEP=0;Delay100us();BEEP=1; TR0=0; } if(key3==0) { BEEP=0;Delay100us();BEEP=1; TR0=1; } if(KEY1==0) { delay(180); if(KEY1==0) { TR0=0; flag++; if(flag>4) { flag=0; TR0=1; LED1=1;LED2=1;LED3=1;LED4=1; } } } switch(flag) { case 1: LED1=0;LED2=1;LED3=1;LED4=1; if(KEY2==0) { delay(180); if(KEY2==0) { hour++; if(hour>23) hour=0; } } if(KEY3==0) { delay(150); if(KEY3==0) { hour--; if(hour<0) hour=23; } } display(hour,min,sec,week); break; case 2: LED1=1;LED2=0;LED3=1;LED4=1; if(KEY2==0) { delay(180); if(KEY2==0) { min++; if(min>59) min=0; } } if(KEY3==0) { delay(180); if(KEY3==0) { min--; if(min<0) min=59; } } display(hour,min,sec,week); break; case 3: LED1=1;LED2=1;LED3=0;LED4=1; if(KEY2==0) { delay(180); if(KEY2==0) { sec++; if(sec>59) sec=0; } } if(KEY3==0) { delay(180); if(KEY3==0) { sec--; if(sec<0) sec=59; } } display(hour,min,sec,week); break; case 4:LED1=1;LED2=1;LED3=1;LED4=0; if(KEY2==0) { delay(180); if(KEY2==0) { week++; if(week>7) week=1; } } if(KEY3==0) { delay(180); if(KEY3==0) { week--; if(week<1) week=7; } } display(hour,min,sec,week); break; case 5:LED1=1;LED2=1;LED3=1;LED4=1;flag=0;TR0=1; default:break; } display(hour,min,sec,week); } } void display(unsigned char hour,unsigned char min,unsigned char sec,unsigned char week) { P0=LED[hour/10]; //The tens digit of the hour is sent to the digital tube for display P2=0xfe; delay(1); P2=0xff; P0=LED[hour%10]; //The unit digit of the hour is sent to the 2-digit digital tube for display P2=0xfd; delay(1); P2=0xff; P0=LED[min/10]; //The horizontal bar sends the digital tube to 3-digit display P2=0xfb; delay(1); P2=0xff; P0=LED[min%10]; //The tens digit of the minute is sent to the 4-digit digital tube for display P2=0xf7; delay(1); P2=0xff; P0=LED[sec/10]; //The units digit of the minute is sent to the 5-digit digital tube for display P2=0xef; delay(1); P2=0xff; P0=LED[sec%10]; //The horizontal bar sends the digital tube to 6-digit display P2=0xdf; delay(1); P2=0xff; P0=LED[10]; //The tens digit of the second is sent to the 7-digit digital tube for display P2=0xbf; delay(1); P2=0xff; P0=LED[week]; //The units digit of the second is sent to the 8-bit digital tube for display P2=0x7f; delay(1); P2=0xff; } void T0_time() interrupt 1 //Timer interrupt processing function { TH0=(65536-50000)/256; //Resend the high 8 bits of the initial value of 50ms to TH0 TL0=(65536-50000)%256; //Resend the lower eight bits of the initial value of the timing 50ms to TH0 tcount++; //When the 50ms time is up, add 1 if(tcount==20) //Judge whether it is 1s { tcount=0; //After 1s, the variable is cleared to 0 sec++; //The second count variable is increased by 1 if(sec==60) //Judge whether the second has reached 60 { sec=0; //When it reaches 60, the second variable is cleared to 0 ……………………
Previous article:Course Design on Making and Debugging Single Chip Microcomputer Intelligent Stopwatch
Next article:433 remote control decoding source program made by single chip microcomputer, with learning function, can store 8 groups of remote control codes
- 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
- Melexis launches ultra-low power automotive contactless micro-power switch chip
- Molex leverages SAP solutions to drive smart supply chain collaboration
- Pickering Launches New Future-Proof PXIe Single-Slot Controller for High-Performance Test and Measurement Applications
- Apple faces class action lawsuit from 40 million UK iCloud users, faces $27.6 billion in claims
- Apple faces class action lawsuit from 40 million UK iCloud users, faces $27.6 billion in claims
- The US asked TSMC to restrict the export of high-end chips, and the Ministry of Commerce responded
- The US asked TSMC to restrict the export of high-end chips, and the Ministry of Commerce responded
- ASML predicts that its revenue in 2030 will exceed 457 billion yuan! Gross profit margin 56-60%
- Detailed explanation of intelligent car body perception system
- How to solve the problem that the servo drive is not enabled
- What happens when the motor suddenly stops running during operation?
- [National Technology Low Power Series N32L43x Review] 02. Create a template project
- Altium Designer copper patch teardrop setting problem
- [Sipeed LicheeRV 86 Panel Review] 2- Board Resource Introduction and Data Collection
- How much do you know about fast charging? A collection of learning materials on fast charging technology and solutions
- Internal clock and RTOS system
- [Xianji HPM6750 Review 1] Experience with two IDE (SES and RS) development platforms
- BlueNRG-x Documentation - Copy and create your own projects
- Looking for a linear voltage regulator chip
- 【Paper】How to design broadband, efficient GaN RF power amplifiers