TA的每日心情 | 开心 2019-6-24 16:41 |
---|
签到天数: 709 天 连续签到: 1 天 [LV.9]以坛为家II
|
【玩转系列】序列之8:大时钟驾到
转载请注明出处和作者:请尊重版权所有!否则后果自负,谢谢!!
本节主要是从下面3个方面进行讲解:
1.工具准备工作
2.时钟显示程序
3.时钟显示效果
一、工具准备工作
1.电脑一台;
2.LCD12864液晶一块;
3.USB数据线一根;
4.单片机开发板一块;
5.杜邦线若干根;
6.排线一组;
7.已经装安装MDK和keil软件。
二、时钟显示程序
1.时间显示UI界面函数。
const sWidget MuTime[] ={ 0,16,16,112,Def,Def,ShowTime,CTRLTime,ShowTime,TimeYDraw,10,(void*)&InY, 16, 40,16,64,Def,Def,ShowTime,CTRLTime,0 ,TimeHDraw,0,(void*)&InH, 32, 40,16,64,Def,Def,ShowTime,CTRLTime,0 ,DrawOpen,0,(void*)&InO, 32,112,16,16,Def,Def,ShowTime,CTRLTime,0 ,DrawOpenW,0,"", 48, 40,16,64,Def,Def,ShowTime,CTRLTime,0 ,DrawClose,0,(void*)&InC, 48,112,16,16,Def,Def,ShowTime,CTRLTime,0 ,DrawCloseW,0,"",};
2.时间调整调用函数。
N8 isSameTime(N8 H,N8 M,N8 S){ if(gST.Hour != H) return 0; if(gST.Min != M) return 0; if(gST.Sec != S) return 0; return 1;}void AutoOnOff(void){ if(gLED.AuOn.IsCheck){if(isSameTime(gLED.AuOn.H,gLED.AuOn.M,gLED.AuOn.S))gLED.Run =1;} if(gLED.AuOf.IsCheck){if(isSameTime(gLED.AuOf.H,gLED.AuOf.M,gLED.AuOf.S))gLED.Run =0;}}void CTRLTime(void){ switch(gUI.Key) { case KeyUp:case KeyDown: break; case KeyFun:EEP_Save(); UIGoTo(&WinM); break; case KeyEsc: break; case KeyOK: switch(gUI.iMu) { case 3:gLED.AuOn.IsCheck=(gLED.AuOn.IsCheck)?(0)1);break; case 5:gLED.AuOf.IsCheck=(gLED.AuOf.IsCheck)?(0)1);break; default:EditInit((sEditInPut*)gUI.pMu->Data); } break; case KeyRun: LedRunSw();break; }}void DrawOpen(void){ if(!UI_MuEdit){ sprintf(str,"%.2d:%.2d:%.2d",gLED.AuOn.H,gLED.AuOn.M,gLED.AuOn.S); } ASCII8x16(gUI.pMu->A.Top,gUI.pMu->A.Left,(UI_MuEdit)?(gUI.Es)str));}void DrawClose(void){ if(!UI_MuEdit){ sprintf(str,"%.2d:%.2d:%.2d",gLED.AuOf.H,gLED.AuOf.M,gLED.AuOf.S); } ASCII8x16(gUI.pMu->A.Top,gUI.pMu->A.Left,(UI_MuEdit)?(gUI.Es)str));}void DrawOpenW(void){ str[0]='a';str[1]=(gLED.AuOn.IsCheck)?('1')'2'); str[2]=str[3]=0; GBstr(gUI.pMu->A.Top,gUI.pMu->A.Left,Mode_CP,str);}void DrawCloseW(void){ str[0]='a';str[1]=(gLED.AuOf.IsCheck)?('1')'2');str[2]=str[3]=0; GBstr(gUI.pMu->A.Top,gUI.pMu->A.Left,Mode_CP,str);}void TimeHDraw(void){ if(!UI_MuEdit){ sprintf(str,"%.2d:%.2d:%.2d",gST.Hour,gST.Min,gST.Sec); } ASCII8x16(gUI.pMu->A.Top,gUI.pMu->A.Left,(UI_MuEdit)?(gUI.Es)str));}void TimeYDraw(void){ char weak[1]; if(!UI_MuEdit){ sprintf(str,"%.4d %.2d %.2d",gST.Year,gST.Month,gST.Day); } ASCII8x16(gUI.pMu->A.Top,gUI.pMu->A.Left,(UI_MuEdit)?(gUI.Es)str)); GBstr(gUI.pMu->A.Top ,gUI.pMu->A.Left+32,Mode_Ad,"年 月 日"); weak[0]=18+gST.Week; GBi(16,16,Mode_CP,1,weak);}void CallStrTimeY(void){ gST.Year = (gUI.Es[0]-'0')*1000+(gUI.Es[1]-'0')*100+(gUI.Es[2]-'0')*10+gUI.Es[3]-'0'; gST.Month = (gUI.Es[6]-'0')*10+gUI.Es[7]-'0'; gST.Day = (gUI.Es[10]-'0')*10+gUI.Es[11]-'0'; RTC_Set(&gST);}void CallByTimeY(void){ int pro,max,k; switch(gUI.Ei) { case 7: pro='1';max='2';k=2;break; case 11: pro='3';max='1';k=1;break; default: gUI.Es[gUI.Ei]='*';return; } if(gUI.Es[gUI.Ei-1]>=pro) gUI.Es[gUI.Ei]=(gUI.Key > k)?(max)gUI.Key+'0'); else gUI.Es[gUI.Ei]= gUI.Key+ '0';}void CallStrTimeH(void){ gST.Hour = (gUI.Es[0]-'0')*10+gUI.Es[1]-'0'; gST.Min = (gUI.Es[3]-'0')*10+gUI.Es[4]-'0'; gST.Sec = (gUI.Es[6]-'0')*10+gUI.Es[7]-'0'; RTC_Set(&gST);}void CallStrAon(void){ gLED.AuOn.H= (gUI.Es[0]-'0')*10+gUI.Es[1]-'0'; gLED.AuOn.M= (gUI.Es[3]-'0')*10+gUI.Es[4]-'0'; gLED.AuOn.S= (gUI.Es[6]-'0')*10+gUI.Es[7]-'0';}void CallStrAof(void){ gLED.AuOf.H= (gUI.Es[0]-'0')*10+gUI.Es[1]-'0'; gLED.AuOf.M= (gUI.Es[3]-'0')*10+gUI.Es[4]-'0'; gLED.AuOf.S= (gUI.Es[6]-'0')*10+gUI.Es[7]-'0';}void CallByTimeH(void){ int i=1,pro='2',max='3'; if(gUI.Es[i-1]>=pro) gUI.Es=(gUI.Key > 3)?(max)gUI.Key+'0'); else gUI.Es= gUI.Key+ '0';}void ShowTime(void){ RTC_Get(&gST); RunMuDraw(0,0xff);}void DrawTime(void){ LCM_CLR(); GBstr(32,0,Mode_CP,"启动"); GBstr(48,0,Mode_CP,"关闭"); ShowTime();}
3.时间显示函数。
const sEditInPut InY={"x09x09x09x09 x01r x03r",CallByTimeY,CallStrTimeY};const sEditInPut InH={"x02r:x05x09:x05x09",CallByTimeH,CallStrTimeH};const sEditInPut InO={"x02r:x05x09:x05x09",CallByTimeH,CallStrAon};const sEditInPut InC={"x02r:x05x09:x05x09",CallByTimeH,CallStrAof};const sWin WinTime = {MuNum(MuTime),0,1,1,&DrawTime,(void*)0,MuTime};
三、时钟显示效果
file:///G:Tempksohtmlwps5D33.tmp.jpg
file:///G:Tempksohtmlwps5D34.tmp.jpg
file:///G:Tempksohtmlwps5D45.tmp.jpg |
|