unsigned char BeepTime;
const unsigned char BeepTab[4]={6,10,20,50};
void Sound_Control(void)
{
unsigned char temp;
if(BeepDelay == 0)
{
temp = BeepTime;
if(Flg_Beep == 1)
{
Flg_Beep = 0;
temp >>= 2; //temp = temp / 4;
}
else
{
if((temp&0xf0) != 0)
{
Flg_Beep = 1;
BeepTime -= 0x10;
}
else return;
}
temp &= 0x03;
BeepDelay = BeepTab[temp];
}
}
__interrupt static void r_tau0_channel4_interrupt(void) //定时中断函数 125us
{
if(Flg_Beep == 1)
{
if(M_Buz == M_IN) M_Buz = M_OUT;
_Buz ^= 1;
}
else
{ _Buz = 0;
M_Buz = M_IN;
}
}
void main()
{
.....
.....
while(1)
{
Sound_Control();
}
}
不太能理解为什么BeepTime这个变量可以做到高4位控制蜂鸣次数,低4位控制蜂鸣时长,有大神可以解析下吗
|