求大神帮忙 看一下代码

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;  //一个周期结束
}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值