1、开发环境:
RT-Thread版本:4.0.3
操作系统:Windows 10
RT-Thread Studio版本:2.1.0
微控制器: AB32VG1(32位 RISC-V 处理器)
2、板载介绍
开发板的资料比较少,下图是通过RT-Thread Studio获得的资料信息。本文将通过GPIO模拟控制RGB LED灯实现全彩控制。
LED-R | PE1 |
LED-G | PE4 |
LED-B | PA2 |
3、环境搭建
环境的搭建主要是RT-Thread Studio安装与包管理、项目的创建于配置和程序下载。环境的配置是参考博客文章环境搭建参考。
4、实现全彩LED灯闪烁
(1)LED灯电路图
LED灯采用共阳极连接。
(2)实现代码
/**Includes*********************************************************************/
#include <rtthread.h>
#include "board.h"
int main(void)
{
uint32_t cnt = 0;
uint8_t pin_r = rt_pin_get("PE.1");
uint8_t pin_g = rt_pin_get("PE.4");
uint8_t pin_b = rt_pin_get("PA.2");
rt_pin_mode(pin_r, PIN_MODE_OUTPUT);
rt_pin_mode(pin_g, PIN_MODE_OUTPUT);
rt_pin_mode(pin_b, PIN_MODE_OUTPUT);
while (1)
{
//红
rt_pin_write(pin_r, PIN_LOW);
rt_pin_write(pin_g, PIN_HIGH);
rt_pin_write(pin_b, PIN_HIGH);
rt_thread_mdelay(1000);
//绿
rt_pin_write(pin_r, PIN_HIGH);
rt_pin_write(pin_g, PIN_LOW);
rt_pin_write(pin_b, PIN_HIGH);
rt_thread_mdelay(1000);
//蓝
rt_pin_write(pin_r, PIN_HIGH);
rt_pin_write(pin_g, PIN_HIGH);
rt_pin_write(pin_b, PIN_LOW);
rt_thread_mdelay(1000);
//黄(红+绿)
rt_pin_write(pin_r, PIN_LOW);
rt_pin_write(pin_g, PIN_LOW);
rt_pin_write(pin_b, PIN_HIGH);
rt_thread_mdelay(1000);
//紫(红+蓝)
rt_pin_write(pin_r, PIN_LOW);
rt_pin_write(pin_g, PIN_HIGH);
rt_pin_write(pin_b, PIN_LOW);
rt_thread_mdelay(1000);
//青(绿+蓝)
rt_pin_write(pin_r, PIN_HIGH);
rt_pin_write(pin_g, PIN_LOW);
rt_pin_write(pin_b, PIN_LOW);
rt_thread_mdelay(1000);
//白(红+绿+蓝)
rt_pin_write(pin_r, PIN_LOW);
rt_pin_write(pin_g, PIN_LOW);
rt_pin_write(pin_b, PIN_LOW);
rt_thread_mdelay(1000);
//黑(全部关闭)
rt_pin_write(pin_r, PIN_HIGH);
rt_pin_write(pin_g, PIN_HIGH);
rt_pin_write(pin_b, PIN_HIGH);
rt_thread_mdelay(1000);
cnt++;
}
return 0;
}
(3)实验现象
本帖最后由 臭弟弟 于 2021-4-16 15:44 编辑