void Init_Timer0(void)
{
TMOD |= 0x01; //使用模式1,16位定时器,使用"|"符号可以在使用多个定时器时不受影响
TH0=(65536-20000)/256; //重新赋值 20ms
TL0=(65536-20000)%256;
EA=1; //总中断打开
ET0=1; //定时器中断打开
TR0=1; //定时器开关打开
}
void Timer0_isr(void) interrupt 1
{
static unsigned char countLed_1 =0;
static unsigned char countLed_2 =0;
static unsigned char countLed_3 =0;
TH0=(65536-2000)/256; //重新赋值 20ms
TL0=(65536-2000)%256;
time_20ms++;
if(time_20ms % 100 == 0)
{
disFlag =1 ;//定时更新显示
}
countLed_1++;
if(countLed_1<pwm_1) //led1 占空比调节
{led_1=0;} //打开
else if(countLed_1<=6) //关闭时间段
{
led_1=1; //关闭
if(countLed_1 == 6) countLed_1=0; //一个周期结束
}
countLed_2++;
if(countLed_2<pwm_2) //led2 占空比调节
{led_2=0;} //打开
else if(countLed_2<=6) //关闭时间段
{
led_2=1; //关闭
if(countLed_2 == 6) countLed_2=0; //一个周期结束
}
countLed_3++;
if(countLed_3<pwm_3) //led3 占空比调节
{led_3=0;} //打开
else if(countLed_3<=6) //关闭时间段
{
led_3=1; //关闭
if(countLed_3 == 6) countLed_3=0; //一个周期结束
}
}