当前位置:网站首页>Control buzzer based on C51
Control buzzer based on C51
2022-07-29 02:12:00 【Miaowu】
Preface : This experiment is based on STC89C52RC Single chip microcomputer , Program and control the buzzer according to the circuit schematic . because 51 The structure of Series MCU is similar , Readers can draw inferences from this blog , Realize the required functions .
Catalog :
The single chip microcomputer selected in the experiment and its structure are displayed ( In general C51 For example , The others are similar ), The buzzer operated in this experiment is located in the serial number ⑱ Location

One 、 Buzzer Introduction
Buzzer can be divided into Active buzzer ( Including drive line ) and Passive buzzer ( External drive ). Active and passive , It doesn't mean power , It refers to whether there is an oscillation circuit inside the buzzer , Internal oscillation circuit of active buzzer , Just provide power to sound ; The passive buzzer needs to provide a certain frequency pulse signal to sound , The frequency is usually at 1.5-5KHZ Between , The physical drawing of buzzer is shown in the figure below :

Distinguish between active and passive buzzers : Place the pins of the two buzzers upward , One with a green circuit board is a passive buzzer , What is closed with black glue without circuit board is an active buzzer
For passive buzzers , If you change the frequency, you can adjust the buzzer tone , Produce a variety of different timbres 、 The sound of tone . If you change the high and low level duty cycle of the output level , You can change the sound level of the buzzer
Two 、 Circuit schematic analysis
For this experiment, we should realize the control of buzzer , We can't use SCM directly IO Mouth drive . because 51 Single chip microcomputer IO The driving ability of the port is weak ( Even if the external pull-up resistor ), The buzzer drive takes about 30mA, So it's very difficult . The buzzer module circuit on the development version used in this experiment is shown in the figure below :

51 SCM is mainly used to control rather than drive , Using chips directly GPIO Pins to drive high-power devices , Or burn the chip , Or it won't drive . So drive high-power devices , It is necessary to build the driving circuit , The driver chip on the development board is ULN2003D. It can be seen from the above figure ,ULN2003D Control the input port of the buzzer and the P2.5 Connect , The corresponding output is OUT5. adopt ULN2003D,GPIO The pin can control the buzzer .
The buzzer used in this experiment is a passive buzzer , To make it sound , You need to input the pulse of the specified frequency , High and low levels
3、 ... and 、 Realize buzzer ringing
To realize the sounding of passive buzzer , It is necessary to input a pulse signal with a specified frequency to the buzzer , The designated frequency of the passive buzzer is 1.5-5KHZ, Then the period is 0.2ms-66.6ms. That is, every 0.2ms-66.6ms Turn the high and low levels inside once to control the buzzer to sound .

Based on the above analysis , It is easy to program and control the buzzer to sound
/*************************************************************************************
* Name of the experiment : Buzzer experiment
* Experimental phenomena : The buzzer sounds after downloading the program , Close after a period of time
***************************************************************************************/
#include "reg52.h"
typedef unsigned int u16; // Redefine the default data type of the system
typedef unsigned char u8;
sbit BEEP=P2^5; // take P2.5 Pins are defined as BEEP
/*******************************************************************************
* Function name : delay_10us
* The functionality : The time delay function ,ten_us=1 when , About time delay 10us
*******************************************************************************/
void delay_10us(u16 ten_us)
{
while(ten_us--);
}
void main()
{
u16 i=2000;
while(1)
{
while(i--)// loop 2000 Time
{
BEEP=!BEEP;// Generate a pulse signal of a certain frequency ,1ms Flip once
delay_10us(100);
}
i=0;// Zero clearing
BEEP=0;// Turn off the buzzer
}
}
Thank you for watching. , If you have doubts or supplements about the content , Feel free to leave a comment , Common progress !!!

边栏推荐
- Leetcode exercise - Sword finger offer 45. arrange the array into the smallest number
- H5 background music is played automatically by touch
- Navigation--实现Fragment之间数据传递和数据共享
- Dynamic memory and smart pointer
- h5背景音乐通过触摸自动播放
- 12.< tag-动态规划和子序列, 子数组>lt.72. 编辑距离
- Mathematical modeling -- heat conduction of subgrade on Permafrost
- 数学建模——仓内拣货优化问题
- Opencv image sharpness evaluation (camera autofocus)
- 为什么 BI 软件都搞不定关联分析
猜你喜欢

Detailed explanation of IVX low code platform series -- Overview (II)

Mathematical modeling - location of police stations
![[the road of Exile - Chapter 5]](/img/ef/7ecc1cb4a95c613f7be91f7acc761c.png)
[the road of Exile - Chapter 5]
![[public class preview]: application exploration of Kwai gpu/fpga/asic heterogeneous platform](/img/e7/1d06eba0e50eeb91d2d5da7524f4af.png)
[public class preview]: application exploration of Kwai gpu/fpga/asic heterogeneous platform

FPGA实现10M多功能信号发生器

Solution of Lenovo notebook camera unable to open

2022年编程语言排名,官方数据来了,让人大开眼界

Why does stonedb dare to call it the only open source MySQL native HTAP database in the industry?

Mathematical modeling -- Optimization of picking in warehouse

Mathematical modeling -- cold proof simulation of low temperature protective clothing with phase change materials
随机推荐
Leetcode/ and continuous shortest subarray greater than or equal to target
JVM内存溢出在线分析Dump文件以及在线分析打开.hprof文件得出JVM运行报告jvisualvm怎么在线分析
How to prevent all kinds of affiliated fraud?
2022.7.27-----leetcode.592
What is the function of data parsing?
“蔚来杯“2022牛客暑期多校训练营3,签到题CAJHF
费曼学习法(符号表)
Jetpack--了解ViewModel和LiveData的使用
表单校验 隐藏的输入框 显示才校验
Leetcode exercise - Sword finger offer 45. arrange the array into the smallest number
12.< tag-动态规划和子序列, 子数组>lt.72. 编辑距离
在Qt中如何编写插件,加载插件和卸载插件
Basic working principle and LTSpice simulation of 6T SRAM
【ONE·Data || 链式二叉树】
为什么 BI 软件都搞不定关联分析
[electronic components] zener diode
mobile-picker.js
Click back to the top JS
Understand the working principle of timer in STM32 in simple terms
QT source code analysis -- QObject (4)