微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > 基于 STM32 RTC的万年历

基于 STM32 RTC的万年历

时间:12-03 来源:互联网 点击:

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;
}
}

不要使用串口助手 推荐使用超级终端。

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top