一个51单片机的程序,求大神帮忙看一下
#include<reg52.h>#defineucharunsignedchar#defineuintunsignedintuintpwm,tper,times=0;u...
#include <reg52.h>
#define uchar unsigned char
#define uint unsigned int
uint pwm,tper,times=0;
uchar tab[4]={20,40,60,80};
sbit pulse=P1^0;
bit flag;
void t0isr() interrupt 1
{
flag=~flag;
pulse=~pulse;
if(flag)
{
TH0=(65536-pwm)/256;
TL0=(65536-pwm)%256;
}
if(!flag)
{
TH0=(65536-(tper-pwm))/256;
TL0=(65536-(tper-pwm))%256;
}
}
void t1isr() interrupt 3
{
TH1=(65536-50000)/256;
TL1=(65536-50000)%256;
times++;
pwm=tper*tab[(times/200)%4]/100;
}
main()
{
TMOD=0x11;
tper=1000;
pwm=tper*tab[0]/100;
TH0=(65536-pwm)/256;
TL0=(65536-pwm)%256;
TH1=(65536-50000)/256;
TL1=(65536-50000)%256;
TR0=1;
TR1=1;
ET0=1;
ET1=1;
EA=1;
while(1);
}
大概是产生一个占空比循环改变的电压,帮忙加个输出 展开
#define uchar unsigned char
#define uint unsigned int
uint pwm,tper,times=0;
uchar tab[4]={20,40,60,80};
sbit pulse=P1^0;
bit flag;
void t0isr() interrupt 1
{
flag=~flag;
pulse=~pulse;
if(flag)
{
TH0=(65536-pwm)/256;
TL0=(65536-pwm)%256;
}
if(!flag)
{
TH0=(65536-(tper-pwm))/256;
TL0=(65536-(tper-pwm))%256;
}
}
void t1isr() interrupt 3
{
TH1=(65536-50000)/256;
TL1=(65536-50000)%256;
times++;
pwm=tper*tab[(times/200)%4]/100;
}
main()
{
TMOD=0x11;
tper=1000;
pwm=tper*tab[0]/100;
TH0=(65536-pwm)/256;
TL0=(65536-pwm)%256;
TH1=(65536-50000)/256;
TL1=(65536-50000)%256;
TR0=1;
TR1=1;
ET0=1;
ET1=1;
EA=1;
while(1);
}
大概是产生一个占空比循环改变的电压,帮忙加个输出 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询