当前位置:网站首页>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 !!!
边栏推荐
- Implementation of 10m multifunctional signal generator with FPGA
- (cvpr-2019) selective kernel network
- [the road of Exile - Chapter 6]
- Talk about possible problems when using transactions (@transactional)
- JetPack--Navigation实现页面跳转
- Mathematical modeling -- the laying of water pipes
- 12.< tag-动态规划和子序列, 子数组>lt.72. 编辑距离
- 【ONE·Data || 数组堆简单实现及其延伸】
- Comprehensive explanation of "search engine crawl"
- 数学建模——永冻土层上关于路基热传导问题
猜你喜欢
LeetCode 练习——剑指 Offer 45. 把数组排成最小的数
第十五天(VLAN相关知识)
JetPack--Navigation实现页面跳转
JS dom2 and dom3
基于 ICA 与 DL 的语音信号盲分离
Verilog procedure assignment statements: blocking & non blocking
(cvpr-2019) selective kernel network
LM13丨形态量化-动量周期分析
Mathematical modeling - location of police stations
Know that Chuangyu is listed in many fields of ccsip 2022 panorama
随机推荐
一文读懂Okaleido Tiger近期动态,挖掘背后价值与潜力
【ONE·Data || 链式二叉树】
[electronic components] zener diode
Anti crawler mechanism solution: JS code generates random strings locally
[public class preview]: application exploration of Kwai gpu/fpga/asic heterogeneous platform
Idea connection database
2022.7.27-----leetcode.592
iVX低代码平台系列详解 -- 概述篇(二)
Implementation of 10m multifunctional signal generator with FPGA
数学建模——自来水管道铺设问题
MySQL high performance optimization notes (including 578 pages of notes PDF document), collected
Type analysis of demultiplexer (demultiplexer)
Stonedb invites you to participate in the open source community monthly meeting!
QT source code analysis -- QObject (4)
“蔚来杯“2022牛客暑期多校训练营3,签到题CAJHF
How to crawl web pages with playwright?
[云原生]微服务架构是什么
druid. io index_ Realtime real-time query
分布式开发漫谈
【MySQL】sql给表起别名