微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > STM32 RTC测试成功 _只显示 时分秒

STM32 RTC测试成功 _只显示 时分秒

时间:11-13 来源:互联网 点击:

源文件位置 STM32F10x_StdPeriph_Lib_V3.1.2\Project\STM32F10x_StdPeriph_Examples\RTC\Calendar

仔细阅读其中的readme
摘抄如下
@par How to use it ?
In order to make the program work, you must do the following :
- Create a project and setup all project configuration
- Add the required Library files :
- stm32f10x_gpio.c
- stm32f10x_rcc.c
- stm32f10x_rtc.c
- stm32f10x_bkp.c
- stm32f10x_pwr.c
- misc.c
- stm32f10x_usart.c
- stm32f10x_exti.c
- system_stm32f10x.c (under Libraries\CMSIS\Core\CM3)
- stm32_eval.c (under Utilities\STM32_EVAL)
- Edit stm32f10x.h file to select the device you are working on.
- Edit stm32_eval.h file to select the evaluation board you will use.

根据之前的经验 建立工程

options中建议选上 use microLIB


现在的时间,睡觉啦

程序地址

RTC测试成功
转自Tony嵌入式论坛,地址:http://www.cevx.com/bbs/thread-26329-1-1.html

=========================================================

关键代码分析

/**
* @brief Returns the time entered by user, using Hyperterminal.
* @param None
* @retval Current time RTC counter value
*/
uint32_t Time_Regulate(void)
{
uint32_t Tmp_HH = 0xFF, Tmp_MM = 0xFF, Tmp_SS = 0xFF;

printf("\r\n==============Time Settings=====================================");
printf("\r\n Please Set Hours");

while (Tmp_HH == 0xFF)
{
Tmp_HH = USART_Scanf(23);//若超级终端输入的数据大于23,超级终端提示出错
}
printf(": %d", Tmp_HH);
printf("\r\n Please Set Minutes");
while (Tmp_MM == 0xFF)
{
Tmp_MM = USART_Scanf(59);
}
printf(": %d", Tmp_MM);
printf("\r\n Please Set Seconds");
while (Tmp_SS == 0xFF)
{
Tmp_SS = USART_Scanf(59);
}
printf(": %d", Tmp_SS);

/* Return the value to store in RTC counter register */
return((Tmp_HH*3600 + Tmp_MM*60 + Tmp_SS));
}

--------------------------------------

/**
* @brief Displays the current time.
* @param TimeVar: RTC counter value.
* @retval None
*/
void Time_Display(uint32_t TimeVar)
{
uint32_t THH = 0, TMM = 0, TSS = 0;

/* Compute hours */
THH = TimeVar / 3600;
/* Compute minutes */
TMM = (TimeVar % 3600) / 60;
/* Compute seconds */
TSS = (TimeVar % 3600) % 60;

printf("Time: %0.2d:%0.2d:%0.2d\r", THH, TMM, TSS);//\r回车,光标移到本行首
}

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

网站地图

Top