/* .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---| |------------------------| |
關(guān) -----| |--beeper_off_timer--| |--------------------|
API使用
關(guān)閉: SetBeep(0,0,0);
長叫: SetBeep(1,0,0);
叫1聲 : SetBeep(1,20,30);
叫2聲 : SetBeep(2,20,30);
連續(xù)聲: SetBeep(0XFF,20,30);
SetBeep(1,5,0); 按鍵人機(jī)界面使用
SetBeep(0xff,35,50); 運(yùn)行中提示聲
SetBeep(0xff,20,30); 危險(xiǎn)出錯(cuò)警報(bào)聲
注: num > 0XFF 做連續(xù)聲特殊應(yīng)用
*/
static u8 beeper_on_timer = 0,beeper_off_timer = 0,BeepNum = 0;
static u16 BeepCnt = 0;
/* 配置參數(shù) (次數(shù) 開聲音時(shí)間 關(guān)聲音時(shí)間) */
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;
}
/* 系統(tǒng)后臺(tái)定時(shí)10mS調(diào)用一次 */
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;
}
}
}
|