zoukankan      html  css  js  c++  java
  • 蜂鸣器的驱动程序

    #include "REG52.H"
    #define const_time_05s 222
    #define const_time_1s 444
    #define const_time_3s 1332
    #define const_time_6s 2664
    #define const_voice_short 40
    #define const_voice_long 200
    void initial_myself();
    void initial_peripheral();
    void delay_long(unsigned int uiDelaylong);
    void led_flicker();
    void alarm_run();
    void T0_time();
    sbit led_dr=P3^5;
    sbit beep_dr=P1^5;
    unsigned char ucLedStep=0;
    unsigned int uiTimeLedCnt=0;
    unsigned char ucAlarmStep=0;
    unsigned int uiTimeAlarmCnt=0;
    unsigned int uiVoiceCnt=0;
    void main()
    {
     initial_myself();
     delay_long(100);
     initial_peripheral();
     while(1)
     {
      led_flicker();
      alarm_run();
     }
    }
    void led_flicker()  //第三区  LED闪烁程序
    {
     switch(ucLedStep)
     {
      case 0:
       if(uiTimeLedCnt>=const_time_05s)
       {
        uiTimeLedCnt=0;
        led_dr=0;
        ucLedStep=1;
       }
       break;
      case 1:
       if(uiTimeLedCnt>=const_time_05s)
       {
        uiTimeLedCnt=0;
        led_dr=1;
        ucLedStep=0;
       }  
       break; 
     }
    }
    void alarm_run()
    {
     switch(ucAlarmStep)
     {
      case 0:
       if(uiTimeAlarmCnt>=const_time_3s)
       {
        uiTimeAlarmCnt=0;
        uiVoiceCnt=const_voice_short;
        ucAlarmStep=1;
       }
       break;
      case 1:
       if(uiTimeAlarmCnt>=const_time_6s)
       {
        uiTimeAlarmCnt=0;
        uiVoiceCnt=const_voice_long;
        ucAlarmStep=0;
       }
       break;
     }
    }
    void T0_time() interrupt 1
    {
     TF0=0;
     TR0=0;
     if(uiTimeLedCnt<0xffff)
      uiTimeLedCnt++;
     if(uiTimeAlarmCnt<0xffff)
      uiTimeAlarmCnt++;
     
     if(uiVoiceCnt!=0)
     {
      uiVoiceCnt--;
      beep_dr=0;
     }
     else
     {
      ;
      beep_dr=1;
     }
     
     TH0=0xf8;
     TL0=0x2f;
     TR0=1;
    }
    void delay_long(unsigned int uiDelaylong)
    {
     unsigned int i;
     unsigned int j;
     for(i=0;i<uiDelaylong;i++)
      for(j=0;j<500;j++)
       ;
    }
    void initial_myself()
    {
     TMOD=0x01;
     TH0=0xf8;
     TL0=0x2f;
     led_dr=1;
     beep_dr=1;
    }
    void initial_peripheral()
    {
     EA=1;
     ET0=1;
     TR0=1;
    }
     
     
     
     
     
     
     
  • 相关阅读:
    抽象类与抽象方法
    简单工厂模式
    面向对象的七种基本设计原则
    HashTable集合遍历的三种方法
    继承(父类为虚方法以及子类的重写)
    继承(is与as)
    Chrome OS 更新新版本可让Linux访问USB连接的Android设备
    谷歌对Intel 10nm进度不满
    盖茨对没能做好手机系统对抗苹果表示遗憾
    微软内部封杀 Slack
  • 原文地址:https://www.cnblogs.com/TheFly/p/11938697.html
Copyright © 2011-2022 走看看