#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit PWM=P2^0; //LED灯
bit DIR;
uint count,value,timer1;
void Timer1Init()
{
TMOD|=0x01;
TH1=0xff;
TL1=0xff;
EA=1;
ET1=1;
TR1=1;
}
void main()
{
Timer1Init();
while(1)
{
if(count>100)
{
count=0;
if(DIR==1)
{
value++;
}
if(DIR==0)
{
value--;
}
}
if(value==1000)
{
DIR=0;
}
if(value==0)
{
DIR=1;
}
if(timer1>1000)
{
timer1=0;
}
if(timer1<value)
{
PWM=1;
}
else
{
PWM=0;
}
}
}
void Time1(void) interrupt 3
{
TH1=0xff;
TL1=0xff;
timer1++;
count++;
}
如果文章或资源对您有帮助,欢迎打赏作者。一路走来,感谢有您!
txttool.com 说一段 esp56物联 查询128 IP查询