利用RT-Thread延時(shí)函數(shù)控制gpio引腳繼而控制燈的亮滅情況。
編寫 rgb 彩燈運(yùn)行線程,三種顏色依次切換,中間延時(shí) 1s
static void rgb_thread_entry(void* p)
{
RGB_Init();
while(1)
{
rt_thread_mdelay(1000);
RGB_Blue(1);
rt_thread_mdelay(1000);
RGB_Green(1);
rt_thread_mdelay(1000);
RGB_Red(1);
}
}
創(chuàng)建線程啟動(dòng)函數(shù),用于啟動(dòng)上一步編寫的線程主體
static int Thread_RGB(void)
{
rt_thread_t thread = RT_NULL;
thread = rt_thread_create("rgb", rgb_thread_entry, RT_NULL, 512, 10, 10);
if(thread == RT_NULL)
{
rt_kprintf("Thread_GRB Init ERROR");
return RT_ERROR;
}
rt_thread_startup(thread);
}
添加將線程初始化添加入系統(tǒng)初始化中
INIT_APP_EXPORT(Thread_RGB);
將 main.c 中的 while 里的代碼改成 rt_thread_mdelay(1000);編譯程序,可以看到無報(bào)錯(cuò)

編譯完成,打開 Downloaded 下載器,通過 download 下載生成的.dcf 文件(第一次使用前需要先安裝串口驅(qū)動(dòng))
總的來說 GPIO 的使用步驟很簡(jiǎn)單,第一步獲取對(duì)應(yīng) GPIO 句柄,第二步配置 GPIO 模式,之后就可以調(diào)用 rtt 函數(shù)
對(duì) GPIO 進(jìn)行讀寫操作了!
-
嵌入式
+關(guān)注
關(guān)注
5149文章
19655瀏覽量
317295 -
RT-Thread
+關(guān)注
關(guān)注
32文章
1403瀏覽量
41887
發(fā)布評(píng)論請(qǐng)先 登錄
RT-Thread記錄(二、RT-Thread內(nèi)核啟動(dòng)流程)

RT-Thread編程指南
RT-Thread用戶手冊(cè)
RT-Thread編程高階用法-函數(shù)擴(kuò)展之$Sub$$與$Super$$

RT-Thread全球技術(shù)大會(huì):螢石研發(fā)團(tuán)隊(duì)使用RT-Thread的技術(shù)挑戰(zhàn)

RT-Thread全球技術(shù)大會(huì):Kconfig在RT-Thread中的工作機(jī)制

RT-Thread全球技術(shù)大會(huì):在RT-Thread上編寫測(cè)試用例

RT-Thread全球技術(shù)大會(huì):RT-Thread測(cè)試用例集合案例

RT-Thread學(xué)習(xí)筆記 RT-Thread的架構(gòu)概述

RT-Thread文檔_RT-Thread 潘多拉 STM32L475 上手指南

基于RT-Thread Studio學(xué)習(xí)

RT-Thread v5.0.2 發(fā)布

評(píng)論