The topics to be selected are as follows:
1. Requirements for digital clocks : 24- hour time display, time adjustment at any time, hourly time announcement and alarm function.
The microcontroller source program is as follows:
#include #include //********************************Macro definition******************************** typedef unsigned char uchar; typedef unsigned int uint; //****************************Bit declaration******************************** sbit key1=P1^0; sbit key2=P1^1; sbit key3=P1^2; sbit key4=P1^3; sbit beep=P3^0; //************************The value displayed by the digital tube************************** uchar code table[]= { 0x3f,0x06,0x5b,0x4f,0x66,0x6d, 0x7d,0x07,0x7f,0x6f,0x40,0x00 }; //****************************Function declaration****************************** void jia(); void jian(); //********************Array definition, the array contains 8 values****************** fly table1[8],table2[8],table3[8],table4[8]; //**************************Time display initial value************************** uchar shi=12,fen=0,miao=0; //**************************Define global variables**************************** fly shi1,fen1,miao1,shi2,fen2,miao2,shi3,fen3,miao3; flying shi4,fen4,miao4; uchar flag, flag1, wss, cnt, cnt1, alm1, alm2, alm3; // 1 second equal time, digit flash count calibration, alarm 1, alarm 2, alarm 3 uint flag2; // Buzzer //*********************Delay function, used for dynamic scanning of digital tubes***************** void delay(float i) { fly x,y; for(x=i;x>0;x--) for(y=120;y>0;y--); } //*******************************Initialization function***************************** void init() { TMOD=0x01; //Working mode 1 TH0=0x3c; // Timing time: 50ms (65536-50000)/256 TL0=0x0b0; //(65536-50000)%256 EA=1; //Open the general interrupt ET0=1; //Turn on the timer TR0=1; //Start the timer beep=0; } //********************Display sub-function, used to display time value***************** void display() { flying i,j; if(cnt!=10||wss==0) { table1[0]=miao%10; //Separate the ones and tens of seconds table1[1]=miao/10; } else table1[0]=table1[1]=11; if(cnt!=11||wss==0) { table1[3]=fen%10; //Separate the ones and tens of a minute table1[4]=fen/10; } else table1[3]=table1[4]=11; if(cnt!=12||wss==0) { table1[6]=shi%10; // ones and tens when separated table1[7]=shi/10; } else table1[6]=table1[7]=11; table1[2]=table1[5]=10; j=0xfb; for(i=0;i<=7;i++) //Scan from seconds to hours { P2=j; P0=table[table1[i]]; //Display value delay(10); j=_cror_(j,1); //Circular right shift } } //*******************Display sub-function, used to display timing 1 time***************** void display1() { flying i,j; if(alm1==0) { if(cnt!=1||wss==0) { table2[0]=miao1%10; //The following meanings are the same as above table2[1]=miao1/10; } else table2[0]=table2[1]=11; if(cnt!=2||wss==0) { table2[3]=fen1%10; table2[4]=fen1/10; } else table2[3]=table2[4]=11; if(cnt!=3||wss==0) { table2[6]=shi1%10; table2[7]=shi1/10; } else table2[6]=table2[7]=11; } else table2[0]=table2[1]=table2[3]=table2[4]=table2[6]=table2[7]=10; table2[2]=table2[5]=10; j=0xfb; for(i=0;i<=7;i++) { P2=j; P0=table[table2[i]]; delay(10); j=_cror_(j,1); } } //********************Display sub-function, used to display timing 2 time****************** void display2() { flying i,j; if(alm2==0) { if(cnt!=4||wss==0) { table3[0]=miao2%10; //The following meanings are the same as above table3[1]=miao2/10; } else table3[0]=table3[1]=11; if(cnt!=5||wss==0) { table3[3]=fen2%10; table3[4]=fen2/10; } else table3[3]=table3[4]=11; if(cnt!=6||wss==0) { table3[6]=shi2%10; table3[7]=shi2/10; } else table3[6]=table3[7]=11; } else table3[0]=table3[1]=table3[3]=table3[4]=table3[6]=table3[7]=10; table3[2]=table3[5]=10; j=0xfb; for(i=0;i<=7;i++) { P2=j; P0=table[table3[i]]; delay(10); j=_cror_(j,1); } } //***************Display sub-function, used to display the time value of timing 3****************// void display3() { flying i,j; if(alm3==0) { if(cnt!=7||wss==0) { table4[0]=miao3%10; //Separate the ones and tens of seconds table4[1]=miao3/10; } else table4[0]=table4[1]=11; if(cnt!=8||wss==0) { table4[3]=fen3%10; //Separate the ones and tens of a minute table4[4]=fen3/10; } else table4[3]=table4[4]=11; if(cnt!=9||wss==0) { table4[6]=shi3%10; // ones and tens when separated table4[7]=shi3/10; } else table4[6]=table4[7]=11; } else table4[0]=table4[1]=table4[3]=table4[4]=table4[6]=table4[7]=10; table4[2]=table4[5]=10; j=0xfb; //Scan from seconds to hours for(i=0;i<=7;i++) { P2=j; P0=table[table4[i]]; //Display value delay(10); j=_cror_(j,1); //Circular right shift } } //**************************Time sub-function********************************// void start() { if(flag>=20) //Judge whether it is one second { wss=~wss; flag=0; //When it arrives, the flag is cleared if(cnt1!=0) { miao4++; // seconds plus 1 if(miao4>59) //Judge whether the seconds have reached 60s { miao4=0; //When reached, clear to zero fen4++; // add 1 if(fen4>59) //The following meaning is the same as above { fen4=0; shi4++; if(shi4>23) shi4=0; } } } else { miao++; // seconds plus 1 if(miao>59) //Judge whether the seconds have reached 60s { miao=0; //When reached, clear to zero fen++; // add 1 if(fen>59) //The following meaning is the same as above { fen=0; it++; if(shi>23) it=0; } } } } } //**************************Keyboard scanning subfunction************************// void key_scan() { if(key1==0) { while(!key1) //Prevent display from dropping { if(cnt==1||cnt==2||cnt==3) display1(); if(cnt==4||cnt==5||cnt==6) display2(); if(cnt==7||cnt==8||cnt==9) display3(); if(cnt==0||cnt==10||cnt==11||cnt==12||cnt==13) display(); } cnt++; //Record the number of times key1 is pressed if(cnt==10&&cnt1==0) { miao4=miao; fen4=fen; shi4=shi; cnt1++; } if(cnt==13) { cnt=0; if(cnt1==1) { miao=miao4; fen=fen4; shi=shi4; } cnt1=0; } } if(key2==0) //Judge whether key2 is pressed { while(!key2) //Prevent display from dropping { if(cnt==1||cnt==2||cnt==3) display1(); if(cnt==4||cnt==5||cnt==6) display2(); if(cnt==7||cnt==8||cnt==9) display3(); if(cnt==0||cnt==10||cnt==11||cnt==12||cnt==13)
Previous article:51 MCU uses DAC0832 to program the output of square wave, sawtooth wave, triangle wave, sine wave
Next article:Multifunctional clock thermometer DS1302+LCD1602 based on 51 single chip microcomputer
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Intel promotes AI with multi-dimensional efforts in technology, application, and ecology
- ChinaJoy Qualcomm Snapdragon Theme Pavilion takes you to experience the new changes in digital entertainment in the 5G era
- Infineon's latest generation IGBT technology platform enables precise control of speed and position
- Two test methods for LED lighting life
- Don't Let Lightning Induced Surges Scare You
- Application of brushless motor controller ML4425/4426
- Easy identification of LED power supply quality
- World's first integrated photovoltaic solar system completed in Israel
- Sliding window mean filter for avr microcontroller AD conversion
- What does call mean in the detailed explanation of ABB robot programming instructions?
- How to judge the quality of servo electronic transformer
- What are the advantages and disadvantages of servo electronic transformers
- Causes of unbalanced output voltage of servo electronic transformer
- Does voltage instability affect the servo motor?
- How to solve the problem of too low voltage when the motor starts
- What is the output voltage of the servo drive?
- What are the symptoms of servo drive output phase loss?
- New breakthrough! Ultra-fast memory accelerates Intel Xeon 6-core processors
- New breakthrough! Ultra-fast memory accelerates Intel Xeon 6-core processors
- Consolidating vRAN sites onto a single server helps operators reduce total cost of ownership
- csi_pwm_init function
- Noise suppression model in MP3 players
- MSP432P401R manually realizes the breathing light
- 【NXP Rapid IoT Review】 + WEB IDE usage experience and improvement suggestions
- Can you please help me analyze the principle of this circuit? Thank you.
- TI Solar Cell Charging Maximum Power Point Tracking Algorithm Reference Design
- New step-up DC/DC controller from Linear Technology for 42V automotive systems
- Sunplus Technology promotes 16-bit industrial control microcontroller
- The weekly review information is here~~
- What is the difference between adding a conjugate inductor and a capacitor behind the rectifier bridge?