標(biāo)題:
C語言軟件模擬PWM實(shí)現(xiàn)呼吸燈效果
[打印本頁]
作者:
李白不喝酒
時(shí)間:
2020-9-22 14:19
標(biāo)題:
C語言軟件模擬PWM實(shí)現(xiàn)呼吸燈效果
#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
}
}
作者:
man1234567
時(shí)間:
2020-9-29 08:08
須寧頻率 是什么鬼 ?為啥程序只有一個(gè)函數(shù) ?
歡迎光臨 (http://www.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1