基于 STM32 RTC的万年历
void start_rct(void)
{
if(BKP_ReadBackupRegister(BKP_DR1) != 0xA5A5)
{
/* Backup data register value is not correct or not yet programmed (when
the first time the program is executed) */
printf("\r\n\n RTC not yet configured....");
/* RTC Configuration */
RTC_Configuration();
printf("\r\n RTC configured....");
/* Adjust time by values entred by the user on the hyperterminal */
Time_Adjust();
BKP_WriteBackupRegister(BKP_DR1, 0xA5A5);
}
else
{
/* Check if the Power On Reset flag is set */
if(RCC_GetFlagStatus(RCC_FLAG_PORRST) != RESET)
{
printf("\r\n\n Power On Reset occurred....");
}
/* Check if the Pin Reset flag is set */
else if(RCC_GetFlagStatus(RCC_FLAG_PINRST) != RESET)
{
printf("\r\n\n External Reset occurred....");
}
printf("\r\n No need to configure RTC....");
/*一下都是可以省略的 RTC_Configuration 已有启用 RTC_IT_SEC */
/* Wait for RTC registers synchronization */
RTC_WaitForSynchro();
/* Enable the RTC Second */
RTC_ITConfig(RTC_IT_SEC, ENABLE);
/* Wait until last write operation on RTC registers has finished */
RTC_WaitForLastTask();
}
}
其中这个函数决定了 printf 函数的输出目标 一定要有的。
int fputc(int ch)
{
USART_SendData(USART2, (u8) ch);
while(USART_GetFlagStatus(USART2, USART_FLAG_TXE) == RESET);
return ch;
}
秒中断;
/******************************************************************************/
/* STM32F10x Peripherals Interrupt Handlers */
/******************************************************************************/
/**
* @brief This function handles RTC global interrupt request.
* @param None
* @retval None
*/
extern u8 TimeDisplay;
void LEDToggle(void);
void RTC_IRQHandler(void)
{
if (RTC_GetITStatus(RTC_IT_SEC) != RESET)
{
/* Clear the RTC Second interrupt */
RTC_ClearITPendingBit(RTC_IT_SEC);
/* Toggle LED1 闪灯*/
LEDToggle();
/* Enable time update */
TimeDisplay = 1;
}
}
不要使用串口助手 推荐使用超级终端。
STM32RTC万年 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)