当前位置:网站首页>Buzzer experiment based on stm32f103zet6 library function
Buzzer experiment based on stm32f103zet6 library function
2022-06-27 19:18:00 【It's Beichen bupiacra】
be based on STM32F103ZET6 Library function buzzer experiment
Buzzer
type
elite STM32 The buzzer on the development board is an electromagnetic active buzzer .
Passive
The active power here doesn't refer to the power supply “ Source ”, It's about whether there's a self oscillating circuit , The active buzzer has its own oscillation circuit , It will be electrified ; The passive buzzer does not have its own oscillation circuit , It has to be provided externally 2~5Khz Right and left square wave drive , To make a sound .
Driving mode
We don't have to STM32 Of IO Direct drive buzzer , It is Drive the buzzer after current expansion through triode
Hardware design
Schematic diagram
The driving signal of the buzzer is connected to STM32 Of PB8 On 
In the picture we use a NPN triode (S8050) To drive the buzzer ,R33 It is mainly used to prevent the buzzer from misfiring The sound . When PB.8 When the output is high , The buzzer will sound , When PB.8 When the output is low , The buzzer stops .

stay BEEP A very small current is input through the amplification of the triode , Make the end connected to the buzzer output the amplified current , Can make the buzzer ring
software design
beep.c
#include "beep.h"
void BEEP_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE); // Can make GPIOB Port clock
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8; //BEEP-->GPIOB.8 port configuration
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; // Push pull output
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; // Speed is 50MHz
GPIO_Init(GPIOB, &GPIO_InitStructure); // Initialization according to parameters GPIOB.8
GPIO_ResetBits(GPIOB,GPIO_Pin_8);// Output 0, Turn off the buzzer output
}
The design here is mainly to set GPIO and LED The configuration of is roughly the same
beep.h
#ifndef __BEEP_H
#define __BEEP_H
#include "sys.h" // Buzzer port definition
#define BEEP PBout(8) // BEEP, Buzzer interface
void BEEP_Init(void); // initialization
#endif
Here, a bit band operation is used to realize a certain IO Port output control ,BEEP On behalf of Watch PB8 The output state of . We just need to make BEEP=1, You can make the buzzer sound
main.c
#include "sys.h"
#include "delay.h"
#include "led.h"
#include "beep.h"
int main(void)
{
delay_init(); // Delay function initialization
LED_Init(); // Initialization and LED Connected hardware interface
BEEP_Init(); // Initialize the buzzer port
while(1)
{
LED0=0;
BEEP=0;
delay_ms(300);
LED0=1;
BEEP=1;
delay_ms(300);
}
}
边栏推荐
- International School of Digital Economics, South China Institute of technology 𞓜 unified Bert for few shot natural language understanding
- MongoDB和MySQL的区别
- Market status and development prospect forecast of global 3-Chloro-1,2-Propanediol industry in 2022
- Current market situation and development prospect forecast of global 3,3 ', 4,4' - biphenyltetracarboxylic dianhydride industry in 2022
- Technology sharing | introduction to kubernetes pod
- 【建议收藏】ABAP随笔-EXCEL-4-批量导入-推荐
- Application of tdengine in monitoring of CNC machine tools
- What is ICMP? What is the relationship between Ping and ICMP?
- 云原生数据库:数据库的风口,你也可以起飞
- TIA博途_基于SCL语言制作模拟量输入输出全局库的具体方法
猜你喜欢
随机推荐
“我让这个世界更酷”2022华清远见研发产品发布会圆满成功
China's Industrial Software Market Research Report is released, and SCADA and MES of force control enrich the ecology of domestic industrial software
通过 G1 GC Log 重新认识 G1 垃圾回收器
Market status and development prospect forecast of phenethyl resorcinol for skin care industry in the world in 2022
实施MES管理系统前,要对哪些问题进行评估
OpenSSL client programming: SSL session failure caused by an obscure function
CMS 执行的七个阶段
The difficulty of realizing time series database "far surpassing" general database in specific scenarios
Market status and development prospect of resorcinol derivatives for skin products in the world in 2022
Industry university cooperation cooperates to educate people, and Kirin software cooperates with Nankai University to complete the practical course of software testing and maintenance
Market status and development prospect forecast of global active quality control air sampler industry in 2022
[elt.zip] openharmony paper Club - witness file compression system erofs
Market status and development prospect forecast of the global infusion needle less connector industry in 2022
一种朴素的消失点计算方法
CDGA|交通行业做好数字化转型的核心是什么?
TIA博途_基于SCL语言制作模拟量输入输出全局库的具体方法
图扑数字孪生智慧能源一体化管控平台
Technology sharing | introduction to kubernetes pod
MySQL数据库登录和退出的两种方式
Market status and development prospect forecast of global epoxy resin active toughener industry in 2022








