Joke Collection Website - Blessing messages - Please help me to write a 5 1 single chip clock program, which displays 0220 when connected. The program also has an alarm function.

Please help me to write a 5 1 single chip clock program, which displays 0220 when connected. The program also has an alarm function.

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

# include & ltabsacc.h & gt// includes the header file.

# include & ltreg52.h & gt// includes the header file.

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

#define uchar unsigned char // data type definition

/* * * * * * * * * * * * * * * * * * Define variables and initialize * * * * * * * * * * * *

uchar n = 3 1; //Define the day of the month variable and initialize it.

uchar ms = 0; //Define millisecond variables and initialize them.

uchar h 1=2,m 1=2,s 1 = 0; //Define the timing hour, minute and second variables and initialize them.

uchar h2=0,m2= 1,S2 = 1; //Define the timing hour, minute and second variables and initialize them.

Uchar year =0, month =0, day = 0; //Define the year, month and day variables and initialize them.

uchar wday = 6; //Define the day of the week variable and initialize it.

uchar * h = & amph 1 * m = & amp; m 1,* s = & amps 1; //Define video bit variables and initialize them.

uchar * p; //Define the adjustment pointer

uchar k 1=0,k2=0,k3=0,k4=0,K5 = 0; //Define control variables and initialize them.

Uchar counter = 0; //Define the bell beat variable and initialize it.

Uchar count = 0; //define the bell note variable and initialize it.

sbit sound=p 1^0; //Defines the ringtone output bit.

uchar a[8]={ 1,2,3,4,5,6,7 }; //Define the display output bit array and initialize it.

Uchar code tt[ 12]={

0x3f,0x06,0x5b,0x4f,0x66,0x6d,

0x7d、0x07、0x7f、0x6f、0x40、0x00

}; //Digital tube display code

Uchar code array [] = {

0x 18,0x30,0x 1C,0x 10,0x20,0x40,0x 1C,0x 10,

0x 18,0x 10,0x20,0x 10,0x 1C,0x 10,0x 18,0x40,

0x 1C,0x20,0x20,0x20,0x 1C,0x20,0x 18,0x20,

0x20,0x80,0xFF,0x00,0x20,0x30,0x 1C,0x 10,

0x 18,0x20,0x 15,0x20,0x 1C,0x20,0x20,0x20,

0x26,0x40,0x20,0x20,0x2B,0x20,0x26,0x20,

0x20,0x20,0x30,0x80,0xFF,0x00,0x20,0x20,

0x 1C,0x 10,0x 18,0x 10,0x20,0x20,0x26,0x20,

0x2B,0x20,0x30,0x20,0x2B,0x40,0x20,0x20,

0x 1C,0x 10,0x 18,0x 10,0x20,0x20,0x26,0x20,

0x2B,0x20,0x30,0x20,0x2B,0x40,0x20,0x30,

0x 1C,0x 10,0x 18,0x20,0x 15,0x20,0x 1C,0x20,

0x20,0x20,0x26,0x40,0x20,0x20,0x2B,0x20,

0x26,0x20,0x20,0x20,0x30,0x80,0x20,0x30,

0x 1C,0x 10,0x20,0x 10,0x 1C,0x 10,0x20,0x20,

0x26,0x20,0x2B,0x20,0x30,0x20,0x2B,0x40,

0x20,0x 15,0x 1F,0x05,0x20,0x 10,0x 1C,0x 10,

0x20,0x20,0x26,0x20,0x2B,0x20,0x30,0x20,

0x2B,0x40,0x20,0x30,0x 1C,0x 10,0x 18,0x20,

0x 15,0x20,0x 1C,0x20,0x20,0x20,0x26,0x40,

0x20,0x20,0x2B,0x20,0x26,0x20,0x20,0x20,

0x30,0x30,0x20,0x30,0x 1C,0x 10,0x 18,0x40,

0x 1C,0x20,0x20,0x20,0x26,0x40,0x 13,0x60,

0x 18,0x20,0x 15,0x40,0x 13,0x40,0x 18,0x80,

0x00,0x00

};

//array[i]=0x00 indicates the end of the song.

//array[i]=0xff stands for rest.

/*******************************************************************

* Function name: leap ()

* Function: Calculate the number of days in February.

* Entry parameter: year

* Export parameters: None

*******************************************************************/

Ucharleap (ucharyyear)//Determines whether it is a leap year, and returns the number of days in February.

{//Returns 29 in leap years and 28 in normal years.

Year+= 2000;

If (year %4==0)

{if(year% 100==0)

{if(year%400==0)

Return to 29;

Otherwise return to 28;

}

Otherwise, return to 29;

}

Otherwise return to 28;

}

/*******************************************************************

* Function name: mon ()

* Function: Calculates and returns the number of days in each month.

* Entry parameter: month

* Export parameters: None

*******************************************************************/

Uchar mon(uchar month) // Calculates and returns the number of days in each month.

{

Switch (month)

{

Case 1:

Case 3:

Case 5:

Case 7:

Case 8:

Case 10:

Case 12: Return 31; Break; //February every month 1, 3, 5, 7, 8, 10, 1 day.

Case 4:

Case 6:

Case 9:

Case 1 1: return 30; Break; //April, June, September, 165438+ October, 30 days per month.

Case 2: Return to leap (year); Break; //Returns the number of days in February.

Default: break

}

}

/*******************************************************************

* Function name: Music ()

* Function: Music beat control

* Inlet parameters: None

* Export parameters: None

*******************************************************************/

Void music(void) // ringtone music

{

counter++; //Beat count

If (counter & gt= array[count+ 1]// Beat number judgment

{

Count+= 2; //note transformation

Counter = 0; //Clear the number of beats.

if(count & gt; = 192) // Judge whether to finish singing a song.

count = 0; //Returns the first note.

}

}

/*******************************************************************

* function name: timer 1 ()

* Function: Music frequency setting

* Inlet parameters: None

* Export parameters: None

*******************************************************************/

Voidtimer 1 (void) interrupt 1 use1/tone setting.

{

Sound = ~ sound; //ringtone output

TH0 =(0x ffff-30 * array[count])& gt; & gt8; //Audio Settings

TL0 =(0x ffff-30 * array[count])& amp; 0xff

}

/*******************************************************************

* Function name: Timer3 ()

* function: interrupt timing

* Inlet parameters: None

* Export parameters: None

*******************************************************************/

Voidtimer 3 (invalid) interrupt 3 uses 3// timer interrupt.

{

th 1 = 0xd 8; //The initial value of the counter is overloaded.

TL 1 = 0x ef; //Define the delay size of unit beat as 10 ms.

if(K5)music(); //Call the alarm clock music lns

Otherwise TR0 = 0;; //Turn off the bell after reaching the set alarm time.

If(++ms== 100) // time one second.

{ ms = 0;

If(++s 1==60) // time is one minute.

{ s 1 = 0;

If(++m 1==60) // time is one hour.

{ m 1 = 0;

If(++h 1==24) // time of day.

{ h 1 = 0;

N=mon (month); //Take the number of days per month

if(++day & gt; N) // The time is one month

{ day = 1;

If (++month & gt 12) // is timed for one year.

{ month = 1;

year++;

}

}

if((+wday & gt; 6) // week count

wday = 0;

}

}

K5-; //alarm time length countdown

if(h 1 = = H2 & amp; & ampM 1==m2) // Judge whether it is time.

{

TR0 = 1; //ring the bell to interrupt lns

K5 = s2// Set the alarm time length.

}

}

}

}

/*******************************************************************

* Function name: d3 ()

* Function: Digital tube output display

* Inlet parameters: None

* Export parameters: None

*******************************************************************/

Void 3(void)// Display output

{

uchar sel=0x80,I; //Define sel as a bit strobe variable and initialize it.

If(k2) // Judge whether it is in the state of time adjustment.

{

if(k2 = = 4)a[0]= a[ 1]= a[4]= a[6]= a[7]= 10; //Day of the week display settings

if(k 1 & amp; & amp(k3-= = 0))k3 = 255; //Set this bit to adjust the initial value of flicker.

}

for(I = 0; I < = 8; I++) // Cyclically display eight digital tubes.

{

P2 = 0x ff; //Clear the screen

P0 = TT[a[I]]; //Output the displayed value

if(k 1 & amp; & (k3> 200))//Determine whether it flashes.

if(k 1 = = 1 & amp; & amp(I = = 6 | | I = = 7))P2 = 0x ff; //Time flashing

else if(k 1 = = 2 & amp; & amp(I = = 3 | | I = = 4))P2 = 0x ff; //Split flicker

else if(k 1 = = 3 & amp; & amp(I = = 0 | | I = = 1))P2 = 0x ff; //The second bit flashes.

else P2 = ~ sel; //Non-blinking state

else P2 = ~ sel; //Non-blinking state

sel = sel & gt& gt 1; //Display displacement bit

}

}

/*******************************************************************

* Function name: d2 ()

* Function and energy: cyclic calling

* Inlet parameters: None

* Export parameters: None

*******************************************************************/

Empty d2 (empty)

{

while( 1)

{

a[0]= * s % 10; //Assign a value to the display array

a[ 1]= * s/ 10;

a[2]= 10;

a[3]= * m % 10;

a[4]= * m/ 10;

a[5]= 10;

a[6]= * h % 10;

a[7]= * h/ 10;

D3(); //Call the display output function

}

}

/*******************************************************************

* function name: d 1 ()

* Function: Interrupt setting

* Inlet parameters: None

* Export parameters: None

*******************************************************************/

Void d d1(invalid)

{

TMOD = 0x 1 1;

th 1 = 0x ff; TH0 = 0xff

TL 1 = 0x ff; TL0 = 0xff

IE = 0x8f

tr 1 = 1;

IT0 = 1; it 1 = 1;

IP = 0x02

}

/*******************************************************************

* Function name: main ()

* Function: program entry, calling function subfunction.

* Inlet parameters: None

* Export parameters: None

*******************************************************************/

Invalid master (invalid)

{

d 1(); //Call the interrupt bit setting function

D2();

}

/*******************************************************************

* Function name: d5 ()

* Function: Switch the display menu.

* Inlet parameters: None

* Export parameters: None

*******************************************************************/

Void 5(void)// Displays the menu adjustment function.

{

Switch (k2)

{

Case1:{h =&; h 1; m = & ampm 1; s = & amps 1; } broken; //Menu 1: Display the clock time.

Case 2: {h = & h2; m = & ampm2; s = & ampS2; } broken; //Menu 2: Display Timed Time

Case 3: {h = & year; M =& month; S = & days; } broken; //Menu 3: Display calendar year, month and day.

Case 4: {h =&; Wdaym = & ampwdays = & wday} broken; //Menu 4: Show Day of the Week 0-6

Default value: {k2 = 0;; h = & amph 1; m = & ampm 1; s = & amps 1; } broken; //Reset the display

}

}

/*******************************************************************

* Function name: d7 ()

* Work and energy: adjust the limit to prevent the numerical adjustment from exceeding the range.

* Inlet parameters: None

* Export parameters: None

*******************************************************************/

Void d7(void) // Adjust the constraint function.

{

If(k2== 1||k2==2) // Timing and timing restrictions

if(k 1 = = 1 & amp; & amp* p & gt= 24)* p = 0; //hour limit

else if(* p & gt; = 60)* p = 0; //Minute and second limits

If(k2==3) // Calendar limit

if(k 1 = = 1 & amp; & amp* p & gt= 100)* p = 0; //Annual limit

else if(k 1 = = 2 & amp; & amp* p & gt 12)* p = 1; //Monthly limit

else if(k 1 = = 3 & amp; & amp* p & gtn)* p = 1; //Daily limit

If (k2==4)

if(k 1 = = 2 & amp; & amp* p & gt6)* p = 0; //week limit

}

/*******************************************************************

* Function name: Timer0 ()

* Function: menu switching and bit addend adjustment.

* Inlet parameters: None

* Export parameters: None

*******************************************************************/

/* * External interrupt 1 Adjustment function * */

Voidtime r0 (void) interrupt 0 is adjusted with 0// external interrupt 0.

{

If(k 1) // Determines whether it is bit adjustment or menu adjustment.

{

(* p)++; //bit addend adjustment

D7(); //Call the adjustment limit function

}

other

{

k2++; //menu appendix adjustment

D5(); //Call the adjustment menu

}

}

/*******************************************************************

* Function name: Timer2 ()

* Function: Adjust the position selection and turn off the ringtone.

* Inlet parameters: None

* Export parameters: None

*******************************************************************/

Invalid timer 2 (invalid) Interrupt 2 is adjusted with 2// external interrupt 1

{

TR0 = 0; K5 = 0; //Turn off the bell manually

Is if(k2) // off in the adjustment state?

{

if(k2 = = 4){ k 1++; }//Adjust position selection during the period.

if(++k 1 = = 1)p = h; //Select the time position

else if(k 1 = = 2)p = m; //Select a point.

else if(k 1 = = 3)p = s; //Select the second.

else k 1 = 0; //Reset

}

}

I'm under division