今天開始學(xué)習(xí)RGB交替閃爍。
這是一個最基本的io口控制例程。看到AB32VG1編寫的內(nèi)容,感覺有些地方不懂,后面再說。現(xiàn)在先記錄整個學(xué)習(xí)過程。
1.查看硬件電路結(jié)構(gòu)


這里采用了header4×2來轉(zhuǎn)接一下。便于胸口復(fù)用。
2.軟件設(shè)計與編寫
可以看到LED是低電平使能,在相應(yīng)的io口輪次輸出0,使得LED點亮。
獲得LED
設(shè)置pin模式,
輪次輸出相應(yīng)電平,點亮或熄滅相應(yīng)led
void RGB_Init(void)
{
// 獲得 led
Led.LED_R = rt_pin_get("PE.1");
Led.LED_G = rt_pin_get("PE.4");
Led.LED_B = rt_pin_get("PA.1");
// 設(shè)置引腳為輸出方式
rt_pin_mode(Led.LED_R, PIN_MODE_OUTPUT);
rt_pin_mode(Led.LED_G, PIN_MODE_OUTPUT);
rt_pin_mode(Led.LED_B, PIN_MODE_OUTPUT);
rt_kprintf("rgb init success\n");
}
//傳入?yún)?shù) on=1:對應(yīng)亮,on=0:對應(yīng)滅
//紅燈驅(qū)動
void RGB_Red(rt_bool_t on)
{
rt_pin_write(Led.LED_G, PIN_HIGH);
rt_pin_write(Led.LED_B, PIN_HIGH);
if (on) {
rt_pin_write(Led.LED_R, PIN_LOW);
} else {
rt_pin_write(Led.LED_R, PIN_HIGH);
}
}
//藍(lán)燈驅(qū)動
void RGB_Blue(rt_bool_t on){
rt_pin_write(Led.LED_G, PIN_HIGH);
rt_pin_write(Led.LED_R, PIN_HIGH);
if (on) {
rt_pin_write(Led.LED_B, PIN_LOW);
} else {
rt_pin_write(Led.LED_B, PIN_HIGH);
}
}
//綠燈驅(qū)動
void RGB_Green(rt_bool_t on)
{
rt_pin_write(Led.LED_R, PIN_HIGH);
rt_pin_write(Led.LED_B, PIN_HIGH);
if (on) {
rt_pin_write(Led.LED_G, PIN_LOW);
} else {
rt_pin_write(Led.LED_G, PIN_HIGH);
}
}
下面要做的是使得led能夠循環(huán)工作。
void rgb_switch(void)
{
static uint8_t led_num = 0;
if(led_num == 0)
RGB_Red(1);
else if(led_num == 1)
RGB_Blue(1);
else if(led_num == 2)
RGB_Green(1);
led_num++;
if(led_num == 3)
led_num = 0;
}
操作系統(tǒng)入口函數(shù)
void rgb_thread_entry(void* p)
{
RGB_Init();
while(1)
{
rt_thread_mdelay(500);
rgb_switch();
}
}
//這個函數(shù)不太明白是做什么的,應(yīng)該是線程控制函數(shù),不知道哪里有相應(yīng)的教程可以看到
static int Thread_RGB(void)
{
rgb_thread = rt_thread_create("rgb", rgb_thread_entry, RT_NULL, 512, 10, 10);
if(rgb_thread == RT_NULL)
{
rt_kprintf("Thread_GRB Init ERROR");
return RT_ERROR;
}
rt_thread_startup(rgb_thread);
}
然后看到該同學(xué)還設(shè)置了key.h函數(shù)。
//rgb.h
/*
* Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2021-11-06 Administrator the first version
*/
#ifndef APPLICATIONS_RGB_H_
#define APPLICATIONS_RGB_H_
#endif /* APPLICATIONS_RGB_H_ */
不太明白為什么要做這個,是為了以后擴(kuò)展用?
修改主函數(shù)main.c
/*
* Copyright (c) 2020-2021, Bluetrum Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2020/12/10 greedyhao The first version
*/
/**
* Notice!
* All functions or data that are called during an interrupt need to be in RAM.
* You can do it the way exception_isr() does.
*/
#include
#include "board.h"
int main(void)
{
rt_kprintf("Hello, world\n");
while (1)
{
rt_thread_mdelay(500);
rt_thread_mdelay(500);
}
}
該同學(xué)把原來的按鍵控制刪掉后,給了兩個mdelay();不明白為什么要這樣寫。
3.執(zhí)行downloader
實現(xiàn)功能。
看完了這個學(xué)習(xí),感覺疑惑還是很多,
有關(guān)于系統(tǒng)本身的,也有關(guān)于這位同學(xué)的編寫代碼內(nèi)容的。可是獨學(xué)而無友,則孤陋而寡聞。
多向各位大佬學(xué)習(xí)。
爭取能夠看明白。
還有這個編輯界面不知道為什么無法直接在word中直接粘貼復(fù)制。
難道是需要排版才行?
ymf
-
電路
+關(guān)注
關(guān)注
173文章
6026瀏覽量
174940 -
操作系統(tǒng)
+關(guān)注
關(guān)注
37文章
7138瀏覽量
125477 -
中科藍(lán)訊
+關(guān)注
關(guān)注
9文章
61瀏覽量
10234
發(fā)布評論請先 登錄
【BPI-CanMV-K230D-Zero開發(fā)板體驗】+燈效控制與Python編程
RT-Thread支持STM32H723VG芯片嗎?
愛普生壓控晶振 VG7050CDN(X1G004861)在 5G 通信基站中的應(yīng)用
DS1265AB adi

DLPC300在使用5V 1A的電源線供電時,電源指示燈紅綠交替閃爍,是否說明存在故障?
【ELF 2學(xué)習(xí)板試用】命令行功能測試-shell腳本進(jìn)行IO控制-紅綠燈按鈕項目
【ELF 2學(xué)習(xí)板試用】命令行功能測試-shell腳本進(jìn)行IO控制-紅綠燈項目
mXT1296M1T-AT/mXT1296M1T-AB 1.1數(shù)據(jù)手冊

【干貨】性價比拉滿!HK32F407VG開發(fā)板介紹

負(fù)載管的閃爍噪聲和熱噪聲的區(qū)別
TSB41LV01至TSB41AB1過渡文件

【RA-Eco-RA0E1-32PIN-V1.0開發(fā)板試用】軟件驅(qū)動TFT屏幕
TINA-TI仿真,為什么VF1和VG1的波形不一樣?
機(jī)智云ESP8266開發(fā)板RGB彩燈控件

評論