H # include "is the Key."
# include "led. H"
Uchar timeSetBuff [8]={LED_MODE_COUNT '0', '0', '0', '0', LED_MODE_COUNT, '0', '0'};//the clock data buffer
Uchar alarmSetBuff [8]={LED_MODE_ALARM '0', '0', '0', '0', LED_MODE_ALARM, '0', '0'};//alarm clock time data buffer
Uchar timeDisMod=0 x24;//00100100
Uchar secondTemp, minuteTemp hourTemp;
Uchar secondAlarm, minuteAlarm hourAlarm;
Uchar timer0Temp;
Uchar alarmKeyCount;//the clock counting start-stop button
Bit alarm_is_ok;//alarm clock start-stop state
Bit time_is_ok;//time whether to
Bit interface_mod;//display mode, 0 interface mainly time, 1 for setting interface
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* function name: timer 0
* will work: initialization timer 0
No
* entrance parameters:No
* export parameters:* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
Void initTimer0 (void)//timing 10 ms
{
TMOD |=0 x01;//GATE=0, TR=1; C/T=1, counter, zero, the timer; 01 hexadecimal
XDC TH0=0;
TL0=0 x00;
TR0=1;//timer0 control bits, to 1 start timer0
ET0=1;//timer0 interrupted enabled
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* function name: clock is
* can work: to compare the time clock and alarm clock buffer, comparison and points only
No
* entrance parameters:No
* export parameters:* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
Void timeCompare (void)
{
If ((minuteTemp==minuteAlarm) & amp; & (hourTemp==hourAlarm))
{
Time_is_ok=1;
Alarm_is_ok=0;
Interface_mod=1;
}
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* the name of the function: the main function
And implement each function called * can work:
No
* entrance parameters:No
* export parameters:* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
Void main ()
{
Uchar keyRead;
Init_led ();
Init_key ();
InitTimer0 ();
Timer0Temp=0 x00;
SecondTemp=0 x00;
MinuteTemp=0 x00;
HourTemp=0 x00;
SecondAlarm=0 x00;
MinuteAlarm=0 x00;
HourAlarm=0 x00;
AlarmKeyCount=0 x02;
Alarm_is_ok=0;//the default state to stop
Time_is_ok=0;//the default time before the
Interface_mod=0;
Sei ();
While (1)
{
If (interface_mod==1)
LedSweepDisplay (alarmSetBuff timeDisMod);
The else
LedSweepDisplay (timeSetBuff timeDisMod);
If (alarm_is_ok==1)
TimeCompare ();
KeyRead=get_key_value ();
If (keyRead==KEY_ALARM)
{
If (alarm_is_ok==1 | | time_is_ok==1)
{
Alarm_is_ok=0;
Time_is_ok=0;
Interface_mod=0;
AlarmKeyCount=0 x00;
}
The else
{
If (alarmKeyCount & lt; 0 x02)
AlarmKeyCount++;
The else
AlarmKeyCount=0 x00;
If (alarmKeyCount==0 x01)
Interface_mod=1;
If (alarmKeyCount==0 x02)
{
Alarm_is_ok=1;
Interface_mod=0;
}
}
}
If (keyRead==KEY_SECOND)
{if (interface_mod==1)
{
If (secondAlarm & lt; 59)
SecondAlarm++;
The else
SecondAlarm=0 x00;
AlarmSetBuff [S_L]=10 + '0' secondAlarm %;
AlarmSetBuff [S_H]=secondAlarm/10 + '0';
}
The else
{
If (secondTemp & lt; 59)
SecondTemp +=1;
The else
SecondTemp=0 x00;
TimeSetBuff [S_L]=10 + '0' secondTemp %;
TimeSetBuff [S_H]=secondTemp/10 + '0';
}
}
If (keyRead==KEY_MINUTE)
{if (interface_mod==1)
{
If (minuteAlarm & lt; 59)
MinuteAlarm++;
The else
MinuteAlarm=0 x00;
AlarmSetBuff/M_L=10 + '0' minuteAlarm %;
AlarmSetBuff [M_H]=minuteAlarm/10 + '0';
}
The else
{
If (minuteTemp & lt; 59)
MinuteTemp +=1;
The else
MinuteTemp=0 x00;
TimeSetBuff/M_L=10 + '0' minuteTemp %;
TimeSetBuff [M_H]=minuteTemp/10 + '0';
}
}
If (keyRead==KEY_HOUR)
{
If (interface_mod==1)
{
If (hourAlarm & lt; 23)
HourAlarm++;
The else
HourAlarm=0 x00;
AlarmSetBuff/H_L=10 + '0' hourAlarm %;
AlarmSetBuff [H_H]=hourAlarm/10 + '0';
}
The else
{
If (hourTemp & lt; 23)
HourTemp +=1;
The else
HourTemp=0 x00;
TimeSetBuff/H_L=10 + '0' hourTemp %;
TimeSetBuff [H_H]=hourTemp/10 + '0';
}
}
}
}
/* and */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* function name: 0 timer interrupt function
* can work: timer 0 overflow interrupt the entrance, timing 10 ms
No
* entrance parameters:No
* export parameters:* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
Void timer0_overflow (void) interrupt 1
{
XDC TH0=0;
TL0=0 x00;
If (time_is_ok==1)//alarm
WARN_TRUMPET=~ WARN_TRUMPET;
If (timer0Temp & lt; 99)//whether the 1 s to
Timer0Temp + +;
The else//into the interrupt 100
{
Timer0Temp=0 x00;
If (secondTemp & lt; 59)//whether the 1 min to
{
SecondTemp++;
}
The else
{
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull