发帖
6 0 1

基于AI-WB2模块-测试点亮LED

WangChong
论坛元老

72

主题

853

回帖

1万

积分

论坛元老

积分
10871
Ai-WB2系列 902 6 2023-10-5 18:59:52
在我们成功的对环境进行初始化之后,尝试写一个HelloWorld来验证下外设资源
这里我们尝试点亮 1 个 RGB led灯, 本教程基于Ai-wb2-32s-kit 开发板,如若使用Ai-wb2芯片则自己修改GPIO端口即可
步骤如下:
1- 首先在官方下载AI-wb2-32s kit的原理图
2- 根据下图得知,只需要对,对应端口IO3 IO14 IO17 分别给予高电平,那么不同的LED颜色将会被点亮。
360截图17251003107141142.png

3-代码如下:
  1. #include <stdio.h>
  2. #include <string.h>
  3. //引入博流的GPIO库
  4. #include "bl_gpio.h"
  5. #include <FreeRTOS.h>
  6. #include <task.h>

  7. // define the gpio port for blue 定义蓝色gpio端口
  8. #define BLUE_LED  3
  9. // define the gpio port for red  定义红色gpio端口
  10. #define RED_LED  14
  11. // define the gpio port for green 定义绿色gpio端口
  12. #define GREEN_LED  17


  13. void main(){
  14.     // 允许端口输出
  15.    bl_gpio_enable_output(BLUE_LED,1,0);
  16.     //输出高电平
  17.    bl_gpio_output_set(BLUE_LED, 1);
  18.    //休眠一秒
  19.    vTaskDelay(1000);
  20.    bl_gpio_output_set(BLUE_LED, 0);
  21.    vTaskDelay(1000);

  22.    bl_gpio_enable_output(RED_LED,1,0);
  23.    bl_gpio_output_set(RED_LED, 1);
  24.    vTaskDelay(1000);
  25.    bl_gpio_output_set(RED_LED, 0);
  26.    vTaskDelay(1000);

  27.    bl_gpio_enable_output(GREEN_LED,1,0);
  28.    bl_gpio_output_set(GREEN_LED, 1);
  29.    vTaskDelay(1000);
  30.    bl_gpio_output_set(GREEN_LED, 0);
  31.    vTaskDelay(1000);


  32.     bl_gpio_output_set(BLUE_LED, 1);
  33.     bl_gpio_output_set(RED_LED, 1);
  34.     bl_gpio_output_set(GREEN_LED, 1);

  35.    
  36. }
复制代码
在上述代码中,我并不想使用FreeRtos,但是我不知道怎么基于当前的MCU写一个精准的定时,于是为了使用Task里的vTaskDelay 函数,所以必须引入FreeRtos作为前置依赖(因为自己没有系统学习过Freertos, 学习必须一步一个脚印,不能急于求成)


实验现象如下
蓝色灯亮起 - > 熄灭
红色灯亮起- > 熄灭
绿色灯亮起-> 熄灭
红绿蓝同时亮起

微信图片_20231005185838.jpg
Ps:Hal函数或者类似库函数的使用,使其对于应用开发的难度减小了很多,并不是很需要去学习寄存器,而是仅仅的掌握函数


──── 0人觉得很赞 ────

使用道具 举报

2023-10-5 19:55:12
学习
2023-10-5 20:22:13
打卡
2023-10-6 10:26:43
厉害
2023-11-19 15:26:32
膜拜
2023-11-19 23:11:02

加油,一起学习
2023-11-27 18:50:55
打卡
您需要登录后才可以回帖 立即登录
高级模式
返回
统计信息
  • 会员数: 28101 个
  • 话题数: 39327 篇