关于定时器中断PWM的占空比问题。
时间:10-02
整理:3721RD
点击:
flag=0;
void timer0() interrupt 1
{
if(t0_flag == 0)
{
t1_flag = 1;
PWM = 1;
TH0 = (65536 - tpwm )/256;
TL0 = (65536 - tpwm)%256;
}
else
{
t0_flag = 0;
PWM = 0;
TH1 = (65536- 10000 + tpwm )/256;
TL1 = (65536 - 10000 + tpwm )%256;
}
}
tpwm/10000 是否就是代表占空比?如果不行的话要如何实现?
void timer0() interrupt 1
{
if(t0_flag == 0)
{
t1_flag = 1;
PWM = 1;
TH0 = (65536 - tpwm )/256;
TL0 = (65536 - tpwm)%256;
}
else
{
t0_flag = 0;
PWM = 0;
TH1 = (65536- 10000 + tpwm )/256;
TL1 = (65536 - 10000 + tpwm )%256;
}
}
tpwm/10000 是否就是代表占空比?如果不行的话要如何实现?
能不能完整一点啊,有些参数不明确
没改清楚.. 我再改改
unsigned char tpwm; //高电平时间
flag=0;
void timer0() interrupt 1
{
if(flag == 0)
{
flag = 1;
PWM = 1;
TH0 = (65536 - tpwm )/256;
TL0 = (65536 - tpwm)%256;
}
else
{
flag = 0;
PWM = 0;
TH0 = (65536- 10000 + tpwm )/256;
TL0 = (65536 - 10000 + tpwm )%256;
}
}
tpwm/10000 是否就是代表占空比?如果不行的话要如何实现?