【GMT43智能液晶模块】例程九:RTC实验——时钟显示

实验原理:

  STM32的实时时钟(RTC)是一个独立的定时器,有一组连续计数的

计数器,通过软件来对其进行相关的配置,可以提供时钟功能,通过修改计

数器的的值,可以调整时钟。最终通过emWin在显示屏上进行显示。  

示例截图:

 【GMT43智能液晶模块】例程九:RTC实验——时钟显示_第1张图片

源代码下载链接:

链接:http://pan.baidu.com/s/1sloF1fv 密码:gtwo

GMT43购买链接:

【GMT43智能液晶模块】例程九:RTC实验——时钟显示_第2张图片

【GMT43智能液晶模块】例程九:RTC实验——时钟显示_第3张图片

 

核心代码:

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 = 0;
    int minute_bak = 0;
    int hour_bak = 0;
    int year_bak = 0;
    int month_bak = 0;
    int date_bak = 0;
    int week_bak = 0;
    char buffer[10];
    
    GUI_CURSOR_Show();
    WM_SetCreateFlags(WM_CF_MEMDEV);
  GUI_CreateDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), _cbwindow, WM_HBKWIN, 0, 0);
    WM_SetCallback(WM_HBKWIN, NULL);
    add_widget();
    WM_SetCallback(WM_HBKWIN, &_cbDialog);
    while(1){
        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 1:
                    TEXT_SetText(h_text_8, "ÐÇ ÆÚ Ò»");    
                    break;
                case 2:
                    TEXT_SetText(h_text_8, "ÐÇ ÆÚ ¶þ");    
                    break; 
                case 3:
                    TEXT_SetText(h_text_8, "ÐÇ ÆÚ Èý");    
                    break;
                case 4:
                    TEXT_SetText(h_text_8, "ÐÇ ÆÚ ËÄ");    
                    break;
                case 5:
                    TEXT_SetText(h_text_8, "ÐÇ ÆÚ Îå");    
                    break;
                case 6:
                    TEXT_SetText(h_text_8, "ÐÇ ÆÚ Áù");    
                    break;
                case 7:
                    TEXT_SetText(h_text_8, "ÐÇ ÆÚ ÈÕ");
                    break;
                default:
                    break;            
            }
            week_bak = rtc_date.RTC_WeekDay;
        }        
        //¸üÐÂÖ¸ÕëλÖÃ
        temp = ((rtc_time.RTC_Hours + rtc_time.RTC_Minutes / 60.) / 12.)* 2 * PI;
        ph0.x = 26 * sin(temp);
        ph0.y = 26 * cos(temp);
        ph1.x = 5 * sin(temp);
        ph1.y = 5 * cos(temp);
        temp = (rtc_time.RTC_Minutes / 60.) * 2 * PI;
        pm0.x = 36 * sin(temp);
        pm0.y = 36 * cos(temp);
        pm1.x = 5 * sin(temp);
        pm1.y = 5 * cos(temp);    
        temp = (rtc_time.RTC_Seconds / 60.) * 2 * PI;
        ps0.x = 50 * sin(temp);
        ps0.y = 50 * cos(temp);
        ps1.x = 5 * sin(temp);
        ps1.y = 5 * cos(temp);    
            
        //ÃëÕëÏÔʾ
        if(ps0.x != ps0_bak.x || ps0.y != ps0_bak.y){
            GUI_SetPenSize(1);
            GUI_SetColor(GUI_BLACK);
            GUI_DrawLine(tx(ps0_bak.x,60), ty(ps0_bak.y,110), tx(ps1_bak.x,60), ty(ps1_bak.y,110));        
            GUI_SetColor(GUI_WHITE);
            GUI_SetFont(GUI_FONT_20B_ASCII);
            GUI_DispStringAt("12",50,60);
            GUI_DispStringAt("3",99,102);
            GUI_DispStringAt("9",11,102);
            GUI_DispStringAt("6",56,142);            
            GUI_SetPenSize(3);
            GUI_SetColor(GUI_WHITE);
            GUI_DrawLine(tx(pm0.x,60), ty(pm0.y,110), tx(pm1.x,60), ty(pm1.y,110));        
            GUI_SetPenSize(3);
            GUI_SetColor(GUI_WHITE);
            GUI_DrawLine(tx(ph0.x,60), ty(ph0.y,110), tx(ph1.x,60), ty(ph1.y,110));    
            GUI_SetPenSize(1);
            GUI_SetColor(GUI_RED);
            GUI_DrawLine(tx(ps0.x,60), ty(ps0.y,110), tx(ps1.x,60), ty(ps1.y,110));    
        }
        //·ÖÕëÏÔʾ
        if(pm0.x != pm0_bak.x || pm0.y != pm0_bak.y){
            GUI_SetPenSize(3);
            GUI_SetColor(GUI_BLACK);
            GUI_DrawLine(tx(pm0_bak.x,60), ty(pm0_bak.y,110), tx(pm1_bak.x,60), ty(pm1_bak.y,110));        
            GUI_SetPenSize(3);
            GUI_SetColor(GUI_WHITE);
            GUI_DrawLine(tx(pm0.x,60), ty(pm0.y,110), tx(pm1.x,60), ty(pm1.y,110));                
        }
        //ʱÕëÏÔʾ
        if(ph0.x != ph0_bak.x || ph0.y != ph0_bak.y){
            GUI_SetPenSize(3);
            GUI_SetColor(GUI_BLACK);
            GUI_DrawLine(tx(ph0_bak.x,60), ty(ph0_bak.y,110), tx(ph1_bak.x,60), ty(ph1_bak.y,110));    
            GUI_SetPenSize(3);
            GUI_SetColor(GUI_WHITE);
            GUI_DrawLine(tx(ph0.x,60), ty(ph0.y,110), tx(ph1.x,60), ty(ph1.y,110));                
        }
        GUI_SetColor(GUI_WHITE);
        GUI_DrawCircle(tx(0,60), ty(0,110), 3);
        GUI_DrawCircle(tx(0,60), ty(0,110), 4);        
        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();
    }
}

 

你可能感兴趣的:(【GMT43智能液晶模块】例程九:RTC实验——时钟显示)