在日历例子的基础上增加代码,实现循环点亮LED灯珠的功能要根据官方例子,摸索一下官方码农的代码编写习惯。。
- /**
- ******************************************************************************
- * File : RTC/Calendar//main.c
- * Version: V1.2.3
- * Date : 2020-08-15
- * Brief : Main program body
- ******************************************************************************
- */
-
- /* Includes ------------------------------------------------------------------*/
- #include "at32f4xx.h"
- #include "at32_board.h"
- #include "rtc.h"
- #include <stdio.h>
- /** @addtogroup AT32F403A_StdPeriph_Examples
- * @{
- */
- /** @addtogroup RTC_Calendar
- * @{
- */
- /* Private typedef -----------------------------------------------------------*/
- /* Private define ------------------------------------------------------------*/
- /* Private macro -------------------------------------------------------------*/
- /* Private variables ---------------------------------------------------------*/
- char const weekday_table[7][10]={ "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
- /* Private function prototypes -----------------------------------------------*/
- /**
- * [url=home.php?mod=space&uid=247401]@brief[/url] Main program.
- * @param None
- * @retval None
- */
- int main(void)
- {
- int **=0;
- /* USART configuration */
- UART_Print_Init(115200);
- /* RTC configuration */
- RTC_Init();
- RTC_Set(2021,1,25,14,16,59);
- /* print initial message */
- printf("\r\n\nInitial ok");
-
- //新增,对板载的3个灯珠进行初始化,对按钮初始化
- AT32_Board_Init();
-
-
- while(1)
- {
- if(RTC_GetFlagStatus(RTC_FLAG_PACE) != RESET)
- {
- /* Update current time */
- RTC_Get();
- //新增,用于标记该操作哪个灯珠了。
- if(**>3) **=0;
- **++;
-
- /* print the current time */
- printf("\r\n");
- printf("%d/%d/%d ", calendar.w_year, calendar.w_month, calendar.w_date);
- printf("%02d:%02d:%02d %s", calendar.hour, calendar.min, calendar.sec, weekday_table[calendar.week]);
-
- /* Clear the RTC Second flag */
- RTC_ClearFlag(RTC_FLAG_PACE);
-
- /* Wait until last write operation on RTC registers has finished */
- RTC_WaitForLastTask();
- //新增代码,用于循环点亮和关闭灯珠。
- if(**==1)
- AT32_LEDn_Toggle(LED2);
- if(**==2)
- AT32_LEDn_Toggle(LED3);
- if(**==3)
- AT32_LEDn_Toggle(LED4);
-
- }
-
- }
- }
- /**
- * @}
- */
- /**
- * @}
- */
- /******************* (C) COPYRIGHT 2018 ArteryTek *****END OF FILE****/
经过修改后,3个灯珠就循环点亮和熄灭, 之所以没有用delay函数,是因为基例程的RTC_WaitForLastTask();
这个操作其实就是1秒的颜色,因为1秒日历的时钟系统才更新一次呀
|