实验原理:
STM32的实时时钟(RTC)是一个独立的定时器,有一组连续计数的
计数器,通过软件来对其进行相关的配置,可以提供时钟功能,通过修改计
数器的的值,可以调整时钟。最终通过emWin在显示屏上进行显示。
示例截图:
源代码下载链接:
链接:http://pan.baidu.com/s/1sloF1fv 密码:gtwo
GMT43购买链接:
核心代码:
static void frame_process(void)
{
RTC_TimeTypeDef rtc_time;
RTC_DateTypeDef rtc_date;
typedef struct {
int x;
int y;
}POINT_T;
float temp;
static POINT_T ph0,ph0_bak,ph1,ph1_bak,pm0,pm0_bak, pm1,pm1_bak, ps0,ps0_bak, ps1,ps1_bak;
int second_bak = ;
int minute_bak = ;
int hour_bak = ;
int year_bak = ;
int month_bak = ;
int date_bak = ;
int week_bak = ;
char buffer[]; GUI_CURSOR_Show();
WM_SetCreateFlags(WM_CF_MEMDEV);
GUI_CreateDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), _cbwindow, WM_HBKWIN, , );
WM_SetCallback(WM_HBKWIN, NULL);
add_widget();
WM_SetCallback(WM_HBKWIN, &_cbDialog);
while(){
RTC_GetTime(RTC_Format_BIN,&rtc_time);//»ñÈ¡RTCʱ¼ä
RTC_GetDate(RTC_Format_BIN,&rtc_date);//»ñÈ¡RTCÈÕÆÚ
if(second_bak != rtc_time.RTC_Seconds){
sprintf(buffer,"%02d",rtc_time.RTC_Seconds);
TEXT_SetText(h_text_4, buffer);
second_bak = rtc_time.RTC_Seconds;
}
if(minute_bak != rtc_time.RTC_Minutes){
sprintf(buffer,"%02d",rtc_time.RTC_Minutes);
TEXT_SetText(h_text_3, buffer);
minute_bak = rtc_time.RTC_Minutes;
}
if(hour_bak != rtc_time.RTC_Hours){
sprintf(buffer,"%02d",rtc_time.RTC_Hours);
TEXT_SetText(h_text_2, buffer);
hour_bak = rtc_time.RTC_Hours;
}
if(year_bak != rtc_time.RTC_Seconds){
sprintf(buffer,"20%02d",rtc_date.RTC_Year);
TEXT_SetText(h_text_5, buffer);
year_bak = rtc_date.RTC_Year;
}
if(month_bak != rtc_date.RTC_Month){
sprintf(buffer,"%02d",rtc_date.RTC_Month);
TEXT_SetText(h_text_6, buffer);
month_bak = rtc_date.RTC_Month;
}
if(date_bak != rtc_date.RTC_Date){
sprintf(buffer,"%02d",rtc_date.RTC_Date);
TEXT_SetText(h_text_7, buffer);
date_bak = rtc_date.RTC_Date;
}
if(week_bak != rtc_date.RTC_WeekDay){
switch(rtc_date.RTC_WeekDay){
case :
TEXT_SetText(h_text_8, "ÐÇ ÆÚ Ò»");
break;
case :
TEXT_SetText(h_text_8, "ÐÇ ÆÚ ¶þ");
break;
case :
TEXT_SetText(h_text_8, "ÐÇ ÆÚ Èý");
break;
case :
TEXT_SetText(h_text_8, "ÐÇ ÆÚ ËÄ");
break;
case :
TEXT_SetText(h_text_8, "ÐÇ ÆÚ Îå");
break;
case :
TEXT_SetText(h_text_8, "ÐÇ ÆÚ Áù");
break;
case :
TEXT_SetText(h_text_8, "ÐÇ ÆÚ ÈÕ");
break;
default:
break;
}
week_bak = rtc_date.RTC_WeekDay;
}
//¸üÐÂÖ¸ÕëλÖÃ
temp = ((rtc_time.RTC_Hours + rtc_time.RTC_Minutes / .) / .)* * PI;
ph0.x = * sin(temp);
ph0.y = * cos(temp);
ph1.x = * sin(temp);
ph1.y = * cos(temp);
temp = (rtc_time.RTC_Minutes / .) * * PI;
pm0.x = * sin(temp);
pm0.y = * cos(temp);
pm1.x = * sin(temp);
pm1.y = * cos(temp);
temp = (rtc_time.RTC_Seconds / .) * * PI;
ps0.x = * sin(temp);
ps0.y = * cos(temp);
ps1.x = * sin(temp);
ps1.y = * cos(temp); //ÃëÕëÏÔʾ
if(ps0.x != ps0_bak.x || ps0.y != ps0_bak.y){
GUI_SetPenSize();
GUI_SetColor(GUI_BLACK);
GUI_DrawLine(tx(ps0_bak.x,), ty(ps0_bak.y,), tx(ps1_bak.x,), ty(ps1_bak.y,));
GUI_SetColor(GUI_WHITE);
GUI_SetFont(GUI_FONT_20B_ASCII);
GUI_DispStringAt("",,);
GUI_DispStringAt("",,);
GUI_DispStringAt("",,);
GUI_DispStringAt("",,);
GUI_SetPenSize();
GUI_SetColor(GUI_WHITE);
GUI_DrawLine(tx(pm0.x,), ty(pm0.y,), tx(pm1.x,), ty(pm1.y,));
GUI_SetPenSize();
GUI_SetColor(GUI_WHITE);
GUI_DrawLine(tx(ph0.x,), ty(ph0.y,), tx(ph1.x,), ty(ph1.y,));
GUI_SetPenSize();
GUI_SetColor(GUI_RED);
GUI_DrawLine(tx(ps0.x,), ty(ps0.y,), tx(ps1.x,), ty(ps1.y,));
}
//·ÖÕëÏÔʾ
if(pm0.x != pm0_bak.x || pm0.y != pm0_bak.y){
GUI_SetPenSize();
GUI_SetColor(GUI_BLACK);
GUI_DrawLine(tx(pm0_bak.x,), ty(pm0_bak.y,), tx(pm1_bak.x,), ty(pm1_bak.y,));
GUI_SetPenSize();
GUI_SetColor(GUI_WHITE);
GUI_DrawLine(tx(pm0.x,), ty(pm0.y,), tx(pm1.x,), ty(pm1.y,));
}
//ʱÕëÏÔʾ
if(ph0.x != ph0_bak.x || ph0.y != ph0_bak.y){
GUI_SetPenSize();
GUI_SetColor(GUI_BLACK);
GUI_DrawLine(tx(ph0_bak.x,), ty(ph0_bak.y,), tx(ph1_bak.x,), ty(ph1_bak.y,));
GUI_SetPenSize();
GUI_SetColor(GUI_WHITE);
GUI_DrawLine(tx(ph0.x,), ty(ph0.y,), tx(ph1.x,), ty(ph1.y,));
}
GUI_SetColor(GUI_WHITE);
GUI_DrawCircle(tx(,), ty(,), );
GUI_DrawCircle(tx(,), ty(,), );
ps0_bak.x = ps0.x;
ps0_bak.y = ps0.y;
ps1_bak.x = ps1.x;
ps1_bak.y = ps1.y;
pm0_bak.x = pm0.x;
pm0_bak.y = pm0.y;
pm1_bak.x = pm1.x;
pm1_bak.y = pm1.y;
ph0_bak.x = ph0.x;
ph0_bak.y = ph0.y;
ph1_bak.x = ph1.x;
ph1_bak.y = ph1.y;
GUI_Exec();
}
}