当前位置:网站首页>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 !!!

边栏推荐
- 点击按钮,下滑到指定的位置
- JS dom2 and dom3
- FPGA实现10M多功能信号发生器
- 一文读懂Okaleido Tiger近期动态,挖掘背后价值与潜力
- [the road of Exile - Chapter 7]
- [circuit design] peak voltage and surge current
- 关于字符串处理的相关函数记录(长期更新)
- 基于 ICA 与 DL 的语音信号盲分离
- LeetCode 练习——剑指 Offer 45. 把数组排成最小的数
- [electronic components] constant voltage, amplify the current of the load (triode knowledge summary)
猜你喜欢

MotionLayout--在可视化编辑器中实现动画

弹性布局 单选

Stonedb invites you to participate in the open source community monthly meeting!

(arxiv-2018) 重新审视基于视频的 Person ReID 的时间建模

What is the function of data parsing?
![[the road of Exile - Chapter 8]](/img/df/a801da27f5064a1729be326c4167fe.png)
[the road of Exile - Chapter 8]

ciscn 2022 华中赛区 misc

Wonderful use of data analysis
![[10:00 public class]: application exploration of Kwai gpu/fpga/asic heterogeneous platform](/img/e7/1d06eba0e50eeb91d2d5da7524f4af.png)
[10:00 public class]: application exploration of Kwai gpu/fpga/asic heterogeneous platform

基于 ICA 与 DL 的语音信号盲分离
随机推荐
Force deduction brush question (1): sum of two numbers
Implementation of 10m multifunctional signal generator with FPGA
一文读懂Okaleido Tiger近期动态,挖掘背后价值与潜力
数学建模——永冻土层上关于路基热传导问题
Complete collection of common error handling in MySQL installation
Cookie和Session
Jetpack--了解ViewModel和LiveData的使用
How to prevent all kinds of affiliated fraud?
Stonedb invites you to participate in the open source community monthly meeting!
Comprehensive explanation of "search engine crawl"
2022年编程语言排名,官方数据来了,让人大开眼界
The solution of reducing the sharpness of pictures after inserting into word documents
Click the button to slide to the specified position
移动通信——基于卷积码的差错控制系统仿真模型
Lxml web page capture the most complete strategy
【ONE·Data || 数组堆简单实现及其延伸】
Anti crawler mechanism solution: JS code generates random strings locally
The number of consecutive subarrays whose leetcode/ product is less than k
(arxiv-2018) reexamine the time modeling of person Reid based on video
使用本地缓存+全局缓存实现小型系统用户权限管理