电子制作天地网站欢迎您的光临,欢迎提出宝贵意见或建议。本站信息产业部备案: 粤ICP备05114582号
单片机制作“ 叮咚”门铃
AT89S51 DOORBELL

时间:2014-04-02 来源:互联网 作者:不详 编辑: 【关闭


单片机制作“ 叮咚”门铃,AT89S51 DOORBELL

关键字:AT89S51,门铃电路

 
1.实验任务
当按下开关SP1,AT89S51单片机产生“叮咚”声从P1.0端口输出到LM386,经过放大之后送入喇叭。
2.电路原理图
 
单片机制作“ 叮咚”门铃AT89S51 DOORBELL
 
3.系统板上硬件连线
(1.       把“单片机系统”区域中的P1.0端口用导线连接到“音频放大模块”区域中的SPK IN端口上;
(2.       在“音频放大模块”区域中的SPK OUT端口上接上一个8欧或者是16欧的喇叭;
(3.       把“单片机系统”区域中的P3.7/RD端口用导线连接到“独立式键盘”区域中的SP1端口上;
4.程序设计方法
(1.       我们用单片机实定时/计数器T0来产生700HZ和500HZ的频率,根据定时/计数器T0,我们取定时250us,因此,700HZ的频率要经过3次250us的定时,而500HZ的频率要经过4次250us的定时。
(2.       在设计过程,只有当按下SP1之后,才启动T0开始工作,当T0工作完毕,回到最初状态。
(3.       “叮”和“咚”声音各占用0.5秒,因此定时/计数器T0要完成0.5秒的定时,对于以250us为基准定时2000次才可以。
6.汇编源程序
T5HZ                  EQU 30H
T7HZ                  EQU 31H
T05SA                EQU 32H
T05SB                 EQU 33H
FLAG                 BIT 00H
STOP                  BIT 01H
SP1                      BIT P3.7
                            ORG 00H
                            LJMP START
                            ORG 0BH
                            LJMP INT_T0
START:               MOV TMOD,#02H
                            MOV TH0,#06H
                            MOV TL0,#06H
                            SETB ET0
                            SETB EA
NSP:                   JB SP1,NSP
                            LCALL DELY10MS
                            JB SP1,NSP
                            SETB TR0
                            MOV T5HZ,#00H
                            MOV T7HZ,#00H
                            MOV T05SA,#00H
                            MOV T05SB,#00H
                            CLR FLAG
                            CLR STOP                  
                            JNB STOP,$
                            LJMP NSP
DELY10MS:       MOV R6,#20
D1:                      MOV R7,#248
                            DJNZ R7,$
                            DJNZ R6,D1
                            RET
INT_T0:             INC T05SA
                            MOV A,T05SA
                            CJNE A,#100,NEXT
                            MOV T05SA,#00H
                            INC T05SB
                            MOV A,T05SB
                            CJNE A,#20,NEXT
                            MOV T05SB,#00H
                            JB FLAG,STP
                            CPL FLAG
                            LJMP NEXT
STP:                    SETB STOP
                            CLR TR0
                            LJMP DONE
NEXT:                JB FLAG,S5HZ
                            INC T7HZ
                            MOV A,T7HZ
                            CJNE A,#03H,DONE
                            MOV T7HZ,#00H
                            CPL P1.0
                            LJMP DONE
S5HZ:                 INC T5HZ
                            MOV A,T5HZ
                            CJNE A,#04H,DONE
                            MOV T5HZ,#00H
                            CPL P1.0
                            LJMP DONE
DONE:                RETI
                            END
 
7.C语言源程序
#include
unsigned char t5hz;
unsigned char t7hz;
unsigned int tcnt;
bit stop;
bit flag;
void main(void)
{
  unsigned char i,j;
  TMOD=0x02;
  TH0=0x06;
  TL0=0x06;
  ET0=1;
  EA=1;
  while(1)
    {
      if(P3_7==0)
        {
          for(i=10;i>0;i--)
          for(j=248;j>0;j--);
          if(P3_7==0)
            {
              t5hz=0;
              t7hz=0;
              tcnt=0;
              flag=0;
              stop=0;
              TR0=1;
              while(stop==0);
            }
        }
    }
}
void t0(void) interrupt 1 using 0
{
  tcnt++;
  if(tcnt==2000)
    {
      tcnt=0;
      if(flag==0)
        {
          flag=~flag;
        }
        else
          {
            stop=1;
            TR0=0;
          }
    }
  if(flag==0)
    {
      t7hz++;
      if(t7hz==3)
        {
          t7hz=0;
          P1_0=~P1_0;
        }
    }
    else
      {
        t5hz++;
        if(t5hz==4)
          {
            t5hz=0;
            P1_0=~P1_0;
          }
      }
}
 
 


◆相关文章◆
◆ 编辑推荐 ◆
用户:
更多评论
您要为您所发的言论的后果负责,故请各位遵纪守法并注意语言文明。60个字以内
留言:
验证码:

免责声明:
●本站所有内容均来自网络,以学习为目的,如果侵犯了您的利益,请来信告知,立即删除,站长邮件为"diy+dzdiy.com",请将"+"变更为"@"
●电子制作存在风险,请注意人身安全,如果您在根据本站电路进行制作过程中发生伤害,本站不负任何责任。

版权所有:www.dzdiy.com ? 2001-2012 本站信息产业部备案: 粤ICP备05114582号