Digital clock design based on 51 microcontroller – digital tube display

Digital clock design based on 51 microcontroller

(Simulation + Program + Schematic + Design Report)

Function introduction

Specific functions:

1. Automatic timing, showing 24-hour time, and a 6-digit LED display showing hours, minutes, and seconds.

2. Automatic timing, showing 24-hour time, and a 6-digit LED display showing hours, minutes, and seconds.

3. Equipped with calibration function, the current time can be set directly by pressing the buttons.

4. It has the function of adjusting the alarm clock and reporting the hourly time.

?

/******************51 Microcontroller Digital Clock Design******************

*********************original design******************/
#include <REGX52.H>

#define uint unsigned int
#define uchar unsigned char
/******************Definition of digital tube****************/
#define SMG_XS P0 //Nigital tube data display
#define SMG_KZ P2 //Nigital tube control display
#define Speak P3_7 //Define buzzer interface
#define LED1 P3_4 //Define LED1 interface (travel time indicator light)
#define LED2 P3_5 //Define LED2 interface (alarm indicator light is on)
#define LED3 P3_6 //Define LED3 interface (hourly time indicator light)
 
#define Key1 P1_0 //Time adjustment allowed key
#define Key2 P1_1 //Hours and minutes plus button
#define Key3 P1_2 //Hours and minutes subtraction button
#define Key4 P3_1 //Alarm time adjustment allows button
#define Key5 P3_2 //On/off alarm button
#define Key6 P3_3 //On/off hourly time chime button

uchar code Data[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,0xBF};//No decimal point
//Define array digital tube 0 1 2 3 4 5 6 7 8 9 -
uchar code Data1[]={0x40,0x79,0x24,0x30,0x19,0x12,0x02,0x78,0x00,0x10,0x3F};//With decimal point
//Define array digital tube 0 1 2 3 4 5 6 7 8 9 -


uchar hour=12,min=0,sec=0; //The default time when the system is powered on is 12.00.00
uchar hour1=6,min1=0,sec1=0; //The default alarm when the system is powered on is 06.00.00
char num=0; //time base num
uint t=3; //Nigital tube dynamic scanning delay time base source data 3
uchar flag=0; //Display flag bits (0: normal travel time 1: adjust clock 2: adjust minutes)
uint i=0;j=0; //Loop variables i,j
bit nao_z=0; //Alarm clock flag bit (0: turn off the alarm clock 1: turn on the alarm clock)
uchar flag_nao_z=0; //Alarm clock display mode (0: Display normal travel time 1: Display alarm time 2: Adjust alarm clock 3: Adjust alarm minutes)
bit bao_shi=0; //The hourly chime flag bit (0: The hourly chime is not allowed, 1: The hourly chime is allowed)
\t\t\t
void delay(uint time) //Scan delay function
{
uint x,y;
for(x=time;x>0;x--)
for(y=110;y>0;y--);
}

void delay_fmq(uint time) //Delay function (buzzer)
{
uint x,y;
for(x=time;x>0;x--)
for(y=5;y>0;y--);
}

void fmq() //Buzzer function (key prompt)
{
for(i=0;i<100;i + + )
{
Speak=0;
delay_fmq(10);
}
Speak=1;
}
void Time0_init() //Timer 0 initialization function
{
TMOD=0x01; //Timer 0 is mode 1
TL0=(65536-50000)%6;
TH0=(65536-50000)/256; //12M crystal oscillator timing time 50ms
ET0=1; //Enable timer 0 interrupt
EA=1; //Enable total interrupt
TR0=0; //Do not start timer 0 first
}
void Time0() interrupt 1 //Timer 0 interrupt service function
{
TH0=(65536-50000)/256; //Reload the initial value and set an interrupt of 50ms
TL0=(65536-50000)%6;
num + + ; //Add 1 to the time base
while(num==20) //1 second is up
{
num=0; //clear num to 0
sec + + ; //Add 1 to seconds
\t
if(flag_nao_z!=0) //Alarm clock display mode is not equal to 0 (normal travel time is not displayed, that is, alarm clock time is displayed)
{
LED1=~LED1; //The indicator light flashes at a frequency of 2Hz (when adjusting the alarm time, it prompts that the time is running)
}
else //Otherwise the alarm clock display mode is equal to 0 (displays normal travel time)
{
LED1=1; //During normal running time, the indicator light does not light up
}
\t\t
if(nao_z==1) //When the alarm clock flag is 1: turn on the alarm clock
{
LED2=0; //Alarm indicator light is on
if(hour==hour1 & amp;min==min1) //At that time, the minutes are the same as the alarm clock hours and minutes
{
Speak=~Speak; //Buzzer interface inversion (2Hz frequency sound)
}
else //Otherwise the hours and minutes are different from the alarm clock hours and minutes
{
Speak=1; //Turn off the buzzer
}
}
else //Otherwise turn off the alarm clock
{
LED2=1; //Alarm indicator light does not light up
}
}
while(sec==60) //1 minute is up
{
sec=0; //Clear to 0 in seconds
min + + ; //Add 1 to the score
}
while(min==60) //1 hour is up
{
min=0; //Distinguish 0
hour + + ; //Add 1 to hour
}
while(hour==24) //24 hours to come
{
hour=0; //Time clear to 0
}
}

void disp(hour,min,sec) //Normal display mode of digital tube
{
SMG_XS=Data[hour/10]; //Ten digits of hour
SMG_KZ=0xdf; //Control the first digital tube to light up
delay(t); //Delay (blanking)
SMG_KZ=0xff;
SMG_XS=Data1[hour]; //hour digit
SMG_KZ=0xef; //Control the second digital tube to light up
delay(t); //Delay (blanking)
SMG_KZ=0xff;
SMG_XS=Data[min/10]; //Divided into tens
SMG_KZ=0xf7; //Control the third digital tube to light up
delay(t); //Delay (blanking)
SMG_KZ=0xff;
SMG_XS=Data1[min]; //Divided into units
SMG_KZ=0xfb; //Control the 4th digital tube to light up
delay(t); //Delay (blanking)
SMG_KZ=0xff;
SMG_XS=Data[sec/10]; //Ten seconds digit
SMG_KZ=0xfd; //Control the fifth digital tube to light up
delay(t); //Delay (blanking)
SMG_KZ=0xff;
SMG_XS=Data[sec]; //Second digit
SMG_KZ=0xfe; //Control the 6th digital tube to light up
delay(t); //Delay (blanking)
SMG_KZ=0xff;
}

void disp1(hour,min,sec) //Nigital tube mode 1: hour adjustment mode (the clock flashes on the digital tube)
{
j + + ; //j plus 1
while(j==40) {j=0;} //When j is 40, j is cleared to 0
if(j<20) //when j is less than 20, hours, minutes and seconds will be displayed
{
SMG_XS=Data[hour/10]; //Ten digits of hour
SMG_KZ=0xdf; //Control the first digital tube to light up
delay(t); //Delay (blanking)
SMG_KZ=0xff;
SMG_XS=Data1[hour]; //hour digit
SMG_KZ=0xef; //Control the second digital tube to light up
delay(t); //Delay (blanking)
SMG_KZ=0xff;
SMG_XS=Data[min/10]; //Divided into tens
SMG_KZ=0xf7; //Control the third digital tube to light up
delay(t); //Delay (blanking)
SMG_KZ=0xff;
SMG_XS=Data1[min]; //Divided into units
SMG_KZ=0xfb; //Control the 4th digital tube to light up
delay(t); //Delay (blanking)
SMG_KZ=0xff;
SMG_XS=Data[sec/10]; //Ten seconds digit
SMG_KZ=0xfd; //Control the fifth digital tube to light up
delay(t); //Delay (blanking)
SMG_KZ=0xff;
SMG_XS=Data[sec]; //Second digit
SMG_KZ=0xfe; //Control the 6th digital tube to light up
delay(t); //Delay (blanking)
SMG_KZ=0xff;
}
else //Otherwise, it will not be displayed when 20<j<40; minutes and seconds will be displayed.
{
SMG_XS=Data[hour/10]; //Ten digits of hour
SMG_KZ=0xff; //Control the first digital tube not to light up
delay(t); //Delay (blanking)
SMG_KZ=0xff;
SMG_XS=Data1[hour]; //hour digit
SMG_KZ=0xff; //Control the second digital tube not to light up
delay(t); //Delay (blanking)
SMG_KZ=0xff;
SMG_XS=Data[min/10]; //Divided into tens
SMG_KZ=0xf7; //Control the third digital tube to light up
delay(t); //Delay (blanking)
SMG_KZ=0xff;
SMG_XS=Data1[min]; //Divided into units
SMG_KZ=0xfb; //Control the 4th digital tube to light up
delay(t); //Delay (blanking)
SMG_KZ=0xff;
SMG_XS=Data[sec/10]; //Ten seconds digit
SMG_KZ=0xfd; //Control the fifth digital tube to light up
delay(t); //Delay (blanking)
SMG_KZ=0xff;
SMG_XS=Data[sec]; //Second digit
SMG_KZ=0xfe; //Control the 6th digital tube to light up
delay(t); //Delay (blanking)
SMG_KZ=0xff;
}
}

void disp2(hour,min,sec) //Nigital tube mode 2: Adjust minute mode (minutes flash on the digital tube)
{
j + + ; //j plus 1
while(j==40) {j=0;} //When j is 40, j is cleared to 0
if(j<20) //when j is less than 20, hours, minutes and seconds are all displayed
{
SMG_XS=Data[hour/10]; //Ten digits of hour
SMG_KZ=0xdf; //Control the first digital tube to light up
delay(t); //Delay (blanking)
SMG_KZ=0xff;
SMG_XS=Data1[hour]; //hour digit
SMG_KZ=0xef; //Control the second digital tube to light up
delay(t); //Delay (blanking)
SMG_KZ=0xff;
SMG_XS=Data[min/10]; //Divided into tens
SMG_KZ=0xf7; //Control the third digital tube to light up
delay(t); //Delay (blanking)
SMG_KZ=0xff;
SMG_XS=Data1[min]; //Divided into units
SMG_KZ=0xfb; //Control the 4th digital tube to light up
delay(t); //Delay (blanking)
SMG_KZ=0xff;
SMG_XS=Data[sec/10]; //Ten seconds digit
SMG_KZ=0xfd; //Control the fifth digital tube to light up
delay(t); //Delay (blanking)
SMG_KZ=0xff;
SMG_XS=Data[sec]; //Second digit
SMG_KZ=0xfe; //Control the 6th digital tube to light up
delay(t); //Delay (blanking)
SMG_KZ=0xff;
}
else //Otherwise, it will be displayed when 20<j<40, minutes will not be displayed, and seconds will be displayed.
{
SMG_XS=Data[hour/10]; //Ten digits of hour
SMG_KZ=0xdf; //Control the first digital tube to light up
delay(t); //Delay (blanking)
SMG_KZ=0xff;
SMG_XS=Data1[hour]; //hour digit
SMG_KZ=0xef; //Control the second digital tube to light up
delay(t); //Delay (blanking)
SMG_KZ=0xff;
SMG_XS=Data[min/10]; //Divided into tens
SMG_KZ=0xff; //Control the third digital tube not to light up
delay(t); //Delay (blanking)
SMG_KZ=0xff;
SMG_XS=Data1[min]; //Divided into units
SMG_KZ=0xff; //Control the 4th digital tube not to light up
delay(t); //Delay (blanking)
SMG_KZ=0xff;
SMG_XS=Data[sec/10]; //Ten seconds digit
SMG_KZ=0xfd; //Control the fifth digital tube to light up
delay(t); //Delay (blanking)
SMG_KZ=0xff;
SMG_XS=Data[sec]; //Second digit
SMG_KZ=0xfe; //Control the 6th digital tube to light up
delay(t); //Delay (blanking)
SMG_KZ=0xff;
}
}

void disp3(hour1,min1,sec1) //Nigital tube mode 3 (display alarm time)
{
SMG_XS=Data[hour1/10]; //Alarm clock hour ten digits
SMG_KZ=0xdf; //Control the first digital tube to light up
delay(t); //Delay (blanking)
SMG_KZ=0xff;
SMG_XS=Data1[hour1]; //alarm clock hour one digit
SMG_KZ=0xef; //Control the second digital tube to light up
delay(t); //Delay (blanking)
SMG_KZ=0xff;
SMG_XS=Data[min1/10]; //alarm clock divided into ten digits
SMG_KZ=0xf7; //Control the third digital tube to light up
delay(t); //Delay (blanking)
SMG_KZ=0xff;
SMG_XS=Data1[min1]; //Alarm clock minutes
SMG_KZ=0xfb; //Control the 4th digital tube to light up
delay(t); //Delay (blanking)
SMG_KZ=0xff;
SMG_XS=Data[sec1/10]; //Alarm clock seconds ten digits
SMG_KZ=0xfd; //Control the fifth digital tube to light up
delay(t); //Delay (blanking)
SMG_KZ=0xff;
SMG_XS=Data[sec1]; //alarm clock second digit
SMG_KZ=0xfe; //Control the 6th digital tube to light up
delay(t); //Delay (blanking)
SMG_KZ=0xff;
}

void disp4(hour1,min1,sec1) //Nigital tube mode 4: Adjust the alarm clock (the alarm clock flashes on the digital tube)
{
j + + ; //j plus 1
while(j==40) {j=0;} //When j is 40, j is cleared to 0
if(j<20) //j is less than 20, alarm clock displays hours, minutes and seconds
{
SMG_XS=Data[hour1/10]; //Alarm clock hour ten digits
SMG_KZ=0xdf; //Control the first digital tube to light up
delay(t); //Delay (blanking)
SMG_KZ=0xff;
SMG_XS=Data1[hour1]; //alarm clock hour one digit
SMG_KZ=0xef; //Control the second digital tube to light up
delay(t); //Delay (blanking)
SMG_KZ=0xff;
SMG_XS=Data[min1/10]; //Alarm clock divided into ten digits
SMG_KZ=0xf7; //Control the third digital tube to light up
delay(t); //Delay (blanking)
SMG_KZ=0xff;
SMG_XS=Data1[min1]; //Alarm clock minutes
SMG_KZ=0xfb; //Control the 4th digital tube to light up
delay(t); //Delay (blanking)
SMG_KZ=0xff;
SMG_XS=Data[sec1/10]; //Alarm clock seconds ten digits
SMG_KZ=0xfd; //Control the fifth digital tube to light up
delay(t); //Delay (blanking)
SMG_KZ=0xff;
SMG_XS=Data[sec1]; //alarm clock second digit
SMG_KZ=0xfe; //Control the 6th digital tube to light up
delay(t); //Delay (blanking)
SMG_KZ=0xff;
}
else //otherwise 20<j<40 alarm clock does not display hours, displays minutes, displays seconds
{
SMG_XS=Data[hour1/10]; //Alarm clock hour ten digits
SMG_KZ=0xff; //Control the first digital tube not to light up
delay(t); //Delay (blanking)
SMG_KZ=0xff;
SMG_XS=Data1[hour1]; //alarm clock hour one digit
SMG_KZ=0xff; //Control the second digital tube not to light up
delay(t); //Delay (blanking)
SMG_KZ=0xff;
SMG_XS=Data[min1/10]; //Alarm clock divided into ten digits
SMG_KZ=0xf7; //Control the third digital tube to light up
delay(t); //Delay (blanking)
SMG_KZ=0xff;
SMG_XS=Data1[min1]; //Alarm clock minutes
SMG_KZ=0xfb; //Control the 4th digital tube to light up
delay(t); //Delay (blanking)
SMG_KZ=0xff;
SMG_XS=Data[sec1/10]; //Alarm clock seconds ten digits
SMG_KZ=0xfd; //Control the fifth digital tube to light up
delay(t); //Delay (blanking)
SMG_KZ=0xff;
SMG_XS=Data[sec1]; //alarm clock second digit
SMG_KZ=0xfe; //Control the 6th digital tube to light up
delay(t); //Delay (blanking)
SMG_KZ=0xff;
}
}

void disp5(hour1,min1,sec1) //Nigital tube mode 5: Adjust the alarm minute (the alarm minute flashes on the digital tube)
{
j + + ; //j plus 1
while(j==40) {j=0;} //When j is 40, j is cleared to 0
if(j<20) //j is less than 20, alarm clock displays hours, minutes and seconds
{
SMG_XS=Data[hour1/10]; //Alarm clock hour ten digits
SMG_KZ=0xdf; //Control the first digital tube to light up
delay(t); //Delay (blanking)
SMG_KZ=0xff;
SMG_XS=Data1[hour1]; //alarm clock hour one digit
SMG_KZ=0xef; //Control the second digital tube to light up
delay(t); //Delay (blanking)
SMG_KZ=0xff;
SMG_XS=Data[min1/10]; //alarm clock divided into ten digits
SMG_KZ=0xf7; //Control the third digital tube to light up
delay(t); //Delay (blanking)
SMG_KZ=0xff;
SMG_XS=Data1[min1]; //Alarm clock minutes
SMG_KZ=0xfb; //Control the 4th digital tube to light up
delay(t); //Delay (blanking)
SMG_KZ=0xff;
SMG_XS=Data[sec1/10]; //Alarm clock seconds ten digits
SMG_KZ=0xfd; //Control the fifth digital tube to light up
delay(t); //Delay (blanking)
SMG_KZ=0xff;
SMG_XS=Data[sec1]; //alarm clock second digit
SMG_KZ=0xfe; //Control the 6th digital tube to light up
delay(t); //Delay (blanking)
SMG_KZ=0xff;
}
else //otherwise 20<j<40 alarm clock displays hours, does not display minutes, displays seconds
{
SMG_XS=Data[hour1/10]; //Alarm clock hour ten digits
SMG_KZ=0xdf; //Control the first digital tube to light up
delay(t); //Delay (blanking)
SMG_KZ=0xff;
SMG_XS=Data1[hour1]; //alarm clock hour one digit
SMG_KZ=0xef; //Control the second digital tube to light up
delay(t); //Delay (blanking)
SMG_KZ=0xff;
SMG_XS=Data[min1/10]; //Alarm clock divided into ten digits
SMG_KZ=0xff; //Control the third digital tube not to light up
delay(t); //Delay (blanking)
SMG_KZ=0xff;
SMG_XS=Data1[min1]; //Alarm clock minutes
SMG_KZ=0xff; //Control the 4th digital tube not to light up
delay(t); //Delay (blanking)
SMG_KZ=0xff;
SMG_XS=Data[sec1/10]; //Alarm clock seconds ten digits
SMG_KZ=0xfd; //Control the fifth digital tube to light up
delay(t); //Delay (blanking)
SMG_KZ=0xff;
SMG_XS=Data[sec1]; //alarm clock second digit
SMG_KZ=0xfe; //Control the 6th digital tube to light up
delay(t); //Delay (blanking)
SMG_KZ=0xff;
}
}

void key_cl() //Key processing (adjustment time)
{
if(Key1==0) //When time adjustment is allowed and the key is pressed
{
delay(5); //delay debounce
if(Key1==0) // Then determine whether the time adjustment is allowed and the key is pressed.
{
TR0=0; //Close timer 0
num=0; //Time base cleared to 0
sec=0; //clear seconds
TL0=(65536-50000)%6;
TH0=(65536-50000)/256; //12M crystal oscillator timing time 50ms
flag + + ; //Increase the display flag by 1 (0: normal travel time 1: adjust the clock 2: adjust the minutes)
if(flag==3) //When flag is 3
{
flag=0; //clear flag to 0
}
}
SMG_KZ=0xff; //Turn off the digital tube display
fmq(); //Button tone
while(Key1==0); //Wait for the key to be released
}
if(flag==1) //When flag is 1 (adjust clock)
{
if(Key2==0) //When the minute is added, the key is pressed
{
delay(5); //delay debounce
if(Key2==0) //Determine whether the hour and minute keys are pressed or not
{
hour + + ; //Add 1 to hour
while(hour==24) {hour=0;} //When hour is 24, hour is cleared to 0
}
SMG_KZ=0xff; //Turn off the digital tube display
fmq(); //Button tone
while(Key2==0); //Wait for the key to be released
}
if(Key3==0) //When the key is pressed, the points are subtracted
{
delay(5); //delay debounce
if(Key3==0) //Determine whether the hour and minute subtraction keys are pressed.
{
hour--; //decrease hour by 1
while(hour==-1) {hour=23;} //When hour is -1, hour is set to 23
\t\t\t\t
}
SMG_KZ=0xff; //Turn off the digital tube display
fmq(); //Button tone
while(Key3==0); //Wait for the key to be released
}
}
if(flag==2) //When flag is 2 (adjust minutes)
{
if(Key2==0) //When the minute is added, the key is pressed
{
delay(5); //delay debounce
if(Key2==0) //Determine whether the hour and minute keys are pressed or not
{
min + + ; //Add 1 to the score
while(min==60) {min=0;} //When min is 60, min is cleared to 0
\t\t
}
SMG_KZ=0xff; //Turn off the digital tube display
fmq(); //Button tone
while(Key2==0); //Wait for the key to be released
}
if(Key3==0) //When the key is pressed, the points are subtracted
{
delay(5); //delay debounce
if(Key3==0) //Determine whether the hour and minute subtraction keys are pressed.
{
min--; //minus 1
while(min==-1) {min=59;} //When min is -1, min is set to 59
\t\t
}
SMG_KZ=0xff; //Turn off the digital tube display
fmq(); //Button tone
while(Key3==0); //Wait for the key to be released
}
}
}

void key_cl1() //Key processing 1 (alarm clock setting)
{
if(Key4==0) //When the alarm time adjustment is allowed, the key is pressed
{
delay(5); //delay debounce
if(Key4==0) //Then determine whether the alarm time adjustment is allowed and the button is pressed.
{
flag_nao_z + + ; //Add 1 to the alarm display mode (0: Display normal travel time 1: Display alarm time 2: Adjust alarm clock 3: Adjust alarm minutes)
if(flag_nao_z==4) {flag_nao_z=0;} //When flag_nao_z is 4, flag_nao_z is cleared to 0
}
SMG_KZ=0xff; //Turn off the digital tube display
fmq(); //Button tone
while(Key4==0); //Wait for the key to be released
}
if(flag_nao_z==2) //When entering to adjust the alarm clock
{
if(Key2==0) //When the hour and minute are added, the key is pressed
{
delay(5); //delay debounce
if(Key2==0) //Determine whether the hour and minute keys are pressed or not
{
hour1 + + ; //Alarm clock plus 1
while(hour1==24) {hour1=0;} //When the alarm clock is 24, the alarm clock is cleared to 0
\t\t
}
SMG_KZ=0xff; //Turn off the digital tube display
fmq(); //Button tone
while(Key2==0); //Wait for the key to be released
}
if(Key3==0) //When, the minute is subtracted when the key is pressed
{
delay(5); //delay debounce
if(Key3==0) //Determine whether the hour and minute subtraction keys are pressed.
{
hour1--; //Alarm clock minus 1
while(hour1==-1) {hour1=23;} //When the alarm clock is -1, the alarm clock is set to 23
}
SMG_KZ=0xff; //Turn off the digital tube display
fmq(); //Button tone
while(Key3==0); //Wait for the key to be released
}
}
if(flag_nao_z==3) //When entering to adjust the alarm clock minutes
{
if(Key2==0) //When the hour and minute are added, the key is pressed
{
delay(5); //delay debounce
if(Key2==0) //Determine whether the hour and minute keys are pressed or not
{
min1 + + ; //Add 1 to the alarm minute
while(min1==60) {min1=0;} //When the alarm minute is 60, the alarm minute is cleared to 0
\t\t
}
SMG_KZ=0xff; //Turn off the digital tube display
fmq(); //Button tone
while(Key2==0); //Wait for the key to be released
}
if(Key3==0) //When, the minute is subtracted when the key is pressed
{
delay(5); //delay debounce
if(Key3==0) //Determine whether the hour and minute subtraction keys are pressed.
{
min1--; //Alarm minute minus 1
while(min1==-1) {min1=59;} //When the alarm minute is -1, the alarm minute is set to 59
\t\t
}
SMG_KZ=0xff; //Turn off the digital tube display
fmq(); //Button tone
while(Key3==0); //Wait for the key to be released
}
}
}

void key_cl2() //Button processing 2 (alarm clock, hourly time button processing)
{
if(Key5==0) //When the alarm button is pressed
{
delay(5); //delay debounce
if(Key5==0) //then determine whether the alarm button is pressed
{
nao_z=~nao_z; //Invert the alarm clock flag (0: turn off the alarm clock 1: turn on the alarm clock)
}
SMG_KZ=0xff; //Turn off the digital tube display
fmq(); //Button tone
while(Key5==0); //Wait for the key to be released
}
if(Key6==0) //When the hour is announced, the button is pressed
{
delay(5); //delay debounce
if(Key6==0) //Then determine whether the hourly time chime button is pressed
{
bao_shi=~bao_shi; //The hourly chime flag is inverted (0: The hourly chime is not allowed, 1: The hourly chime is allowed)
}
SMG_KZ=0xff; //Turn off the digital tube display
fmq(); //Button tone
if(bao_shi==1) //When the hourly chime flag is 1: allow hourly chime
{
LED3=0; //The hourly time indicator light is on
}
else //Otherwise the hourly chime flag is 0: no hourly chime is allowed
{
LED3=1; //The hourly time indicator light does not light up
}
while(Key6==0); //Wait for the key to be released
}
}

void SMG_disp() //Data display (hours, minutes and seconds)
{
if(flag==0) //The display flag is 0 (0: normal travel time 1: adjust the clock 2: adjust the minutes)
{
disp(hour,min,sec); //Normal display mode of digital tube
}
if(flag==1) //The display flag is 1 (0: normal travel time 1: adjust the clock 2: adjust the minutes)
{
disp1(hour,min,sec);//Nigital tube mode 1: hour adjustment mode (the clock flashes on the digital tube)
}
if(flag==2) //The display flag is 2 (0: normal travel time 1: adjust the clock 2: adjust the minutes)
{
disp2(hour,min,sec);//Nigital tube mode 2: Adjust minute mode (minutes flash on the digital tube)
}
}

void SMG_disp1() //Data display 1 (alarm clock hours minutes seconds)
{
if(flag_nao_z==1) //Alarm clock display mode is 1 (0: Display normal travel time 1: Display alarm time 2: Adjust alarm clock 3: Adjust alarm minutes)
{
disp3(hour1,min1,sec1); //Nigital tube mode 3: display alarm time
}
if(flag_nao_z==2) //Alarm clock display mode is 2 (0: Display normal travel time 1: Display alarm time 2: Adjust alarm clock 3: Adjust alarm minutes)
{
disp4(hour1,min1,sec1); //Nigital tube mode 4: Adjust the alarm clock (the alarm clock flashes on the digital tube)
}
if(flag_nao_z==3) //Alarm clock display mode is 3 (0: Display normal travel time 1: Display alarm time 2: Adjust alarm clock 3: Adjust alarm minutes)
{
disp5(hour1,min1,sec1); //Nigital tube mode 5: Adjust the alarm minute (the alarm minute flashes on the digital tube)
}
}

void bao_shi_cl() //Hour time reporting processing (0: Do not allow hourly time reporting 1: Allow hourly time reporting)
{
if(bao_shi==1) //Turn on hourly time chime
{
if(TR0==1) //When TR0 is 1 (indicating normal running time)
{
if(min==0 & amp;sec==0) //divided into 0 seconds as 0
{
SMG_KZ=0xff; //Turn off the digital tube display
fmq(); //prompt sound
while(sec==0); //When seconds is 0, continue waiting
}
}
}
}

Hardware design

Use components:

Microcontroller: STC89C52;

(Note: The microcontroller is universal, whether it is 51 or 52, whether it is stc or at, the pin functions are the same. The program is also the same.)

USB connector (female); self-locking switch;

Electrolytic capacitor 10u; resistor 10K;

Ceramic capacitor 30P; crystal oscillator 12M;

Resistor 4.7K; Resistor 470 (SMD);

Transistor 8550; 4-bit common anode digital tube;

2-digit common anode digital tube; LED (red-haired);

Active buzzer; DIP40;

Button; 9*15CM universal board;

USB male to male cable; pin header 2P;

Wires: several;

Flowchart:

?

Design information

01 Simulation diagram

This design uses two versions of proteus7.8 and proteus8.7, and is backward compatible, no need to worry! Specifically as shown in the picture!

02 Schematic Diagram

The schematic diagram of this system is designed using Altium Designer19, as shown in the figure!

?

03 Program

This design is programmed using two versions of the software keil4 and keil5, so there is no need to worry! Specifically as shown in the picture!

04 Design Report

Fourteen thousand word design report, details are as follows!

?

05 Design information

All materials include simulation source files, programs (including comments), AD schematics, reference papers, flow charts, etc. The specific content is as follows, the most complete on the entire network! !

?

The following is the open source 51 microcontroller design information

?Everyone learns and progresses together:

Link: Baidu Netdisk Please enter the extraction code

Extraction code: eyrx

Like and share to learn and progress together! Grow together.