- 代码如下:
#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char
sbit PWM=P0^2;// P2.0??pwm
uchar time; // ????????
void main()
{
TMOD=0x01;//
TH0=0xff;//
TL0=0xf7;//
EA=1;//????
ET0=1;//????0??
TR0=1;//?????0
while(1)
{
}
}
void tim0() interrupt 1
{
TR0=0;//????,?????
TH0=0xff;//(65536-10)/256;//?????
TL0=0xf7;//(65536-10)%256;//0.01ms
TR0=1;//?????
time++;
if(time>=100) //1khz
time=0;
if(time<=30) //占空比为30%
PWM=1;
else PWM=0;
}
网友评论