51单片机pwm呼吸灯问题

error- error- 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
#include<reg52.h>
#include <intrins.h>
#define uint unsigned int
#define uchar unsigned char
sbit pwm =P2^1;
uint count=0,timer1=0,value=0;
bit DIR=1;
void main()
{
TMOD=1;
TH0=(65536-1)/256;
TL0=(65536-1)%256;
EA=1;//开总中断
ET0=1;//开定时器0中断
TR0=1;//TR0置位,启动定时器


while(1)
{

if(timer1>value)
{
pwm=0;
}
else
{
pwm=1;
}

}
}

void time0() interrupt 1 using 1
{
TH0=(65536-1)/256;
TL0=(65536-1)%256;
timer1++;
count++;
if(timer1>500)
{
timer1=0;
}
if(count>100)
{
count=0;
if(DIR==1)
{
value++;
}
if(DIR==0)
{
value--;
}
}

if(value==500)
{
DIR=0;
}
if(value==0)
{
DIR=1;
}

}
到底哪个是周期?哪一个是调节占空比的参数?这个程序不懂==求教了
...全文

相关推荐

评论 8
收藏 已收藏
分享
返回顶部
error-
单片机/工控 27,522 成员 28,796 内容