高中生
最后登录1970-1-1
在线时间 小时
注册时间2016-3-27
|
本人想实现按键调节RTC时间,不考虑断电否。自己可以随时设置时间,参考野火的历程RTC-实时时钟。
是不是专门调用这个函数 RTC_TimeRegulate(); 而不是把这个函数写到 if (RTC_ReadBackupRegister(RTC_BKP_DR0) != 0x32F2) 里面判断是否断电。请问我理解的对不。我现在通过按键调节时间,需要专门调用RTC_TimeRegulate();见下面只需把 USART_Scanf()函数换成按键获取的值,请问我的思路有问题么?
void RTC_TimeRegulate(void)
{
uint32_t tmp_hh = 0xFF, tmp_mm = 0xFF, tmp_ss = 0xFF;
printf("\r\n==============Time Settings=====================================\r\n");
RTC_TimeStructure.RTC_H12 = RTC_H12_AM;
printf("\r\n Please Set Hours (00-23)");
while (tmp_hh == 0xFF)
{
tmp_hh = USART_Scanf(0, 23);
RTC_TimeStructure.RTC_Hours = tmp_hh;
}
printf(": %0.2d\n", tmp_hh);
printf("\r\n Please Set Minutes (00-59)");
while (tmp_mm == 0xFF)
{
tmp_mm = USART_Scanf(0, 59);
RTC_TimeStructure.RTC_Minutes = tmp_mm;
}
printf(": %0.2d\n", tmp_mm);
printf("\r\n Please Set Seconds (00-59)");
while (tmp_ss == 0xFF)
{
tmp_ss = USART_Scanf(0, 59);
RTC_TimeStructure.RTC_Seconds = tmp_ss;
}
printf(": %0.2d\n", tmp_ss);
/* Configure the RTC time register */
if(RTC_SetTime(RTC_Format_BIN, &RTC_TimeStructure) == ERROR)
{
printf("\r\n>> !! RTC Set Time failed. !! <<\r\n");
}
else
{
printf("\r\n>> !! RTC Set Time success. !! <<\r\n");
RTC_TimeShow();
/* Indicator for the RTC configuration */
RTC_WriteBackupRegister(RTC_BKP_DR0, 0x32F2);
}
tmp_hh = 0xFF;
tmp_mm = 0xFF;
tmp_ss = 0xFF;
printf("\r\n==============Date Settings=====================================\r\n");
printf("\r\n Please Set WeekDay (01-07)");
while (tmp_hh == 0xFF)
{
tmp_hh = USART_Scanf(1, 7);
RTC_DateStructure.RTC_WeekDay = tmp_hh;
}
printf(": %0.2d\n", tmp_hh);
tmp_hh = 0xFF;
printf("\r\n Please Set Date (01-31)");
while (tmp_hh == 0xFF)
{
tmp_hh = USART_Scanf(1, 31);
RTC_DateStructure.RTC_Date = tmp_hh;
}
printf(": %0.2d\n", tmp_hh);
printf("\r\n Please Set Month (01-12)");
while (tmp_mm == 0xFF)
{
tmp_mm = USART_Scanf(1, 12);
RTC_DateStructure.RTC_Month = tmp_mm;
}
printf(": %0.2d\n", tmp_mm);
printf("\r\n Please Set Year (00-99)");
while (tmp_ss == 0xFF)
{
tmp_ss = USART_Scanf(0, 99);
RTC_DateStructure.RTC_Year = tmp_ss;
}
printf(": %0.2d\n", tmp_ss);
/* Configure the RTC date register */
if(RTC_SetDate(RTC_Format_BIN, &RTC_DateStructure) == ERROR)
{
printf("\r\n>> !! RTC Set Date failed. !! <<\r\n");
}
else
{
printf("\r\n>> !! RTC Set Date success. !! <<\r\n");
RTC_DateShow();
/* Indicator for the RTC configuration */
RTC_WriteBackupRegister(RTC_BKP_DR0, 0x32F2);
}
}
|
|