求详细解释这个51单片机PWM波原理初学者,求逐步详解.#include sbit LED = P1^0;unsigned char CYCLE; unsigned char PWM_ON ;void delay(unsigned int cnt){while(--cnt);}main(){bit Flag;TMOD |=0x01;TH0=(65536-100)/256; TL0=(65536-100)%256;IE= 0x82; TR0=1;CYCLE = 10;while(!Flag){delay(200000); PWM_ON++; if(PWM_ON == CYCLE){ Flag=1;}}while(Flag) {delay(200000);PWM_ON--;if(PWM_ON == 0){Flag=0;}}}void tim(void) interrupt 1 using 1{static unsigned char count;TH0=(65536-100)/256; TL0=(65
问题描述:
求详细解释这个51单片机PWM波原理
初学者,求逐步详解.
#include
sbit LED = P1^0;
unsigned char CYCLE;
unsigned char PWM_ON ;
void delay(unsigned int cnt)
{
while(--cnt);
}
main()
{
bit Flag;
TMOD |=0x01;
TH0=(65536-100)/256;
TL0=(65536-100)%256;
IE= 0x82;
TR0=1;
CYCLE = 10;
while(!Flag)
{
delay(200000);
PWM_ON++;
if(PWM_ON == CYCLE)
{
Flag=1;
}
}
while(Flag)
{
delay(200000);
PWM_ON--;
if(PWM_ON == 0)
{
Flag=0;
}
}
}
void tim(void) interrupt 1 using 1
{
static unsigned char count;
TH0=(65536-100)/256;
TL0=(65536-100)%256;
if (count==PWM_ON)
{
LED = 1;
}
count++;
if(count == CYCLE)
{
count=0;
if(PWM_ON!=0)
LED = 0;
}
}
答
这个程序每一条语句你肯定能看懂,给你加注释没有必要,给你讲讲PWM的原理,你再对照程序看就明白了你要用51产生PWM去控制LED,首先你要确定PWM的周期T和占空比D,确定了这些以后,你可以用定时器产生一个时间基准t,比如定...