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

边栏推荐
- Sharpness evaluation method without reference image
- How to write, load and unload plug-ins in QT
- Complete collection of common error handling in MySQL installation
- Leetcode 242. valid anagram
- 分布式开发漫谈
- Control the pop-up window and no pop-up window of the input box
- mobile-picker.js
- (cvpr-2019) selective kernel network
- MySQL stores JSON format data
- 全志T3/A40i工业核心板,4核[email protected],国产化率达100%
猜你喜欢

druid. io kill -9 index_ Realtime traceability task

LeetCode 练习——剑指 Offer 45. 把数组排成最小的数

(arxiv-2018) reexamine the time modeling of person Reid based on video

How companies make business decisions -- with the help of data-driven marketing

Force deduction brush question (2): sum of three numbers

Navigation--实现Fragment之间数据传递和数据共享

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

Why can't Bi software do correlation analysis

Introduction to shared data center agent

数学建模——永冻土层上关于路基热传导问题
随机推荐
QT memory management tips
Qt 内存管理小技巧
Semiconductor chip industry chain
In 2022, the official data of programming language ranking came, which was an eye opener
Secret skill winter tide branding skill matching
2022年编程语言排名,官方数据来了,让人大开眼界
Promise solves asynchrony
Click back to the top JS
“蔚来杯“2022牛客暑期多校训练营3,签到题CAJHF
Probability Density Reweight
Lxml web page capture the most complete strategy
Related function records about string processing (long-term update)
How to write, load and unload plug-ins in QT
Mathematical modeling -- heat conduction of subgrade on Permafrost
Talk about possible problems when using transactions (@transactional)
费曼学习法(符号表)
Try to understand the essence of low code platform design from another angle
Comprehensive analysis of news capture doorway
数学建模——公交调度优化
Promise解决异步