[AT32F407] 【AT-START-F407测评】+循环点亮LED

[复制链接]
 楼主| 发表于 2021-1-25 20:51 | 显示全部楼层 |阅读模式
在日历例子的基础上增加代码,实现循环点亮LED灯珠的功能要根据官方例子,摸索一下官方码农的代码编写习惯。。

  1. /**
  2.   ******************************************************************************
  3.   * File   : RTC/Calendar//main.c
  4.   * Version: V1.2.3
  5.   * Date   : 2020-08-15
  6.   * Brief  : Main program body
  7.   ******************************************************************************
  8.   */
  9.        
  10. /* Includes ------------------------------------------------------------------*/
  11. #include "at32f4xx.h"
  12. #include "at32_board.h"
  13. #include "rtc.h"
  14. #include <stdio.h>

  15. /** @addtogroup AT32F403A_StdPeriph_Examples
  16.   * @{
  17.   */

  18. /** @addtogroup RTC_Calendar
  19.   * @{
  20.   */

  21. /* Private typedef -----------------------------------------------------------*/
  22. /* Private define ------------------------------------------------------------*/
  23. /* Private macro -------------------------------------------------------------*/
  24. /* Private variables ---------------------------------------------------------*/
  25. char const weekday_table[7][10]={ "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};

  26. /* Private function prototypes -----------------------------------------------*/

  27. /**
  28.   * [url=home.php?mod=space&uid=247401]@brief[/url]  Main program.
  29.   * @param  None
  30.   * @retval None
  31.   */
  32. int main(void)
  33. {
  34.         int **=0;

  35.         /* USART configuration */
  36.         UART_Print_Init(115200);

  37.         /* RTC configuration */
  38.         RTC_Init();
  39.         RTC_Set(2021,1,25,14,16,59);
  40.         /* print initial message */
  41.         printf("\r\n\nInitial ok");
  42.        
  43. //新增,对板载的3个灯珠进行初始化,对按钮初始化
  44.         AT32_Board_Init();
  45.        

  46.        
  47.         while(1)
  48.         {
  49.                 if(RTC_GetFlagStatus(RTC_FLAG_PACE) != RESET)       
  50.                 {
  51.                         /* Update current time */
  52.                         RTC_Get();
  53. //新增,用于标记该操作哪个灯珠了。                       
  54.                         if(**>3) **=0;
  55.                         **++;
  56.                        
  57.                         /* print the current time */
  58.                         printf("\r\n");
  59.                         printf("%d/%d/%d ", calendar.w_year, calendar.w_month, calendar.w_date);
  60.                         printf("%02d:%02d:%02d %s", calendar.hour, calendar.min, calendar.sec, weekday_table[calendar.week]);
  61.                
  62.                         /* Clear the RTC Second flag */
  63.                         RTC_ClearFlag(RTC_FLAG_PACE);
  64.                        
  65.                         /* Wait until last write operation on RTC registers has finished */
  66.                         RTC_WaitForLastTask();
  67. //新增代码,用于循环点亮和关闭灯珠。
  68.                         if(**==1)
  69.                         AT32_LEDn_Toggle(LED2);
  70.                         if(**==2)
  71.                         AT32_LEDn_Toggle(LED3);
  72.                         if(**==3)
  73.                         AT32_LEDn_Toggle(LED4);
  74.        
  75.                 }

  76.                
  77.         }
  78. }

  79. /**
  80.   * @}
  81.   */

  82. /**
  83.   * @}
  84.   */

  85. /******************* (C) COPYRIGHT 2018 ArteryTek *****END OF FILE****/
经过修改后,3个灯珠就循环点亮和熄灭, 之所以没有用delay函数,是因为基例程的RTC_WaitForLastTask();

这个操作其实就是1秒的颜色,因为1秒日历的时钟系统才更新一次呀
您需要登录后才可以回帖 登录 | 注册

本版积分规则

个人签名:如果你觉得我的分享或者答复还可以,请给我点赞,谢谢。

2045

主题

16347

帖子

222

粉丝
快速回复 返回顶部 返回列表