|
![](static/image/common/ico_lz.png)
楼主 |
发表于 2021-7-20 11:35:12
|
显示全部楼层
函数的设计和实现
(1)Carry_Time函数:
这个函数用于时间的进位。
源码:
void Carry_Time(){
if(Second > 58){
Second = 0;
Minutes = Minutes + 1;
}
if(Minutes > 58){
Minutes = 0;
Hour = Hour + 1;
}
if(Hour > 22){
Hour = 0;
}
}
(2)Time_display函数
用于显示时间。数码管显示功能直接用 nix_display_time2(Hour,Minutes,Second); 加以完成。
源码:
void Time_display(){
delay(1000);
Second = Second + 1;
Carry_Time();
nix_display_time2(Hour,Minutes,Second);//数码管显示时间
}
(3)SET_time函数
设置时间。在设置时间时,数码管跳动,以提示在设置时间。
源码:
void SET_time(){
uint8 key = 0;
Time[(int)(0)] = Hour;
Time[(int)(1)] = Minutes;
Time[(int)(2)] = Second;
while (!(key == 3)) {
if(!P3_2){
Time[(int)(key)] = Time[(int)(key)] + 1;
if(Time[(int)(2)] > 58){
Time[(int)(2)] = 0;
Time[(int)(1)] = Time[(int)(1)] + 1;
}
if(Time[(int)(1)] > 58){
Time[(int)(1)] = 0;
Time[(int)(0)] = Time[(int)(0)] + 1;
}
if(Time[(int)(0)] > 22){
Time[(int)(0)] = 0;
}
}
if(!P3_3){
key = key + 1;
}
nix_display_time2(Time[(int)(0)],Time[(int)(1)],Time[(int)(2)]);//数码管显示时间
delay(50);
nix_display_clear();//数码管清屏
delay(50);
}
Hour = Time[(int)(0)];
Minutes = Time[(int)(1)];
Second = Time[(int)(2)];
}
(4)SET_Alarm函数
设置闹钟时间。
源码:
void SET_Alarm(){
uint8 key = 0;
uint8 key_2 = 0;
Time[(int)(0)] = 12;
Time[(int)(1)] = 0;
Time[(int)(2)] = 0;
while (!(key == 3)) {
if(!P3_2){
Time[(int)(key)] = Time[(int)(key)] + 1;
if(Time[(int)(2)] > 58){
Time[(int)(2)] = 0;
Time[(int)(1)] = Time[(int)(1)] + 1;
}
if(Time[(int)(1)] > 58){
Time[(int)(1)] = 0;
Time[(int)(0)] = Time[(int)(0)] + 1;
}
if(Time[(int)(0)] > 22){
Time[(int)(0)] = 0;
}
}
if(!P3_3){
key = key + 1;
}
nix_display_time2(Time[(int)(0)],Time[(int)(1)],Time[(int)(2)]);//数码管显示时间
delay(50);
nix_display_clear();//数码管清屏
delay(50);
key_2 = key_2 + 1;
if(key_2 > 9){
Second = Second + 1;
key_2 = 0;
Carry_Time();
}
}
P_Hour = Time[(int)(0)];
P_Minutes = Time[(int)(1)];
P_Second = Time[(int)(2)];
}
(5)Judge_Alarm函数
判断是否到达闹钟时间。
源码:
uint8 Judge_Alarm(){
if (((Hour == P_Hour) && (Minutes == P_Minutes)) && (Second == P_Second)){
return 1;}
return 0;
}
void T_IRQ0(void) interrupt 1 using 1{
nix_scan_callback();//数码管扫描回调函数
}
|
|