📄 蜂鸣器原理及应用.htm
字号:
src="蜂鸣器原理及应用.files/fmq4.gif" width=328 border=0></A></TD>
<TD vAlign=top width="2%">
<DIV align=center>
<P> </P></DIV></TD></TR>
<TR>
<TD vAlign=top> </TD>
<TD vAlign=top>
<DIV align=center><SPAN class=style128>图 3
</SPAN></DIV></TD>
<TD vAlign=top> </TD></TR></TBODY></TABLE>
<DIV align=justify><BR> <SPAN
class=style125> </SPAN>如图所示,蜂鸣器的正极接到VCC(+5V)电源上面,蜂鸣器的负极接到三极管的发射极E,三极管的基级B经过限流电阻R1后由单片机的P3.7引脚控制,当P3.7输出高电平时,三极管T1截止,没有电流流过线圈,蜂鸣器不发声;当P3.7输出低电平时,三极管导通,这样蜂鸣器的电流形成回路,发出声音。因此,我们可以通过程序控制P3.7脚的电平来使蜂鸣器发出声音和关闭。<BR><BR> <SPAN
class=style125> </SPAN>程序中改变单片机P3.7引脚输出波形的频率,就可以调整控制蜂鸣器音调,产生各种不同音色、音调的声音。另外,改变P3.7输出电平的高低电平占空比,则可以控制蜂鸣器的声音大小,这些我们都可以通过编程实验来验证。<BR><BR><BR> <SPAN
class=style125> <SPAN
class=style141>二、蜂鸣器的实验例程</SPAN></SPAN></DIV>
<P align=left> <SPAN
class=style125> </SPAN>下面我们通过几个实验例程来学习蜂鸣器的编程使用,通过这些实验,给大家一个更加感性的认识。<BR><BR> <SPAN
class=style125> </SPAN><SPAN
class=style161>1、简单的蜂鸣器实验程序:</SPAN>本程序通过在P3.7输出一个音频范围的方波,驱动实验板上的蜂鸣器发出蜂鸣声,其中DELAY延时子程序的作用是使输出的方波频率在人耳朵听觉能力之内的20KHZ以下,如果没有这个延时程序的话,输出的频率将大大超出人耳朵的听觉能力,我们将不能听到声音。更改延时常数,可以改变输出频率,也就可以调整蜂鸣器的音调。大家可以在实验中更改#228为其他值,听听蜂鸣器音调的改变。<BR><BR> <SPAN
class=style125> </SPAN> ORG <SPAN
class=style125> </SPAN> <SPAN
class=style125> </SPAN>0000H<BR> <SPAN
class=style125> </SPAN> AJMP <SPAN
class=style125> </SPAN> MAIN<SPAN
class=style125> </SPAN> <SPAN
class=style125>
</SPAN>;跳转到主程序<BR><BR> <SPAN
class=style125> </SPAN> ORG <SPAN
class=style125> </SPAN> <SPAN
class=style125> </SPAN>
0030H<BR>MAIN: CPL <SPAN
class=style125> </SPAN> <SPAN
class=style125> </SPAN> P3.7 <SPAN
class=style125> </SPAN> <SPAN class=style125>
</SPAN>;蜂鸣器驱动电平取反<BR> <SPAN
class=style125> </SPAN> LCALL <SPAN
class=style125> </SPAN>DELAY <SPAN
class=style125> </SPAN>
;延时<BR> <SPAN
class=style125> </SPAN> AJMP <SPAN
class=style125> </SPAN> MAIN <SPAN
class=style125> </SPAN> <SPAN
class=style125> </SPAN>;反复循环<BR><BR>DELAY:MOV <SPAN
class=style125> </SPAN>R7,#228 <SPAN
class=style125>
</SPAN>;延时子程序,更改该延时常数可以改变蜂鸣器发出的音调<BR>DE1:
DJNZ <SPAN class=style125> </SPAN>
R7,DE1<BR> <SPAN
class=style125> </SPAN> RET<BR> <SPAN
class=style125> </SPAN> END<BR><BR><SPAN
class=style161> <SPAN
class=style125> </SPAN>2、倒车警示音实验程序:</SPAN>我们知道各种卡车、货柜车在倒车时候,会发出倒车的蜂鸣警示提示音,同时警示黄灯也同步闪烁,提醒后面的人或车辆注意。本实验例程就实现倒车警示功能,通过实验板上的蜂鸣器发出警示音,同时通过实验板上P1.2和P1.5上的两个黄色发光二极管来发出黄色警示灯。<BR><BR> <SPAN
class=style125> </SPAN> ORG <SPAN
class=style125> </SPAN>
0000H<BR> <SPAN
class=style125> </SPAN> AJMP <SPAN
class=style125> </SPAN> START <SPAN
class=style125>
</SPAN>;跳转到初始化程序<BR><BR> <SPAN
class=style125> </SPAN> ORG <SPAN
class=style125> </SPAN> <SPAN
class=style125> </SPAN>0033H<BR>START:<BR> <SPAN
class=style125> </SPAN> MOV <SPAN
class=style125> </SPAN> <SPAN
class=style125> </SPAN>SP,#60H<SPAN
class=style125> </SPAN><SPAN
class=style125> </SPAN>;SP初始化<BR> <SPAN
class=style125> </SPAN> MOV <SPAN
class=style125> </SPAN> <SPAN
class=style125> </SPAN>P3,#0FFH<SPAN
class=style125> </SPAN><SPAN
class=style125> </SPAN>;端口初始化<BR><BR>MAIN:
ACALL <SPAN class=style125> </SPAN>SOUND<SPAN
class=style125> </SPAN><SPAN
class=style125> </SPAN><SPAN
class=style125> </SPAN>
;蜂鸣器发声<BR> <SPAN
class=style125> </SPAN> ACALL <SPAN
class=style125> </SPAN>YS500M <SPAN
class=style125> </SPAN><SPAN
class=style125> </SPAN><SPAN
class=style125> </SPAN>;延时<BR> <SPAN
class=style125> </SPAN> AJMP <SPAN
class=style125> </SPAN><SPAN
class=style125> </SPAN>MAIN<BR><BR>SOUND:<BR> <SPAN
class=style125> </SPAN> MOV <SPAN
class=style125> </SPAN> <SPAN
class=style125> </SPAN>P1,#11011011B ;点亮2个警示黄色发光二极管
<BR> <SPAN class=style125> </SPAN>
MOV <SPAN class=style125> </SPAN> <SPAN
class=style125> </SPAN>R2,#200<SPAN
class=style125> </SPAN><SPAN
class=style125> </SPAN><SPAN
class=style125> </SPAN>;响200个周期<BR>SND1:
CLR <SPAN class=style125> </SPAN> <SPAN
class=style125> </SPAN>P3.7<SPAN
class=style125> </SPAN><SPAN
class=style125> </SPAN><SPAN
class=style125> </SPAN><SPAN
class=style125> </SPAN>
;输出低电平T1导通,蜂鸣器响<BR> <SPAN
class=style125> </SPAN> ACALL <SPAN
class=style125> </SPAN>YS1ms<SPAN
class=style125> </SPAN><SPAN
class=style125> </SPAN><SPAN
class=style125> </SPAN><SPAN
class=style125> </SPAN> ;延时<BR> <SPAN
class=style125> </SPAN> SETB <SPAN
class=style125> </SPAN><SPAN
class=style125> </SPAN>P3.7<SPAN
class=style125> </SPAN><SPAN
class=style125> </SPAN><SPAN
class=style125> </SPAN><SPAN
class=style125> </SPAN>
;输出高电平T1截止,蜂鸣器不响<BR> <SPAN
class=style125> </SPAN> ACALL <SPAN
class=style125> </SPAN>YS1ms <SPAN
class=style125> </SPAN><SPAN
class=style125> </SPAN><SPAN
class=style125> </SPAN><SPAN
class=style125> </SPAN>;延时<BR> <SPAN
class=style125> </SPAN> DJNZ <SPAN
class=style125> </SPAN> R2,SND1<BR> <SPAN
class=style125> </SPAN> MOV <SPAN
class=style125> </SPAN> <SPAN
class=style125> </SPAN>P1,#0FFH<SPAN
class=style125> </SPAN><SPAN
class=style125> </SPAN><SPAN
class=style125> </SPAN>;熄灭黄色警示灯<BR> <SPAN
class=style125> </SPAN> RET<BR><BR>YS1ms: <SPAN
class=style125> </SPAN><SPAN
class=style125> </SPAN><SPAN
class=style125> </SPAN><SPAN
class=style125> </SPAN><SPAN
class=style125> </SPAN><SPAN
class=style125> </SPAN><SPAN
class=style125> </SPAN><SPAN
class=style125> </SPAN><SPAN
class=style125> </SPAN>;1ms延时子程序
<BR> <SPAN class=style125> </SPAN>
MOV <SPAN class=style125> </SPAN> <SPAN
class=style125> </SPAN>R0,#2<BR>YL1: MOV <SPAN
class=style125> </SPAN> <SPAN
class=style125> </SPAN>R1,#250<SPAN
class=style125> </SPAN><SPAN
class=style125> </SPAN><SPAN
class=style125> </SPAN>
;改变R0的数值可改变声音频率<BR> <SPAN
class=style125> </SPAN> DJNZ <SPAN
class=style125> </SPAN> R1,$<BR> <SPAN
class=style125> </SPAN> DJNZ <SPAN
class=style125> </SPAN> R0,YL1<BR> <SPAN
class=style125> </SPAN> RET<BR><BR>YS500M: <SPAN
class=style125> </SPAN><SPAN
class=style125> </SPAN><SPAN
class=style125> </SPAN><SPAN
class=style125> </SPAN><SPAN
class=style125> </SPAN><SPAN
class=style125> </SPAN><SPAN
class=style125> </SPAN><SPAN
class=style125> </SPAN><SPAN
class=style125> </SPAN>
;500ms延时子程序<BR> <SPAN
class=style125> </SPAN> MOV <SPAN
class=style125> </SPAN> <SPAN
class=style125> </SPAN>R0,#6<BR>YL2: MOV <SPAN
class=style125> </SPAN> <SPAN
class=style125> </SPAN>R1,#200<BR>YL3:
MOV <SPAN class=style125> </SPAN> <SPAN
class=style125> </SPAN>R2,#250<BR> <SPAN
class=style125> </SPAN> DJNZ <SPAN
class=style125> </SPAN> R2,$<BR> <SPAN
class=style125> </SPAN> DJNZ <SPAN
class=style125> </SPAN> R1,YL3<BR> <SPAN
class=style125> </SPAN> DJNZ <SPAN
class=style125> </SPAN> R0,YL2<BR> <SPAN
class=style125> </SPAN> RET</P>
<P align=left> <SPAN
class=style125> </SPAN> END<BR><BR><BR><SPAN
class=style161> <SPAN
class=style125> </SPAN>3、“叮咚”电子门铃实验程序:</SPAN>常见的家用电子门铃在有客人来访时候,如果按压门铃按钮时,室内会发出“叮咚”声音,本实验程序模拟电子门铃的发音,当我们按压实验板上的K1按钮时候,蜂鸣器发出“叮咚”音乐声,是一个比较实用的程序。</P>
<TABLE width="100%" align=center border=0>
<TBODY>
<TR>
<TD vAlign=top>
<DIV class=style157 align=center>
<DIV align=left> <SPAN
class=style125> </SPAN>“叮咚”电子门铃实验ASM源程序:</DIV></DIV></TD>
<TD vAlign=top> </TD>
<TD vAlign=top>
<DIV align=justify><SPAN
class=style135>“叮咚”电子门铃C语言源程序:</SPAN></DIV></TD></TR>
<TR>
<TD vAlign=top width="51%"> <SPAN
class=style125> </SPAN>ORG <SPAN
class=style125> </SPAN>0000H<BR> <SPAN
class=style125> </SPAN>LJMP START
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -