static u8 beeper_on_timer = 0,beeper_off_timer = 0,BeepNum = 0;
static u16 BeepCnt = 0;
void SetBeep(u8 num,u8 time_on,u8 time_off) //用户调用函数 {次数,开时间,关时间)单位10mS 其中num=0xff为连续模式
{
BeepNum = num;
beeper_on_timer = time_on;
beeper_off_timer = time_off;
SetBeeper(0);
BeepCnt = 0;
}
void ProF_10mS_Beeper(void) //定期器10mS调度任务
{
if(BeepCnt)
{
BeepCnt--;
if(BeepCnt == beeper_off_timer)
SetBeeper(0);
}
else
{
if(BeepNum == 0XFF)
{
SetBeeper(1);
BeepCnt = beeper_on_timer + beeper_off_timer;
}
else if(BeepNum)
{
SetBeeper(1);
BeepNum --;
BeepCnt = beeper_on_timer + beeper_off_timer;
}
}
}
sbit   IN_LED = P4^7;
void SetBeeper(u8 high) //蜂鸣器接口
{
if(high)
PIN_LED = 1;
else
PIN_LED = 0;
}
|