void InterruptTimer1() interrupt 3
{static bit dir = 0;
static unsigned char index = 0;
unsigned char code table[13] = { //占空比调整表5, 18, 30, 41, 51, 60, 68, 75, 81, 86, 90, 93, 95}
TH1 = T1RH; //重新加载 T1 重载值TL1 = T1RL;
AdjustDutyCycle(table[index]); //调整 PWM 的占空比if (dir == 0) //逐步增大占空比{
index++;
if (index >= 12)
{
dir = 1;
}
}
else //逐步减小占空比{
index--;
if (index == 0)
{
dir = 0;
}
}
这个动态调整dc占空比的话,里面那个dir第一次进来的时候=0 ,第二次为1, dir又为0 ,这个占空比不就永远只在两个数之间循坏了?
|