【ESK32-360测评】+ RTC计时器
<p>1. RTC基本使用</p><p>在例程中,提供了RTC的实验示例,在串口的配合下可以设置RTC的初始数值,并通过串口来输出RTC计时值,其运行效果如图1所示。</p>
<p>图1 串口设置和显示RTC计时值</p>
<p> </p>
<p>2. RTC计时器</p>
<p>为了能直观地来显示RTC计时值,可通过TFT显示屏来实现,所用到的主要为数值显示函数。</p>
<p>改造后的计时显示函数为:</p>
<pre>
<code class="language-cpp">void AP_Time_Show(void)
{
AP_Time_Count(&CurTime);
LCD_ShowNum(Line6,22,CurTime.year,4);
LCD_CharDisplay(Line6, 84, '-');
LCD_ShowNum(Line6,100,CurTime.month,2);
LCD_CharDisplay(Line6, 132, '-');
LCD_ShowNum(Line6,148,CurTime.day,2);
LCD_ShowNum(Line7,52,CurTime.hour,2);
LCD_CharDisplay(Line7, 84, ':');
LCD_ShowNum(Line7,100,CurTime.minute,2);
LCD_CharDisplay(Line7, 132,':');
LCD_ShowNum(Line7,148,CurTime.second,2);
}
</code></pre>
<p>主程序的内容为:</p>
<pre>
<code class="language-cpp">int main(void)
{
CKCU_PeripClockConfig_TypeDef CKCUClock = {{0}};
CKCUClock.Bit.BKP = 1;
CKCU_PeripClockConfig(CKCUClock, ENABLE);
if (PWRCU_CheckReadyAccessed() != PWRCU_OK)
{
while (1);
}
HT32F_DVB_LEDInit(HT_LED1);
RETARGET_Configuration();
NVIC_EnableIRQ(RTC_IRQn);
if (PWRCU_GetFlagStatus() == PWRCU_FLAG_BAKPOR)
{
LCD_StringLineDisplay(Line5, " Power On Reset occurred!");
}
LCD_Init();
LCD_Config();
LCD_BackColorSet(Black);
LCD_TextColorSet(Red);
LCD_StringLineDisplay(Line3, " LCD_RTC TEST");
LCD_TextColorSet(Yellow);
if (PWRCU_ReadBackupRegister((PWRCU_BAKREG_Enum) PWRCU_BAKREG_0_RTC_KEY) != 0xAA55A5A5)
{
LCD_StringLineDisplay(Line5, "RTC not yet configured!");
LCD_StringLineDisplay(Line6, " -- ");
LCD_StringLineDisplay(Line7, " ::");
RTC_Configuration();
#if 1
AP_Time_Init(&DateTime);
#else
DateTime.year = 2020;
DateTime.month= 7;
DateTime.day = 25;
DateTime.hour = 22;
DateTime.minute = 5;
DateTime.second = 0;
#endif
if (!AP_Time_Adjust(&DateTime))
{
LCD_StringLineDisplay(Line5, "Adjust time error!");
while (1);
}
RTC_Cmd(ENABLE);
PWRCU_WriteBackupRegister((PWRCU_BAKREG_Enum) PWRCU_BAKREG_0_RTC_KEY, 0xAA55A5A5);
}
else
{
LCD_StringLineDisplay(Line5, "No need to configure RTC!");
}
LCD_TextColorSet(Yellow);
LCD_StringLineDisplay(Line5, " ");
while (1)
{
if (CK_SECOND_Flag)
{
CK_SECOND_Flag = 0;
AP_Time_Show();
}
}
}
</code></pre>
<p style="text-align:justify"> </p>
<p style="text-align:justify"></p>
<p>图2 显示RTC计时值</p>
<p> </p>
<p>3. 时间设置与调整</p>
<p> 实现图3所示的时间设置与调整函数为:</p>
<pre>
<code class="language-cpp">int f=1,n=0,m=23,c=0,a1=0,a2=0,a3=0;
while(f)
{
TmpStatus = GPIO_ReadInBit(HT_GPIOC, GPIO_PIN_15);
GPIO_WriteOutBits(HT_GPIOD, GPIO_PIN_0, !TmpStatus);// !灭
if(TmpStatus) n++; //増值
if(n>m) n=0;
TmpStatus = GPIO_ReadInBit(HT_GPIOD, GPIO_PIN_1);
GPIO_WriteOutBits(HT_GPIOD, GPIO_PIN_2, TmpStatus);// 亮
if(TmpStatus==0) // 切换
{
c++;
if(c>2) c=0;
if(c==0) m=23;
if(c==1) m=59;
if(c==2) m=59;
}
TmpStatus = GPIO_ReadInBit(HT_GPIOB, GPIO_PIN_9);
GPIO_WriteOutBits(HT_GPIOB, GPIO_PIN_6, TmpStatus);// 亮
if(TmpStatus==0) f=0; //退出
if(c==0) a1=n;
if(c==1) a2=n;
if(c==2) a3=n;
LCD_ShowNum(Line7,52,a1,2);
LCD_CharDisplay(Line7, 84, ':');
LCD_ShowNum(Line7,100,a2,2);
LCD_CharDisplay(Line7, 132,':');
LCD_ShowNum(Line7,148,a3,2);
delay(300);
}
</code></pre>
<p></p>
<p>图3 数据设置与调整</p>
<p> </p>
<p>在数据设置时,以Wakeup键来调整数值的大小,以Key1来切换设置项(确定是时、分、秒),以Key2来确认设置操作。</p>
页:
[1]