| 
 
| 小小程序如下 #include<reg52.h>
 
 int c=800;
 #define l (19000-c)
 #define h (c)
 bit a=1,b;
 sbit PWM=P1^1;
 
 void delay(int x)
 {
 while(x--);
 
 }
 
 void init()
 {
 TMOD=0x01;
 EA=1;
 ET0=1;
 TH0=(65536-h)/256;
 TL0=(65536-h)%256;
 TR0=1;
 }
 
 void main()
 {
 init();
 while(1)
 {
 PWM=a;
 }
 
 
 }
 void time0() interrupt 1
 {
 b=~b;
 if(b)
 {
 TH0=(65536-l)/256;
 TL0=(65536-l)%256;
 a=0;
 }
 else
 {
 TH0=(65536-h)/256;
 TL0=(65536-h)%256;
 a=1;
 }
 
 }这是个产生PWM波的 变量c是高电平的时间 当c=800 时高电平就有1ms多点,但c=799时,高电平就急剧减少 只有5us 怪啊
 | 
 |