原创 6.报警产生器

2008-10-18 14:54 1890 3 3 分类: MCU/ 嵌入式

1. 实验任务<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />


P1.0输出1KHz500Hz的音频信号驱动扬声器,作报警信号,要求1KHz信号响100ms500Hz信号响200ms,交替进行,P1.7接一开关进行控制,当开关接低电平响报警信号,当开关断开告警信号停止,编出程序。


2. 电路原理图


点击开大图


3、实现程序


1. 汇编源程序


FLAG                           BIT 00H


                                      ORG 00H


START:                        JB P1.7,START


                                      JNB FLAG,NEXT


                                      MOV R2,#200


DV:                               CPL P1.0


                                      LCALL DELY500


                                      LCALL DELY500


                                      DJNZ R2,DV


                                      CPL FLAG


NEXT:                         MOV R2,#200


DV1:                   CPL P1.0


                                      LCALL DELY500


                                      DJNZ R2,DV1


                                      CPL FLAG


                                      SJMP START


DELY500:           MOV R7,#250


<?xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com:office:smarttags" />LOOP:                         NOP


                                      DJNZ R7,LOOP


                                      RET


                                      END


2. C语言源程序


#include <AT89X51.H>


unsigned char count;


void dely500(void)
{
  unsigned char i;
  for(i=250;i>0;i--);
}


void main(void)
{
  while(1)
    {
      if(P1_7==0)
        {
          for(count=200;count>0;count--)
            {
              P1_0=~P1_0;
              dely500();            //每间隔500usP1.0取反一次,周期就是1ms,频率LKHZ
            }
          for(count=200;count>0;count--)
            {
              P1_0=~P1_0;
              dely500();
              dely500();          //每间隔1000usP1.0取反一次,周期是2ms,频率500HZ
            }
        }
    }
}
点击看大图


 


 


 


 


 


 

PARTNER CONTENT

文章评论0条评论)

登录后参与讨论
EE直播间
更多
我要评论
0
3
关闭 站长推荐上一条 /3 下一条