打印
[AT32F407]

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

[复制链接]
379|0
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
gaoyang9992006|  楼主 | 2021-1-25 20:51 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
在日历例子的基础上增加代码,实现循环点亮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秒日历的时钟系统才更新一次呀

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

认证:西安公路研究院南京院
简介:主要工作从事监控网络与通信网络设计,以及从事基于嵌入式的通信与控制设备研发。擅长单片机嵌入式系统物联网设备开发,音频功放电路开发。

1939

主题

15842

帖子

204

粉丝