日本黄色一级经典视频|伊人久久精品视频|亚洲黄色色周成人视频九九九|av免费网址黄色小短片|黄色Av无码亚洲成年人|亚洲1区2区3区无码|真人黄片免费观看|无码一级小说欧美日免费三级|日韩中文字幕91在线看|精品久久久无码中文字幕边打电话

當(dāng)前位置:首頁(yè) > 單片機(jī) > 單片機(jī)
[導(dǎo)讀] 在實(shí)際的項(xiàng)目開(kāi)發(fā)過(guò)程中,常常會(huì)遇到硬件電路的修改,然后修改的部分就需要修改驅(qū)動(dòng)程序。想這樣需求該來(lái)該去是程序員們最煩悶的事情(重復(fù)勞動(dòng)痛不欲生啊~)。為了避免或減少重復(fù)勞動(dòng),就需要在程序的

在實(shí)際的項(xiàng)目開(kāi)發(fā)過(guò)程中,常常會(huì)遇到硬件電路的修改,然后修改的部分就需要修改驅(qū)動(dòng)程序。想這樣需求該來(lái)該去是程序員們最煩悶的事情(重復(fù)勞動(dòng)痛不欲生啊~)。為了避免或減少重復(fù)勞動(dòng),就需要在程序的架構(gòu)上下功夫。接下來(lái)以最常見(jiàn)的LED驅(qū)動(dòng)程序?yàn)槔M(jìn)行程序結(jié)構(gòu)設(shè)計(jì)。


1,開(kāi)發(fā)環(huán)境

1,固件庫(kù):STM32F4xx_DSP_StdPeriph_Lib_V1.8.0

2,編譯器:ARMCC V5.06

3,IDE:Keil uVision5

4,操作系統(tǒng):Windows 10 專(zhuān)業(yè)版


2,程序源碼

LED.h文件

/**

******************************************************************************

* @file LED.h

* @author XinLi

* @version v1.0

* @date 24-October-2017

* @brief Header file for LED.c module.

******************************************************************************

* @attention

*

*

Copyright © 2017 XinLi

*

* This program is free software: you can redistribute it and/or modify

* it under the terms of the GNU General Public License as published by

* the Free Software Foundation, either version 3 of the License, or

* (at your option) any later version.

*

* This program is distributed in the hope that it will be useful,

* but WITHOUT ANY WARRANTY; without even the implied warranty of

* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the

* GNU General Public License for more details.

*

* You should have received a copy of the GNU General Public License

* along with this program. If not, see .

*

******************************************************************************

*/

#ifndef __LED_H

#define __LED_H

#ifdef __cplusplus

extern "C" {

#endif

/* Header includes -----------------------------------------------------------*/

#include "stm32f4xx.h"

/* Macro definitions ---------------------------------------------------------*/

#define LEDn (4)

#define LED1_RCC_AHB1Periph_GPIO RCC_AHB1Periph_GPIOC

#define LED1_GPIO GPIOC

#define LED1_GPIO_Pin GPIO_Pin_0

#define LED2_RCC_AHB1Periph_GPIO RCC_AHB1Periph_GPIOC

#define LED2_GPIO GPIOC

#define LED2_GPIO_Pin GPIO_Pin_1

#define LED3_RCC_AHB1Periph_GPIO RCC_AHB1Periph_GPIOB

#define LED3_GPIO GPIOB

#define LED3_GPIO_Pin GPIO_Pin_3

#define LED4_RCC_AHB1Periph_GPIO RCC_AHB1Periph_GPIOB

#define LED4_GPIO GPIOB

#define LED4_GPIO_Pin GPIO_Pin_4

/* Type definitions ----------------------------------------------------------*/

typedef enum

{

LED_Pin1 = 0,

LED_Pin2 = 1,

LED_Pin3 = 2,

LED_Pin4 = 3

}LED_Pin;

typedef enum

{

LED_Off = 0,

LED_On = 1

}LED_Status;

/* Variable declarations -----------------------------------------------------*/

/* Variable definitions ------------------------------------------------------*/

/* Function declarations -----------------------------------------------------*/

void LED_SetStatus(LED_Pin pin, LED_Status status);

LED_Status LED_GetStatus(LED_Pin pin);

/* Function definitions ------------------------------------------------------*/

#ifdef __cplusplus

}

#endif

#endif /* __LED_H */


LED.c文件

/**

******************************************************************************

* @file LED.c

* @author XinLi

* @version v1.0

* @date 24-October-2017

* @brief LED module driver.

******************************************************************************

* @attention

*

*

Copyright © 2017 XinLi

*

* This program is free software: you can redistribute it and/or modify

* it under the terms of the GNU General Public License as published by

* the Free Software Foundation, either version 3 of the License, or

* (at your option) any later version.

*

* This program is distributed in the hope that it will be useful,

* but WITHOUT ANY WARRANTY; without even the implied warranty of

* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the

* GNU General Public License for more details.

*

* You should have received a copy of the GNU General Public License

* along with this program. If not, see .

*

******************************************************************************

*/

/* Header includes -----------------------------------------------------------*/

#include "LED.h"

#include

/* Macro definitions ---------------------------------------------------------*/

/* Type definitions ----------------------------------------------------------*/

/* Variable declarations -----------------------------------------------------*/

/* Variable definitions ------------------------------------------------------*/

static GPIO_TypeDef *LED_GPIO[LEDn] = {LED1_GPIO, LED2_GPIO, LED3_GPIO, LED4_GPIO};

static uint16_t LED_GPIO_Pin[LEDn] = {LED1_GPIO_Pin, LED2_GPIO_Pin, LED3_GPIO_Pin, LED4_GPIO_Pin};

static uint32_t LED_RCC_AHB1Periph_GPIO[LEDn] = {LED1_RCC_AHB1Periph_GPIO, LED2_RCC_AHB1Periph_GPIO, LED3_RCC_AHB1Periph_GPIO, LED4_RCC_AHB1Periph_GPIO};

static __IO LED_Status ledStatus[LEDn] = {LED_Off, LED_Off, LED_Off, LED_Off};

/* Function declarations -----------------------------------------------------*/

static void LED_Init(void);

/* Function definitions ------------------------------------------------------*/

/**

* @brief Led initializes.

* @param None.

* @return None.

*/

static void LED_Init(void)

{

static bool init_flag = false;

if(init_flag == false)

{

init_flag = true;

for(int i = 0; i < LEDn; i++)

{

GPIO_InitTypeDef GPIO_InitStructure = {0};

RCC_AHB1PeriphClockCmd(LED_RCC_AHB1Periph_GPIO[i], ENABLE);

GPIO_InitStructure.GPIO_Pin = LED_GPIO_Pin[i];

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;

GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;

GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;

GPIO_Init(LED_GPIO[i], &GPIO_InitStructure);

GPIO_WriteBit(LED_GPIO[i], LED_GPIO_Pin[i], (BitAction)LED_Off);

}

}

}

/**

* @brief Set led status.

* @param [in] pin: That led.

* @param [in] status: Led status.

* @return None.

*/

void LED_SetStatus(LED_Pin pin, LED_Status status)

{

if(status != ledStatus[pin])

{

ledStatus[pin] = status;

LED_Init();

GPIO_WriteBit(LED_GPIO[pin], LED_GPIO_Pin[pin], (BitAction)status);

}

}

/**

* @brief Get led status.

* @param [in] pin: That led.

* @return Led status.

*/

LED_Status LED_GetStatus(LED_Pin pin)

{

return ledStatus[pin];

}


main.c文件

/**

******************************************************************************

* @file main.c

* @author XinLi

* @version v1.0

* @date 24-October-2017

* @brief Main program body.

***************************

本站聲明: 本文章由作者或相關(guān)機(jī)構(gòu)授權(quán)發(fā)布,目的在于傳遞更多信息,并不代表本站贊同其觀點(diǎn),本站亦不保證或承諾內(nèi)容真實(shí)性等。需要轉(zhuǎn)載請(qǐng)聯(lián)系該專(zhuān)欄作者,如若文章內(nèi)容侵犯您的權(quán)益,請(qǐng)及時(shí)聯(lián)系本站刪除( 郵箱:macysun@21ic.com )。
換一批
延伸閱讀

廈門(mén)2026年3月27日 /美通社/ -- 當(dāng)前,全球Mini/Micro LED產(chǎn)業(yè)正邁入產(chǎn)業(yè)化爆發(fā)的黃金周期,新型顯示技術(shù)加速重構(gòu)全球產(chǎn)業(yè)格局、重塑行業(yè)競(jìng)爭(zhēng)秩序。三安光電湖北有限公司作為公司布局Mini/M...

關(guān)鍵字: LED MICRO 三安光電 NI

這款節(jié)省空間的器件在 5 mA電流下可提供高達(dá) 252 mcd 的發(fā)光強(qiáng)度, 能夠呈現(xiàn)CIE 1931色域內(nèi)色域三角形中的每一種顏色

關(guān)鍵字: 芯片 RGB LED

中國(guó) 上海,2026年3月25日——照明與傳感創(chuàng)新的全球領(lǐng)導(dǎo)者艾邁斯歐司朗(SIX:AMS)今日亮相2026第二十一屆汽車(chē)燈具產(chǎn)業(yè)發(fā)展技術(shù)論壇暨上海國(guó)際汽車(chē)燈具展覽會(huì)(ALE)。本屆ALE以“光馭未來(lái):智能、綠色與安全的...

關(guān)鍵字: 智能前照燈 LED

March 4, 2026 ---- 根據(jù)TrendForce集邦咨詢(xún)最新調(diào)查,隨著生成式AI興起,數(shù)據(jù)中心對(duì)高速傳輸?shù)男枨蟪掷m(xù)提升,原先應(yīng)用在機(jī)柜內(nèi)(Intra-Rack)短距傳輸?shù)你~纜方案,將在傳輸密度與節(jié)能上面臨嚴(yán)...

關(guān)鍵字: 數(shù)據(jù)中心 生成式AI LED

奧地利Premst?tten /德國(guó)慕尼黑(2026年2月24日)——艾邁斯歐司朗(SIX: AMS)與深圳市美志光電技術(shù)有限公司(以下簡(jiǎn)稱(chēng)“美志光電”)就其在美國(guó)與德國(guó)市場(chǎng)未決的LED專(zhuān)利糾紛達(dá)成和解。

關(guān)鍵字: LED 發(fā)射器

Feb. 24, 2026 ---- 根據(jù)TrendForce集邦咨詢(xún)最新UV LED市場(chǎng)趨勢(shì)與產(chǎn)品分析,由于貴金屬、原物料與人工費(fèi)用調(diào)漲,2026年第一季UV LED價(jià)格獲得支撐,客制化產(chǎn)品甚至有機(jī)會(huì)季增5%。在全球光...

關(guān)鍵字: LED 太陽(yáng)光源模擬器

光耦合器對(duì)開(kāi)關(guān)電源(SMPS)設(shè)計(jì)至關(guān)重要,它使得信號(hào)能夠安全、可靠地跨越電氣隔離邊界傳輸。而光耦合器的性能取決于適當(dāng)?shù)钠眉霸诜答伩刂骗h(huán)路內(nèi)的正確集成;配置錯(cuò)誤會(huì)導(dǎo)致不穩(wěn)定、瞬態(tài)響應(yīng)不佳和調(diào)節(jié)性能下降。本文分為兩部分,...

關(guān)鍵字: 光耦合器 開(kāi)關(guān)電源 LED

隨著汽車(chē)向移動(dòng)智能終端演進(jìn),車(chē)內(nèi)座艙體驗(yàn)成為競(jìng)爭(zhēng)焦點(diǎn)。動(dòng)態(tài)流水氛圍燈作為提升科技感與個(gè)性化體驗(yàn)的關(guān)鍵配置,正從中高端車(chē)型快速滲透至更廣泛的車(chē)型市場(chǎng)。在這一趨勢(shì)下,如何在強(qiáng)化視覺(jué)交互的同時(shí)控制成本,成為產(chǎn)業(yè)鏈共同面對(duì)的核心...

關(guān)鍵字: 動(dòng)態(tài)氛圍燈 驅(qū)動(dòng)芯片 LED

這個(gè)項(xiàng)目是為我物理計(jì)算課程中的數(shù)據(jù)可視化項(xiàng)目而設(shè)計(jì)的。其核心理念是通過(guò) LED 燈帶來(lái)展示飛機(jī)在天空中的位置,每盞 LED 燈都代表著一個(gè)位置。這些燈光會(huì)隨著飛機(jī)的活動(dòng)而移動(dòng)并改變顏色。

關(guān)鍵字: LED REST API 樹(shù)莓派 繼電器

該項(xiàng)目展示了在基于 FreeRTOS 的系統(tǒng)(運(yùn)行于 Arduino Uno 上)中實(shí)現(xiàn)安全的數(shù)據(jù)共享訪問(wèn)的實(shí)現(xiàn)方式。

關(guān)鍵字: LED ADC 數(shù)據(jù) Arduino
關(guān)閉