你的浏览器版本过低,可能导致网站不能正常访问!
为了你能正常使用网站功能,请使用这些浏览器。

【STM32-NUCLEO334R8学习笔记】3.RTC+日历,非UNIX时间戳

[复制链接]
caizhiwei 发布时间:2015-2-2 16:01
固件库中已经定义好了2个结构体,使用起来非常方便:
  1. RTC_DateTypeDef RTC_DateStructure;
  2. RTC_TimeTypeDef RTC_TimeStructure;
复制代码
在STM32F30X_RTC.H文件中已定义:


  1. /**
  2.   * @brief  RTC Date structure definition  
  3.   */
  4. typedef struct
  5. {
  6.   uint8_t RTC_WeekDay; /*!< Specifies the RTC Date WeekDay.
  7.                         This parameter can be a value of @ref RTC_WeekDay_Definitions */
  8.   
  9.   uint8_t RTC_Month;   /*!< Specifies the RTC Date Month (in BCD format).
  10.                         This parameter can be a value of @ref RTC_Month_Date_Definitions */

  11.   uint8_t RTC_Date;     /*!< Specifies the RTC Date.
  12.                         This parameter must be set to a value in the 1-31 range. */
  13.   
  14.   uint8_t RTC_Year;     /*!< Specifies the RTC Date Year.
  15.                         This parameter must be set to a value in the 0-99 range. */
  16. }RTC_DateTypeDef;
复制代码
  1. typedef struct
  2. {
  3.   uint8_t RTC_Hours;    /*!< Specifies the RTC Time Hour.
  4.                         This parameter must be set to a value in the 0-12 range
  5.                         if the RTC_HourFormat_12 is selected or 0-23 range if
  6.                         the RTC_HourFormat_24 is selected. */

  7.   uint8_t RTC_Minutes;  /*!< Specifies the RTC Time Minutes.
  8.                         This parameter must be set to a value in the 0-59 range. */
  9.   
  10.   uint8_t RTC_Seconds;  /*!< Specifies the RTC Time Seconds.
  11.                         This parameter must be set to a value in the 0-59 range. */

  12.   uint8_t RTC_H12;      /*!< Specifies the RTC AM/PM Time.
  13.                         This parameter can be a value of @ref RTC_AM_PM_Definitions */
  14. }RTC_TimeTypeDef;
复制代码
在.C文件里做申明:
  1. RTC_DateTypeDef RTC_DateStructure;
  2. RTC_TimeTypeDef RTC_TimeStructure;
复制代码
在main.c中:
  1. RTC_Config();
  2.     while (1)
  3.     {         
  4.         /* Get the RTC current Time */
  5.     RTC_GetTime(RTC_Format_BIN, &RTC_TimeStructure);
  6.     /* Get the RTC current Date */
  7.     RTC_GetDate(RTC_Format_BIN, &RTC_DateStructure);
  8.     /* Display time Format : hh:mm:ss */
  9.     sprintf((char*)showtime,"%.2d:%.2d:%.2d",RTC_TimeStructure.RTC_Hours, RTC_TimeStructure.RTC_Minutes, RTC_TimeStructure.RTC_Seconds);
  10.     /* Display date Format : mm-dd-yy */
  11.     sprintf((char*)showdate,"%.2d-%.2d-%.2d",RTC_DateStructure.RTC_Month, RTC_DateStructure.RTC_Date, 2000 + RTC_DateStructure.RTC_Year);   
  12.    
  13.     }
复制代码
在中断中描输出:
  1. void RTC_Alarm_IRQHandler(void)
  2. {

  3.   if(RTC_GetITStatus(RTC_IT_ALRA) != RESET)
  4.   {
  5.    
  6.        if(GPIO_ReadOutputDataBit(GPIOA,  GPIO_Pin_5)==0)
  7.       GPIO_SetBits(GPIOA, GPIO_Pin_5);  //Green LED
  8.      else
  9.         GPIO_ResetBits(GPIOA, GPIO_Pin_5);  //Green LED

  10.     RTC_ClearITPendingBit(RTC_IT_ALRA);
  11.     EXTI_ClearITPendingBit(EXTI_Line17);
  12.   }
  13. }
复制代码
附件:
Nucleo_F334R8_RTC.zip (3.87 MB, 下载次数: 10)
收藏 评论7 发布时间:2015-2-2 16:01

举报

7个回答
wyxy163@126.com 回答时间:2015-2-2 18:23:07
提示: 作者被禁止或删除 内容自动屏蔽
moyanming2013 回答时间:2015-2-2 19:54:17
XUEXI学习了。。。
Emmanel丶 回答时间:2015-2-2 21:29:24
学习了。。。
STM32-366775 回答时间:2015-2-2 22:03:01
下载学习一下
左岸右岸 回答时间:2015-2-2 22:27:33
如果我也能申请到就能学习学习了
wgsxsm 回答时间:2015-2-3 21:27:56
不错,楼主加油
hanmcustm 回答时间:2015-2-3 21:45:02
不错不错

所属标签

关于
我们是谁
投资者关系
意法半导体可持续发展举措
创新与技术
意法半导体官网
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
官方最新发布
STM32N6 AI生态系统
STM32MCU,MPU高性能GUI
ST ACEPACK电源模块
意法半导体生物传感器
STM32Cube扩展软件包
关注我们
st-img 微信公众号
st-img 手机版