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;
    }
     
     
     
     
     
     
     
  • 相关阅读:
    for循环实战性能优化
    MySQL group_concat 介绍
    MySQL 取分组后每组的最新记录
    MySQL查询top N记录
    常用SQL之日期格式化和查询重复数据
    Java 8 ThreadLocal 源码解析
    避免创建不必要的对象
    IntelliJ IDEA 设置忽略SVN文件和文件夹
    scrapy+selenium+chromedriver解析动态渲染页面
    java读取excel或者csv时日期格式数据处理
  • 原文地址:https://www.cnblogs.com/TheFly/p/11938697.html
Copyright © 2011-2022 走看看