以下是对给定代码的逐行注释:
```c
/****************************************************************************************
*
* @file main.c
* @brief main C file
*
* @date 16 Feb. 2023
* @author AE Team
* @note
* Change Logs:
* Date Author Notes
* 16 Feb. 2023 Lisq the first version
*
* Copyright (C) Shanghai Eastsoft Microelectronics Co. Ltd. All rights reserved.
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the License); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an AS IS BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
****************************************************************************************
*/
/* Includes ------------------------------------------------------------------ */
#include "main.h"
/* Private Macros ------------------------------------------------------------ */
/* Private Variables --------------------------------------------------------- */
/* Public Variables ---------------------------------------------------------- */
/* Private Constants --------------------------------------------------------- */
/* Private function prototypes ----------------------------------------------- */
/* Private Function ---------------------------------------------------------- */
/** @addtogroup Projects_Examples_ALD
* @{
*/
/** @addtogroup Examples
* @{
*/
/**
* @brief 初始化USART模块的引脚。
* @retval None
*/
static void gpio_init(void)
{
ald_gpio_init_t gpio_init;
/* 初始化gpio_init结构体 */
memset(&gpio_init, 0x0, sizeof(gpio_init));
/* 初始化LED引脚 */
gpio_init.mode = ALD_GPIO_MODE_OUTPUT; // 设置模式为输出
gpio_init.od = ALD_GPIO_PUSH_PULL; // 设置OD为推挽模式
gpio_init.pupd = ALD_GPIO_FLOATING; // 设置PUPD为浮空输入
gpio_init.odrv = ALD_GPIO_OUT_DRIVE_NORMAL; // 设置驱动强度为正常
gpio_init.flt = ALD_GPIO_FILTER_DISABLE; // 禁用滤波器
gpio_init.type = ALD_GPIO_TYPE_CMOS; // 设置类型为CMOS
gpio_init.func = ALD_GPIO_FUNC_1; // 设置功能为通用功能1
ald_gpio_init(LED_PORT, LED_PIN, &gpio_init); // 初始化LED引脚
/* 再次初始化gpio_init结构体 */
memset(&gpio_init, 0x0, sizeof(gpio_init));
/* 初始化KEY引脚 */
gpio_init.mode = ALD_GPIO_MODE_INPUT; // 设置模式为输入
gpio_init.od = ALD_GPIO_PUSH_PULL; // 设置OD为推挽模式
gpio_init.pupd = ALD_GPIO_PUSH_DOWN; // 设置PUPD为下拉输入
gpio_init.odrv = ALD_GPIO_OUT_DRIVE_NORMAL; // 设置驱动强度为正常
gpio_init.flt = ALD_GPIO_FILTER_DISABLE; // 禁用滤波器
gpio_init.type = ALD_GPIO_TYPE_CMOS; // 设置类型为CMOS
gpio_init.func = ALD_GPIO_FUNC_1; // 设置功能为通用功能1
ald_gpio_init(KEY_PORT, KEY_PIN, &gpio_init); // 初始化KEY引脚
return;
}
/**
* @brief: 主程序入口点。
* @param: None
* @retval: None
*/
int main(void)
{
/* 初始化ALD系统时钟管理单元(CMU) */
ald_cmu_init();
/* 配置系统时钟 */
ald_cmu_pll_config(ALD_CMU_PLL_INPUT_HOSC8M, ALD_CMU_PLL_OUTPUT_72M); // 配置PLL输入和输出频率
ald_cmu_clock_config(ALD_CMU_CLOCK_PLL, 72000000); // 设置系统时钟为72MHz
/* 使能所有外设时钟 */
ald_cmu_perh_clock_config(ALD_CMU_PERH_ALL, ENABLE);
/* 初始化引脚 */
gpio_init();
while (1)
{
/* 如果按键按下,点亮LED */
if (ald_gpio_read_pin(KEY_PORT, KEY_PIN))
ald_gpio_write_pin(LED_PORT, LED_PIN, 1); // 写入高电平,点亮LED
else
ald_gpio_write_pin(LED_PORT, LED_PIN, 0); // 写入低电平,熄灭LED
}
}
/**
* @}
*/
/**
* @}
*/
/************* (C) COPYRIGHT Eastsoft Microelectronics *****END OF FILE****/
```