stm32万年历流程图_基于 STM32 RTC的万年历

例子基本是照抄官方的 万年历算法也没深入研究 主要是大赛 都要求会用DS1302 若我用STM32来做 肯定不用那个片子了。

这个用的是 LSE (片外低速时钟)配合 掉电寄存器来确定是否配置时钟。本文引用地址:http://www.eepw.com.cn/article/201612/325211.htm

注释很全 话不多说了。

u8 TimeDisplay;

int main(void)

{

SystemInit();

stm32_Init ();//GPIO PA8 Init

USART_Configuration();//USART2 9600-8-N-1

NVIC_Configuration();//Enable the RTC Interrupt

RTC_Configuration();//RTC的启动

start_rct();//检测是否配置时钟

Time_Show();//不断地时钟串口输出

}

void LEDToggle(void)

{

GPIOA->ODR=GPIOA->ODR^GPIO_Pin_8 ;

}

RTC.C///

#include "stm32f10x.h"

#include //用到printf函数的串口的输出函数 注意勾选MicroLIB

u32 Time_Regulate(void);

void Time_Adjust(void);

void Time_Show(void);

void Time_Display(u32 TimeVar);

u32 USART_Scanf(u32 value);

extern u8 TimeDisplay;

void RTC_Configuration(void)

{

/* Enable PWR and BKP clocks */

RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE);

/* Allow access to BKP Domain */

PWR_BackupAccessCmd(ENABLE);

/* Reset Backup Domain */

//BKP_DeInit(); //记录0XA5A5 来确定是否重置时间

/* Enable LSE */

RCC_LSEConfig(RCC_LSE_ON);

/* Wait till LSE is ready */

while (RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET)

{}

/* Select LSE as RTC Clock Source */

RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);

/* Enable RTC Clock */

RCC_RTCCLKCmd(ENABLE);

/* Wait for RTC registers synchronization */

RTC_WaitForSynchro();

/* Wait until last write operation on RTC registers has finished */

RTC_WaitForLastTask();

/* Enable the RTC Second */

RTC_ITConfig(RTC_IT_SEC, ENABLE);

/* Wait until last write operation on RTC registers has finished */

RTC_WaitForLastTask();

/* Set RTC prescaler: set RTC period to 1sec */

RTC_SetPrescaler(32767); /* RTC period = RTCCLK/RTC_PR = (32.768 KHz)/(32767+1) */

/* Wait until last write operation on RTC registers has finished */

RTC_WaitForLastTask();

}

/*******************************************************************************

* Function Name : Time_Regulate

* Description : Returns the time entered by user, using Hyperterminal.

* Input : None

* Output : None

* Return : Current time RTC counter value

*******************************************************************************/

//u32 Month_Days[13] = {0,31,28,31,30, 31, 30, 31, 31, 30, 31, 30, 31};

u32 Month_Days_Accu_C[13] = {0,31,59,90,120,151,181,212,243,273,304,334,365};

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值