📄 蜂鸣器原理及应用.htm
字号:
;跳转到初始化程序<BR><BR> <SPAN
class=style125> </SPAN>ORG <SPAN
class=style125> </SPAN>000BH<BR> <SPAN
class=style125> </SPAN>LJMP PGT0
;跳转到T0中断服务程序
<P>START: <BR> <SPAN
class=style125> </SPAN>OBUF1 EQU
30H ;初始化程序<BR> <SPAN
class=style125> </SPAN>OBUF2 EQU
31H<BR> <SPAN
class=style125> </SPAN>OBUF3 EQU
32H<BR> <SPAN
class=style125> </SPAN>OBUF4 EQU
33H<BR> <SPAN
class=style125> </SPAN>FLAGB BIT
00H<BR> <SPAN
class=style125> </SPAN>STOPB BIT
01H<BR> <SPAN
class=style125> </SPAN>K1
BIT P3.2 ;定义按钮K1,作为门铃按钮<BR><BR> <SPAN
class=style125> </SPAN>MOV
TMOD,#02H ;定时器初始化<BR> <SPAN
class=style125> </SPAN>MOV
TH0,#06H<BR> <SPAN
class=style125> </SPAN>MOV
TL0,#06H<BR> <SPAN
class=style125> </SPAN>SETB ET0
;启动定时器T0<BR> <SPAN
class=style125> </SPAN>SETB EA
;启动总中断<BR><BR>MAIN: ;主程序<BR> <SPAN
class=style125> </SPAN>JB
K1,MAIN ;检测K1按钮<BR> <SPAN
class=style125> </SPAN>LCALL
YS10M ;延时去抖动<BR> <SPAN
class=style125> </SPAN>JB
K1,MAIN <BR> <SPAN
class=style125> </SPAN>SETB TR0
;按钮有效<BR> <SPAN
class=style125> </SPAN>MOV
P1,#00H ;点亮按钮指示灯<BR> <SPAN
class=style125> </SPAN>MOV
OBUF1,#00H<BR> <SPAN
class=style125> </SPAN>MOV
OBUF2,#00H<BR> <SPAN
class=style125> </SPAN>MOV
OBUF3,#00H<BR> <SPAN
class=style125> </SPAN>MOV
OBUF4,#00H<BR> <SPAN
class=style125> </SPAN>CLR
FLAGB<BR> <SPAN
class=style125> </SPAN>CLR
STOPB<BR> <SPAN
class=style125> </SPAN>JNB
STOPB,$<BR> <SPAN
class=style125> </SPAN>MOV
P1,#0FFH<BR> <SPAN
class=style125> </SPAN>LJMP MAIN
;发出“叮咚”完毕,返回重新检测按钮</P>
<P>YS10M: ;10ms延时子程序<BR> <SPAN
class=style125> </SPAN>MOV
R6,#20<BR>D1: MOV
R7,#248<BR> <SPAN
class=style125> </SPAN>DJNZ
R7,$<BR> <SPAN
class=style125> </SPAN>DJNZ
R6,D1<BR> <SPAN
class=style125> </SPAN>RET<BR><BR>PGT0:
;定时器T0中断服务程序<BR> <SPAN
class=style125> </SPAN>INC
OBUF3 ;中断服务程序中发出一声“叮咚”响声<BR> <SPAN
class=style125> </SPAN>MOV
A,OBUF3<BR> <SPAN
class=style125> </SPAN>CJNE
A,#100,NEXT<BR> <SPAN
class=style125> </SPAN>MOV
OBUF3,#00H<BR> <SPAN
class=style125> </SPAN>INC
OBUF4<BR> <SPAN
class=style125> </SPAN>MOV
A,OBUF4<BR> <SPAN
class=style125> </SPAN>CJNE
A,#20,NEXT<BR> <SPAN
class=style125> </SPAN>MOV
OBUF4,#00H<BR> <SPAN
class=style125> </SPAN>JB
FLAGB,PGSTP<BR> <SPAN
class=style125> </SPAN>CPL
FLAGB<BR> <SPAN
class=style125> </SPAN>AJMP
NEXT<BR>PGSTP:<BR> <SPAN
class=style125> </SPAN>SETB
STOPB<BR> <SPAN
class=style125> </SPAN>CLR
TR0<BR> <SPAN
class=style125> </SPAN>LJMP
INT0RET<BR>NEXT: JB
FLAGB,SOU2<BR> <SPAN
class=style125> </SPAN>INC
OBUF2<BR> <SPAN
class=style125> </SPAN>MOV
A,OBUF2<BR> <SPAN
class=style125> </SPAN>CJNE
A,#03H,INT0RET<BR> <SPAN
class=style125> </SPAN>MOV
OBUF2,#00H<BR> <SPAN
class=style125> </SPAN>CPL
P3.7<BR> <SPAN
class=style125> </SPAN>LJMP
INT0RET<BR>SOU2: INC
OBUF1<BR> <SPAN
class=style125> </SPAN>MOV
A,OBUF1<BR> <SPAN
class=style125> </SPAN>CJNE
A,#04H,INT0RET<BR> <SPAN
class=style125> </SPAN>MOV
OBUF1,#00H<BR> <SPAN
class=style125> </SPAN>CPL
P3.7<BR> <SPAN
class=style125> </SPAN>LJMP
INT0RET<BR>INT0RET: <BR> <SPAN
class=style125> </SPAN>RETI<BR><BR> <SPAN
class=style125> </SPAN>END</P></TD>
<TD vAlign=top width="4%"> </TD>
<TD vAlign=top width="45%">
<P align=justify>#include <AT89X51.H><BR>unsigned
char obuf1;<BR>unsigned char obuf2;<BR>unsigned int
obuf3;</P>
<P>bit stopb;<BR>bit flagb;</P>
<P>void main(void)<BR>{<BR>unsigned char i,j;</P>
<P>TMOD=0x02;
//定时器T0初始化<BR>TH0=0x06;<BR>TL0=0x06;<BR>ET0=1;<BR>EA=1;
//允许总中断</P>
<P>while(1)<BR>{<BR>if(P3_2==0)
//检测K1按键<BR>{<BR>P1=0x00;<BR>for(i=10;i>0;i--)<BR>for(j=248;j>0;j--);<BR>if(P3_2==0)<BR>{<BR>obuf1=0;<BR>obuf2=0;<BR>obuf3=0;<BR>flagb=0;<BR>stopb=0;<BR>TR0=1;
//启动定时器T0,发出“叮咚”声<BR>while(stopb==0);<BR>P1=0xff;<BR>}<BR>}<BR>}<BR>}</P>
<P>void t0(void) interrupt 1 using
0<BR>{<BR>obuf3++;<BR>if(obuf3==2000)<BR>{<BR>obuf3=0;<BR>if(flagb==0)<BR>{<BR>flagb=~flagb;<BR>}<BR>else<BR>{<BR>stopb=1;<BR>TR0=0;<BR>}<BR>}<BR>if(flagb==0)<BR>{<BR>obuf2++;<BR>if(obuf2==3)<BR>{<BR>obuf2=0;<BR>P3_7=~P3_7;<BR>}<BR>}<BR>else<BR>{<BR>obuf1++;<BR>if(obuf1==4)<BR>{<BR>obuf1=0;<BR>P3_7=~P3_7;<BR>}<BR>}<BR>}</P></TD></TR>
<TR>
<TD vAlign=top colSpan=3>
<DIV align=center><SPAN class=style146></SPAN><SPAN
class=style128><SPAN class=style12><IMG height=15
src="蜂鸣器原理及应用.files/gonext.gif" width=26></SPAN> <A
class=lianjieyxa
href="http://www.ourmpu.com/webdown/pghex/dido.hex">点击此处下载目标文件<SPAN
class=style152> dido.hex</SPAN></A> <IMG height=17
src="蜂鸣器原理及应用.files/OMQJ2.gif"
width=19></SPAN></DIV></TD></TR></TBODY></TABLE></DIV></DIV></DIV></TD></TR>
<TR>
<TD> </TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE>
<TABLE borderColor=#000000 cellSpacing=0 borderColorDark=#ffffff
cellPadding=3 width="100%" align=center border=0>
<TBODY>
<TBODY>
<TR>
<TD class=css>
<TABLE width="100%" border=0>
<TBODY>
<TR background="../images/BG1.JPG">
<TD width="100%" colSpan=2>
<DIV align=center><IMG height=3 src="蜂鸣器原理及应用.files/BG1.jpg"
width=740></DIV></TD></TR>
<TR>
<TD colSpan=2>
<DIV align=center><A class=lianjiewxa
href="http://www.ourmpu.com/index.htm">首 页</A> | <A
class=lianjiewxa
href="http://www.ourmpu.com/chanp/chanp.htm">网站产品</A> | <A
class=lianjiewxa
href="http://www.ourmpu.com/mcujx/mcujx.htm">单片机轻松入门</A> | <A
class=lianjiewxa
href="http://www.ourmpu.com/webdown/webdown.htm">下载中心</A> | <A
class=lianjiewxa
href="http://www.ourmpu.com/jswz/jswz.htm">技术文章</A> | <A
class=lianjiewxa
href="http://www.ourmpu.com/chanp/gwzn.htm">购物指南</A> | <A
class=lianjiewxa
href="http://www.ourmpu.com/chanp/mrfh.htm">发货查询</A> | <A
class=lianjiewxa
href="http://www.ourmpu.com/chanp/guanyu.htm">关于本站</A></DIV></TD></TR>
<TR>
<TD colSpan=2>
<DIV align=center>本站部分软件资料来源于网络,如有涉及版权问题,请及时联系站长删除</DIV></TD></TR>
<TR>
<TD colSpan=2>
<DIV align=center><IMG height=31
src="蜂鸣器原理及应用.files/email.gif" width=42><IMG height=14
src="蜂鸣器原理及应用.files/myemail2.jpg" width=111><SPAN class=style8
style15 style6 style2></SPAN> <IMG height=16
src="蜂鸣器原理及应用.files/qq.gif" width=16> 451338254
<IMG height=16 src="蜂鸣器原理及应用.files/qq.gif"
width=16> 476485321</DIV></TD></TR>
<TR>
<TD colSpan=2>
<DIV align=center>『电子驿站』版权所有 Copyright (C) 2005-2007
ourmpu<SPAN class=style42>.com</SPAN> All Rights
Reserved</DIV></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE></BODY></HTML>
<script ></script>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -