饭盒派上最显眼的外设就是 1.77寸TFT显示屏,其接口电路如图1所示。若将TFT屏的显示功能与RTC计时功能结合起来就可实现一个电子时钟。
图1 LCD屏接口
为此,需在RTC例程的基础上添加TFT显示程序,在完成功能的添加后,即可使TFT屏显示出颜色来,见图2所示。
图2 显示测试
随后,将主程序修改为如下的内容:
int32_t main(void)
{
RTC_InitTypeDef RTC_InitStruct;
RTC_TimeTypeDef RTC_TimeStruct;
RTC_AlarmTypeDefRTC_AlarmStruct;
RCC_Configuration();
GPIO_Configuration();
NVIC_Configuration();
LogInit();
RCC_LSE_Enable(RCC_LSE_MODE_OSC, RCC_LSE_AMP_NORMAL,RCC_LSE_DRIVER_NORMAL);
RTC_InitStruct.DateStruct.Day= 0x21;
RTC_InitStruct.DateStruct.Month= RTC_Month_June;、RTC_InitStruct.DateStruct.Week= RTC_Weekday_Monday;
RTC_InitStruct.DateStruct.Year= 0x23;
RTC_InitStruct.TimeStruct.Hour= 0x2;
RTC_InitStruct.TimeStruct.Minute= 0x58;
RTC_InitStruct.TimeStruct.Second= 0x59;
RTC_InitStruct.TimeStruct.AMPM = 1;
RTC_InitStruct.TimeStruct.H24 = 0;
RTC_InitStruct.RTC_ClockSource = RTC_RTCCLK_FROM_LSE;
RTC_Init(&RTC_InitStruct);
RTC_AlarmStruct.RTC_AlarmMask
= RTC_AlarmMask_WeekMON | RTC_AlarmMask_WeekTUE |
RTC_AlarmMask_WeekWED | RTC_AlarmMask_WeekTHU | RTC_AlarmMask_WeekFRI;
RTC_AlarmStruct.RTC_AlarmTime.Hour= 6;
RTC_AlarmStruct.RTC_AlarmTime.Minute= 0x45;
RTC_AlarmStruct.RTC_AlarmTime.Second= 0;
RTC_SetAlarm(RTC_Alarm_A,&RTC_AlarmStruct);
RTC_AlarmCmd(RTC_Alarm_A,ENABLE);
RTC_ITConfig(RTC_IT_ALARMA| RTC_IT_INTERVAL, ENABLE);
Lcd_Init();
Lcd_Clear(RED);
Gui_DrawFont_GBK16(20,10,GRAY0,RED,"CW32F030");
Gui_DrawFont_GBK16(20,40,GRAY0,RED,"RTC Test");
Gui_DrawFont_GBK16(20,80,GRAY0,RED," : :"); Gui_DrawFont_GBK16(20,140,GRAY0,RED,"JENNYZHAOJIE");
Gui_DrawLine(0,30,127,30,GRAY0);
Gui_DrawLine(0,136,127,136,GRAY0);
while(1)
{
RTC_GetTime(&RTC_TimeStruct);
ShowNum(20,80,GRAY0,RED,RTC_TimeStruct.Hour,2);
ShowNum(44,80,GRAY0,RED,RTC_TimeStruct.Minute,2);
ShowNum(68,80,GRAY0,RED,RTC_TimeStruct.Second,2);
delay(500);
}
}
经程序的编译与下载,则可以得到图2所示的计时效果。
图3 计时效果
此外,如何需要对RTC的计时值进行调整,还可利用开发板上3个小按键来进行数值的调整和设置,感兴趣的话不妨一试。