pIC16c54警报声程序
#include“pic.h”
#definebeep_outRA2//音效输出
chartmr_buff;
charcycle_buff;
charcycle_set;
intchange_set;
intchange_count;
bitchange_flag;
voidmain(void)
{TRISA=0X0;
PORTA=0;
OPTION=4;
cycle_buff=52;
cycle_set=100;
change_set=196;
TMR0=0;
while(1)
{
if(TMR0==0)
{TMR0=(cycle_set-1)^0XFF;
beep_out=!beep_out;
change_count+=cycle_set;
if(change_count》change_set)
{change_count-=change_set;
if(change_flag)
{if(++cycle_set》195)
{change_flag=0;
}
}
else
{if(–cycle_set《52)
{change_flag=1;
}
}
}
}
}
}