|
#define LED_ON P2 &= 0XFD;
#define LED_OFF P2 |= 0X02;
void SOFW_PWM(unsigned int FRE,unsigned int time_interrupr,unsigned char loop_time)
{//須寧頻率在50以上才能不閃爍,以定時(shí)器中斷50us為例,則ZQ為1/50/50=1000000/2500=400
//FRE:頻率 time_interrupr:中斷時(shí)基 loop_time:呼吸燈由滅到最高亮度所需時(shí)間(單位秒)
static bit up_down_flag = 0,frist_flag = 0;
static unsigned int ON_count = 0;
static unsigned int count = 0,count2 = 0;
static unsigned int ZQ = 0;
if(frist_flag == 0)
{
frist_flag = 1;
ZQ = 1000000/FRE/time_interrupr;
}
if(++count > FRE*loop_time)//FRE=1/ZQ/定時(shí)器中斷
{
count = 0;
if(up_down_flag ==0)
{
if(ON_count < ZQ)
{
ON_count++;
}
else
{
up_down_flag = 1;
}
}
else
{
if(--ON_count == 0)
{
up_down_flag = 0;
}
}
}
if(++count2 > ZQ)//ZQ=1/fre/定時(shí)器中斷時(shí)基
{
count2 = 0;
}
P2M |= 0X02;
if(ON_count > count2)
{
LED_ON
}
else
{
LED_OFF
}
}
|
評(píng)分
-
查看全部評(píng)分
|