用PWM驱动无源蜂鸣器
bit buzzer_bit,/*开/关蜂鸣器位*/unsigned char buzzer_count; /*鸣 叫时间*/
buzzer( )
{
if(buzzer_bit==1)
{
CCPR1L=0X7F;
CCP1CON=0X3C;
PR2=0Xf9;//(4khz);f=1/(pr2+1*4]*T*t2
T2CON=0X04;
buzzer_bit=0;
buzzer_count=0;
}
if(buzzercount>=10)
{
CCP1CON=0;
RC2=0;
buzzer_count=0;
}
}
页:
[1]