1. 根据上手快慢,打算先用VS code入手,这个快准狠,先下载并启动code
#include <rtthread.h>
#include "hal_data.h"
#include <rtdevice.h>
#include <board.h>
#define DBG_TAG "led"
#define DBG_LVL DBG_LOG
#include <rtdbg.h>
/* 配置 LED 灯引脚 */
#define LED_PIN_R BSP_IO_PORT_00_PIN_13
#define LED_PIN_B BSP_IO_PORT_00_PIN_12
#define LED_PIN_G BSP_IO_PORT_06_PIN_13
/* 定义 LED 亮灭电平 */
#define LED_ON (0)
#define LED_OFF (1)
/* 定义 8 组 LED 闪灯表,其顺序为 R B G */
static const rt_uint8_t _blink_tab[][3] =
{
{LED_OFF, LED_OFF, LED_OFF},
{LED_ON, LED_OFF, LED_OFF},
{LED_OFF, LED_ON, LED_OFF},
{LED_OFF, LED_OFF, LED_ON},
{LED_ON, LED_OFF, LED_ON},
{LED_ON, LED_ON, LED_OFF},
{LED_OFF, LED_ON, LED_ON},
{LED_ON, LED_ON, LED_ON},
};
void hal_entry(void)
{
rt_kprintf("\nHello RT-Thread!\n");
rt_kprintf("==================================================\n");
rt_kprintf("This example project is an RGB flicker routine!\n");
rt_kprintf("==================================================\n");
unsigned int count = 0;
unsigned int group_num = sizeof(_blink_tab)/sizeof(_blink_tab[0]);
unsigned int group_current;
/* 设置 RGB 灯引脚为输出模式 */
rt_pin_mode(LED_PIN_R, PIN_MODE_OUTPUT);
rt_pin_mode(LED_PIN_G, PIN_MODE_OUTPUT);
rt_pin_mode(LED_PIN_B, PIN_MODE_OUTPUT);
rt_pin_write(LED_PIN_R, LED_OFF);
rt_pin_write(LED_PIN_G, LED_OFF);
rt_pin_write(LED_PIN_B, LED_OFF);
do
{
/* 获得组编号 */
group_current = count % group_num;
/* 控制 RGB 灯 */
rt_pin_write(LED_PIN_R, _blink_tab[group_current][0]);
rt_pin_write(LED_PIN_B, _blink_tab[group_current][1]);
rt_pin_write(LED_PIN_G, _blink_tab[group_current][2]);
/* 输出 LOG 信息 */
LOG_D("group: %d | red led [%-3.3s] | | blue led [%-3.3s] | | green led [%-3.3s]",
group_current,
_blink_tab[group_current][0] == LED_ON ? "ON" : "OFF",
_blink_tab[group_current][1] == LED_ON ? "ON" : "OFF",
_blink_tab[group_current][2] == LED_ON ? "ON" : "OFF");
count++;
/* 延时一段时间 */
rt_thread_mdelay(500);
}while(count > 0);
}
整个代码结构如下
4 下一步的工作,
这个过程是上手了开发板,但是调试器连接失败,后面任重道远了。
不过,整体看来,rt-thread的开发环境,工作的过程还是比较丝滑的。但是在开发板的连接和使用上,还是有一些问题需要磨合。
本帖最后由 北方 于 2026-1-28 16:15 编辑
引用: 秦天qintian0303 发表于 2026-1-29 11:11 本论坛也有这个活动吗?
感觉发错地方了