码迷,mamicode.com
首页 > 其他好文 > 详细

蜂鸣器的驱动程序---吴坚鸿

时间:2019-11-26 22:21:59      阅读:111      评论:0      收藏:0      [点我收藏+]

标签:time()   lse   蜂鸣器   switch   uid   else   cal   驱动程序   unsigned   

#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;
}
 
 
 
 
 
 
 

蜂鸣器的驱动程序---吴坚鸿

标签:time()   lse   蜂鸣器   switch   uid   else   cal   驱动程序   unsigned   

原文地址:https://www.cnblogs.com/TheFly/p/11938697.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!