代码分享给大家:
/*******************************************************************!
\brief 使用固定格式设置时间,默认东八区
\param[in] year: 0 ~ 99 (十进制)
month: 1 ~ 12 (十进制)
date: 1 ~ 31 (十进制)
day_of_week:1 ~7 (十进制)
hour: 0 ~ 23
minute: 0 ~ 59
second: 0 ~ 59
\param[out] none
\retval none
*******************************************************************/
void BSP_RTC_time_setup(uint8_t year, uint8_t month, uint8_t date,\
uint8_t hour, uint8_t minute, uint8_t second)
{
//设置RTC时间值
rtc_parameter_struct rtc_initpara;
rtc_initpara.factor_asyn = 0x7F;
rtc_initpara.factor_syn = 0xFF;
rtc_initpara.year = (year);
rtc_initpara.day_of_week = RTC_SATURDAY; // 一般用不到
rtc_initpara.month = (month);
rtc_initpara.date = (date);
rtc_initpara.display_format = RTC_24HOUR;
rtc_initpara.am_pm = RTC_AM;
rtc_initpara.hour = RTC_ByteToBCD(hour);
rtc_initpara.minute = RTC_ByteToBCD(minute);
rtc_initpara.second = RTC_ByteToBCD(second);
#if 0
/* current time input */
//当前时间输入
printf("=======Configure RTC Time========\n\r");
printf(" please input hour:\n\r");
while (0xFF == tmp_hh)
{
tmp_hh = usart_input_threshold(23);//输入 时
rtc_initpara.hour = tmp_hh;
}
printf(" %0.2x\n\r", tmp_hh);
printf(" please input minute:\n\r");
while (0xFF == tmp_mm)
{
tmp_mm = usart_input_threshold(59);//输入 分
rtc_initpara.minute = tmp_mm;
}
printf(" %0.2x\n\r", tmp_mm);
printf(" please input second:\n\r");
while (0xFF == tmp_ss)
{
tmp_ss = usart_input_threshold(59);//输入 秒
rtc_initpara.second = tmp_ss;
}
printf(" %0.2x\n\r", tmp_ss);
#endif
//RTC当前时间配置
if(ERROR == rtc_init(&rtc_initpara))
{
printf("\n\r** RTC time configuration failed! **\n\r");
}
else
{
printf("\n\r** RTC time configuration success! **\n\r");
rtc_show_time();
}
}
|
RTC有一个初始化模式,RTC运行起来,如果重新想设置RTC时间,需要控制RTC模块进入初始化模式