固件库中已经定义好了2个结构体,使用起来非常方便:- RTC_DateTypeDef RTC_DateStructure;
- RTC_TimeTypeDef RTC_TimeStructure;
复制代码 在STM32F30X_RTC.H文件中已定义:
- /**
- * @brief RTC Date structure definition
- */
- typedef struct
- {
- uint8_t RTC_WeekDay; /*!< Specifies the RTC Date WeekDay.
- This parameter can be a value of @ref RTC_WeekDay_Definitions */
-
- uint8_t RTC_Month; /*!< Specifies the RTC Date Month (in BCD format).
- This parameter can be a value of @ref RTC_Month_Date_Definitions */
- uint8_t RTC_Date; /*!< Specifies the RTC Date.
- This parameter must be set to a value in the 1-31 range. */
-
- uint8_t RTC_Year; /*!< Specifies the RTC Date Year.
- This parameter must be set to a value in the 0-99 range. */
- }RTC_DateTypeDef;
复制代码- typedef struct
- {
- uint8_t RTC_Hours; /*!< Specifies the RTC Time Hour.
- This parameter must be set to a value in the 0-12 range
- if the RTC_HourFormat_12 is selected or 0-23 range if
- the RTC_HourFormat_24 is selected. */
- uint8_t RTC_Minutes; /*!< Specifies the RTC Time Minutes.
- This parameter must be set to a value in the 0-59 range. */
-
- uint8_t RTC_Seconds; /*!< Specifies the RTC Time Seconds.
- This parameter must be set to a value in the 0-59 range. */
- uint8_t RTC_H12; /*!< Specifies the RTC AM/PM Time.
- This parameter can be a value of @ref RTC_AM_PM_Definitions */
- }RTC_TimeTypeDef;
复制代码 在.C文件里做申明:
- RTC_DateTypeDef RTC_DateStructure;
- RTC_TimeTypeDef RTC_TimeStructure;
复制代码 在main.c中:
- RTC_Config();
- while (1)
- {
- /* Get the RTC current Time */
- RTC_GetTime(RTC_Format_BIN, &RTC_TimeStructure);
- /* Get the RTC current Date */
- RTC_GetDate(RTC_Format_BIN, &RTC_DateStructure);
- /* Display time Format : hh:mm:ss */
- sprintf((char*)showtime,"%.2d:%.2d:%.2d",RTC_TimeStructure.RTC_Hours, RTC_TimeStructure.RTC_Minutes, RTC_TimeStructure.RTC_Seconds);
- /* Display date Format : mm-dd-yy */
- sprintf((char*)showdate,"%.2d-%.2d-%.2d",RTC_DateStructure.RTC_Month, RTC_DateStructure.RTC_Date, 2000 + RTC_DateStructure.RTC_Year);
-
- }
复制代码 在中断中描输出:
- void RTC_Alarm_IRQHandler(void)
- {
- if(RTC_GetITStatus(RTC_IT_ALRA) != RESET)
- {
-
- if(GPIO_ReadOutputDataBit(GPIOA, GPIO_Pin_5)==0)
- GPIO_SetBits(GPIOA, GPIO_Pin_5); //Green LED
- else
- GPIO_ResetBits(GPIOA, GPIO_Pin_5); //Green LED
- RTC_ClearITPendingBit(RTC_IT_ALRA);
- EXTI_ClearITPendingBit(EXTI_Line17);
- }
- }
复制代码 附件:
Nucleo_F334R8_RTC.zip
(3.87 MB, 下载次数: 10)
|