[Zhongke Bluexun AB32VG1 RISC-V board "meets" RTT] GPIO simulation realizes full-color LED lights
[Copy link]
This post was last edited by Chou Didi on 2021-4-16 15:44
1. Development environment:
RT-Thread version: 4.0.3
Operating system: Windows 10
RT-Thread Studio version: 2.1.0
Microcontroller: AB32VG1 (32-bit RISC-V processor)
2. Onboard Introduction
There is little information about the development board. The following figure shows the information obtained through RT-Thread Studio. This article will use GPIO to simulate the control of RGB LED lights to achieve full color control.
IO port corresponding to LED
LED-R |
PE1 |
LED-G |
PE4 |
LED-B |
PA2 |
3. Environment Construction
The construction of the environment mainly involves the installation and package management of RT-Thread Studio, the creation and configuration of the project, and the download of the program. The configuration of the environment is based on the reference of the blog article Environment Construction Reference .
4. Realize full-color LED light flashing
(1) LED lamp circuit diagram
The LED lights are connected with a common anode.
(2) Implementation code
/**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) Experimental phenomenon
|