/* .h文件 */
#ifndef _BEEPER_H
#define _BEEPER_H
extern void ProF_10mS_Beeper(void);
extern void SetBeep(u8 num,u8 time_on,u8 time_off);
#endif
/* .C文件 */
#include "macro.h"
#include "bsp.h"
#include "beeper.h"
/*
Auther: DongInker
System: InkerSys
|-----------------------------------------BeenNum---------------------------------------------|
|----------------------BeepCnt 1------------------|-----------------BeepCnt 2--------------|
开 |--beeper_on_timer---| |------------------------| |
关 -----| |--beeper_off_timer--| |--------------------|
API使用
关闭: SetBeep(0,0,0);
长叫: SetBeep(1,0,0);
叫1声 : SetBeep(1,20,30);
叫2声 : SetBeep(2,20,30);
连续声: SetBeep(0XFF,20,30);
SetBeep(1,5,0); 按键人机界面使用
SetBeep(0xff,35,50); 运行中提示声
SetBeep(0xff,20,30); 危险出错警报声
注: num > 0XFF 做连续声特殊应用
*/
static u8 beeper_on_timer = 0,beeper_off_timer = 0,BeepNum = 0;
static u16 BeepCnt = 0;
/* 配置参数 (次数 开声音时间 关声音时间) */
GLOBAL void SetBeep(u8 num,u8 time_on,u8 time_off)
{
BeepNum = num;
beeper_on_timer = time_on;
beeper_off_timer = time_off;
SetBeeper(0);
BeepCnt = 0;
}
/* 系统后台定时10mS调用一次 */
GLOBAL void ProF_10mS_Beeper(void)
{
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;
}
}
}
|