include stdio h stdio h include string h

  • Slides: 12
Download presentation

軟體程式 //期末專題: : 簡易小時鐘(能顯示日期時間, 並有調整功能) #include <stdio. h > <stdio. h> #include <string. h

軟體程式 //期末專題: : 簡易小時鐘(能顯示日期時間, 並有調整功能) #include <stdio. h > <stdio. h> #include <string. h > <string. h> #include "ycvb. h"" //定義個功能按鍵 #define CLOCK_ADJUST 10 //10為時間調整 #define CLOCK_UP 11 //11為時間上加 #define CLOCK_DOWN 12 //12為時間下減 #define CLOCK_NEXT 13 //13為轉至下一功能 #define CLOCK_RETURN 14 //14為重新設置 unsigned char kbin=0 xff; //將日期時間資訊以結構儲存, , 以方便傳送 struct s. Day. And. Time{ int Year; char Month; char Day; char Hour; char Minute; char Second; //事先定義好一些常數 char code *month[12]={"Jan ", "Feb ", "Mar ", "Apr ", "May ", "Jun ", "July", "Aug ", "Setp", "Oct ", "Nov ", "Dec "}; char code monthday[12]={31, 28, 31, 30, 31}; char code AM[]="AM", PM[]="PM"; void Init. Day. And. Time(struct s. Day. And. Time* Time); //先給予時間的初始值 void Show. Time(struct s. Day. And. Time* * Time); //更新 更新LCD LCD顯示之時間 s. Day. And. Time // void Adjust. Time(struct s. Day. And. Time* * Time); //調整時間 s. Day. And. Time // unsigned char Input=0 xff; void main() {

軟體程式 struct s. Day. And. Time Now; Init_LCD(); DISP_Str(0 x 80, "Date: - -

軟體程式 struct s. Day. And. Time Now; Init_LCD(); DISP_Str(0 x 80, "Date: - - "); DISP_Str(0 x. C 0, "Time: : : "); Init. Day. And. Time(&Now); Show. Time(&Now); while(1) { Show. Time(&Now); delay 1 ms(2); // 起始LCD顯示器 // 設定時間初值 // 顯示時間 // 每次更新時間時就重新顯示一次 // 用時間延遲來計時 //以下是繁雜的計時日期的程式碼. . . Now. Second++; kbin=kbscan(); if(kbin!=0 xff) { if (kbin ==CLOCK_ADJUST){ // 如果使用者按下調整按鈕, (kbin==CLOCK_ADJUST){ 如果使用者按下調整按鈕, 就進入調整模式 DISP_Str(0 xcf, "S: 01"); Adjust. Time(&Now); DISP_Str(0 xcf, " "); } }

軟體程式 // 您可以為保險起見, 先清空這兩個字串(非必要) memset((void*)the. Day, 0, 16); memset((void*)the. Time, 0, 16); DISP_Int(0 x

軟體程式 // 您可以為保險起見, 先清空這兩個字串(非必要) memset((void*)the. Day, 0, 16); memset((void*)the. Time, 0, 16); DISP_Int(0 x 85, (int)Time->Year); DISP_Str(0 x 8 B , month[Time->Month-1]); DISP_Int 2(0 x 90, (char)Time->Day); DISP_Int 2(0 x. C 6, (char)Time->Hour); DISP_Int 2(0 x. C 9, (char)Time->Minute); DISP_Int 2(0 x. CC, (char)Time->Second); } void Init. Day. And. Time(struct s. Day. And. Time* Time) { Time->Year=2010; Time->Month=10; Time->Day=28; Time->Hour=9; Time->Minute=55; Time->Second=34; } void Adjust. Time(struct s. Day. And. Time* Time) { char Fn. Key=0, Set. Fn=1; //設定時間的 作 while(kbin!=CLOCK_RETURN) { kbin=0 xff; while(kbin==0 xff) kbin=kbscan() ; // 等待輸入 if(kbin==CLOCK_NEXT) // 功能選擇 if(kbin==CLOCK_NEXT) { if(Set. Fn<6) //是不是確定要跳到下一個 if(Set. Fn<6) Set. Fn++; //是不是確定要跳到下一個 else Set. Fn=1; DISP_Int 2(0 x. D 1, Set. Fn); } //上下調整 Month if(Set. Fn==1)

軟體程式 { if (kbin ==CLOCK_UP){ (kbin==CLOCK_UP){ Time->Month==12 ? 1: Time->Month+1; Show. Time(Time); } else

軟體程式 { if (kbin ==CLOCK_UP){ (kbin==CLOCK_UP){ Time->Month==12 ? 1: Time->Month+1; Show. Time(Time); } else if (kbin ==CLOCK_DOWN){ (kbin==CLOCK_DOWN){ Time->Month==1 ? 12: Time->Month-1 ; Show. Time(Time); } } //上下調整 Day if(Set. Fn==2) { if (kbin ==CLOCK_UP){ (kbin==CLOCK_UP){ Time->Day==monthday[Time ->Month-1] ? 1: Time->Day+1; Time->Day==monthday[Time->Month-1] Show. Time(Time); } else if (kbin ==CLOCK_DOWN){ (kbin==CLOCK_DOWN){ Time->Day==1 ? monthday[Time->Month-1]: Time->Day-1; Show. Time(Time); } } //上下調整 Year if(Set. Fn==3) { if (kbin ==CLOCK_UP){ (kbin==CLOCK_UP){ Time->Year++; Show. Time(Time); } else if (kbin ==CLOCK_DOWN){ (kbin==CLOCK_DOWN){ Time->Year--; Show. Time(Time); } } //上下調整 Hour if(Set. Fn==4) { if (kbin ==CLOCK_UP){ (kbin==CLOCK_UP){ Time->Hour=(Time->Hour+1)%24; Show. Time(Time); } else if (kbin ==CLOCK_DOWN){ (kbin==CLOCK_DOWN){ Time->Hour=(Time->Hour+23)%24; Show. Time(Time); } } //上下調整 Mins

軟體程式 if(Set. Fn==5) { if (kbin ==CLOCK_UP){ (kbin==CLOCK_UP){ Time->Minute=(Time->Minute+1)%60; Show. Time(Time); } else if

軟體程式 if(Set. Fn==5) { if (kbin ==CLOCK_UP){ (kbin==CLOCK_UP){ Time->Minute=(Time->Minute+1)%60; Show. Time(Time); } else if (kbin ==CLOCK_DOWN){ (kbin==CLOCK_DOWN){ Time->Minute=(Time->Minute+59)%60; Show. Time(Time); } } //上下調整 sec if(Set. Fn==6) { if (kbin ==CLOCK_UP){ (kbin==CLOCK_UP){ Time->Second=(Time->Second+1)%60; Show. Time(Time); } else if (kbin ==CLOCK_DOWN){ (kbin==CLOCK_DOWN){ Time->Second=(Time->Second+59)%60; Show. Time(Time); } }