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

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

在實際的項目開發(fā)過程中,常常會遇到硬件電路的修改,然后修改的部分就需要修改驅(qū)動程序。想這樣需求該來該去是程序員們最煩悶的事情(重復勞動痛不欲生啊~)。為了避免或減少重復勞動,就需要在程序的架構(gòu)上下功夫。接下來以最常見的無源蜂鳴器驅(qū)動程序為例,進行程序結(jié)構(gòu)設(shè)計。



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

1,固件庫:STM32F4xx_DSP_StdPeriph_Lib_V1.8.0

2,編譯器:ARMCC V5.06

3,IDE:Keil uVision5

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



2,程序源碼

BUZZ.h文件

/**

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

* @file BUZZ.h

* @author XinLi

* @version v1.0

* @date 24-October-2017

* @brief Header file for BUZZ.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 __BUZZ_H

#define __BUZZ_H

#ifdef __cplusplus

extern "C" {

#endif

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

#include "stm32f4xx.h"

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

#define BUZZ_RCC_AHB1Periph_GPIO RCC_AHB1Periph_GPIOB

#define BUZZ_GPIO GPIOB

#define BUZZ_GPIO_Pin GPIO_Pin_8

#define BUZZ_GPIO_PinSource GPIO_PinSource8

#define BUZZ_GPIO_AF_TIM GPIO_AF_TIM4

#define BUZZ_RCC_APB1Periph_TIM RCC_APB1Periph_TIM4

#define BUZZ_TIM TIM4

#define BUZZ_TIM_Prescaler (83) /*!< Clock divided to 1MHz. */

#define BUZZ_TIM_Period (249) /*!< 250us timer interrupt. */

#define BUZZ_TIM_OCPolarity TIM_OCPolarity_High

#define BUZZ_TIM_OCInit TIM_OC3Init

#define BUZZ_TIM_OCPreloadConfig TIM_OC3PreloadConfig

#define BUZZ_TIM_SetCompare TIM_SetCompare3

#define BUZZ_TIM_IRQn TIM4_IRQn

#define BUZZ_TIM_IRQHandler TIM4_IRQHandler

#define BUZZ_TIM_IRQ_PreemptionPriority (0)

#define BUZZ_TIM_IRQ_SubPriority (0)

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

typedef enum

{

BUZZ_Off = 0,

BUZZ_Ring = 1,

BUZZ_Drip = 2,

BUZZ_Warning = 3,

BUZZ_Danger = 4

}BUZZ_Status;

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

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

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

void BUZZ_SetStatus(BUZZ_Status status);

BUZZ_Status BUZZ_GetStatus(void);

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

#ifdef __cplusplus

}

#endif

#endif /* __BUZZ_H */


BUZZ.c文件

/**

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

* @file BUZZ.c

* @author XinLi

* @version v1.0

* @date 24-October-2017

* @brief BUZZ 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 "BUZZ.h"

#include

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

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

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

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

static __IO BUZZ_Status buzzStatus = BUZZ_Off;

static __IO int buzzCount = 0;

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

static void BUZZ_PwmInit(void);

static void BUZZ_NvicInit(void);

static void BUZZ_Init(void);

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

/**

* @brief Buzz pwm initializes.

* @param None.

* @return None.

*/

static void BUZZ_PwmInit(void)

{

GPIO_InitTypeDef GPIO_InitStructure = {0};

TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure = {0};

TIM_OCInitTypeDef TIM_OCInitStructure = {0};

RCC_AHB1PeriphClockCmd(BUZZ_RCC_AHB1Periph_GPIO, ENABLE);

RCC_APB1PeriphClockCmd(BUZZ_RCC_APB1Periph_TIM, ENABLE);

GPIO_InitStructure.GPIO_Pin = BUZZ_GPIO_Pin;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;

GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;

GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;

GPIO_Init(BUZZ_GPIO, &GPIO_InitStructure);

GPIO_PinAFConfig(BUZZ_GPIO, BUZZ_GPIO_PinSource, BUZZ_GPIO_AF_TIM);

TIM_TimeBaseStructure.TIM_Prescaler = BUZZ_TIM_Prescaler;

TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;

TIM_TimeBaseStructure.TIM_Period = BUZZ_TIM_Period;

TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;

TIM_TimeBaseInit(BUZZ_TIM, &TIM_TimeBaseStructure);

TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;

TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;

TIM_OCInitStructure.TIM_Pulse = 0;

TIM_OCInitStructure.TIM_OCPolarity = BUZZ_TIM_OCPolarity;

BUZZ_TIM_OCInit(BUZZ_TIM, &TIM_OCInitStructure);

BUZZ_TIM_OCPreloadConfig(BUZZ_TIM, TIM_OCPreload_Enable);

TIM_ARRPreloadConfig(BUZZ_TIM, ENABLE);

TIM_ITConfig(BUZZ_TIM, TIM_IT_Update, ENABLE);

TIM_Cmd(BUZZ_TIM, ENABLE);

}

/**

* @brief Buzz nvic initializes.

* @param None.

* @return None.

*/

static void BUZZ_NvicInit(void)

{

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

Sept. 10, 2025 ---- 根據(jù)TrendForce集邦咨詢最新發(fā)布的《全球電動車逆變器市場數(shù)據(jù)》,2025年第二季受惠純電動車(BEV)銷售成長,全球電動車(注1)牽引逆變器裝機量達766萬臺,年增19%。...

關(guān)鍵字: 增程式電動車 SiC 牽引逆變器

Sept. 8, 2025 ---- 根據(jù)TrendForce集邦咨詢最新調(diào)查,2025年第二季NVIDIA(英偉達) Blackwell平臺規(guī)?;鲐?,以及北美CSP業(yè)者持續(xù)擴大布局General Server(通用型...

關(guān)鍵字: SSD DDR4 服務(wù)器

Sept. 4, 2025 ---- Apple(蘋果)即將發(fā)布iPhone 17、iPhone 17 Air(暫名)、iPhone 17 Pro及Pro Max四款旗艦新機,除了外觀辨識度升級,處理器性能、散熱和拍攝功...

關(guān)鍵字: iPhone 16 A19處理器 折疊機

Sept. 3, 2025 ---- 根據(jù)TrendForce集邦咨詢最新發(fā)布的《2025近眼顯示市場趨勢與技術(shù)分析》報告,2025年隨著國際品牌陸續(xù)推出AR眼鏡原型,以及Meta預計在近期發(fā)布AR眼鏡Celeste,市...

關(guān)鍵字: AR眼鏡 OLED

Sept. 2, 2025 ---- TrendForce集邦咨詢表示,2025年第二季DRAM產(chǎn)業(yè)因一般型DRAM (Conventional DRAM)合約價上漲、出貨量顯著增長,加上HBM出貨規(guī)模擴張,整體營收為3...

關(guān)鍵字: DRAM 智能手機 ASP

Sept. 1, 2025 ---- 根據(jù)TrendForce集邦咨詢最新調(diào)查,2025年第二季因中國市場消費補貼引發(fā)的提前備貨效應,以及下半年智能手機、筆電/PC、Server新品所需帶動,整體晶圓代工產(chǎn)能利用率與出貨...

關(guān)鍵字: 晶圓代工 智能手機 筆電

Aug. 28, 2025 ---- 根據(jù)TrendForce集邦咨詢最新調(diào)查,2025年第二季NAND Flash產(chǎn)業(yè)雖面臨平均銷售價格(ASP)小幅下滑,所幸原廠減產(chǎn)策略緩解供需失衡,疊加中、美兩大市場政策推動,整體...

關(guān)鍵字: NAND Flash SSD AI

Aug. 26, 2025 ---- NVIDIA(英偉達)近日推出的Jetson Thor被視為機器人的物理智慧核心,以Blackwell GPU、128 GB記憶體堆疊出2070 FP4 TFLOPS AI算力,是前...

關(guān)鍵字: 機器人 大型語言模型 AI算力

Aug. 21, 2025 ---- 根據(jù)TrendForce集邦咨詢最新液冷產(chǎn)業(yè)研究,隨著NVIDIA GB200 NVL72機柜式服務(wù)器于2025年放量出貨,云端業(yè)者加速升級AI數(shù)據(jù)中心架構(gòu),促使液冷技術(shù)從早期試點邁...

關(guān)鍵字: AI 數(shù)據(jù)中心 服務(wù)器

除了充電電路外,鋰電池的放電過程也需要保護。鋰電池的放電電壓不能低于3.0V,否則電池壽命會大幅縮短。為了實現(xiàn)這一保護,工程師們設(shè)計了DW01芯片與8205 MOS管的電路組合。DW01芯片能夠監(jiān)控鋰電池的放電電壓和電流...

關(guān)鍵字: 鋰電池 電池
關(guān)閉