我这个程序产生的SPWM波形 它的每个周期之间的连接总是会有个断点 用示波器看 就是会有一小段低电平 用LED灯看 从暗到亮 再从亮到暗 在重复 这中间就会有很短的一个闪烁 我如果不要这个闪烁 我应该怎么做?
#include"reg51.h"
typedef unsigned int u1;
typedef unsigned char u2;
u1 code tiaozhi[]={
1,32,64,95,126,157,188,219,250,280,
310,340,369,398,427,455,483,510,537,563,
589,614,638,662,686,708,730,751,772,791,
810,828,845,862,877,892,906,919,931,942,
952,961,970,977,983,989,993,997,999,1000,
1000,1000,999,997,993,989,983,977,970,961,
952,942,931,919,906,892,877,862,845,828,
810,791,772,751,730,708,686,662,638,614,
589,563,537,510,483,455,427,398,369,340,
310,280,250,219,188,157,126,95,64,32};
//u1 code tiaozhi[]={0,31,63,94,125,156,187,218,249,279,309,339,368,397,426,454,
//482,509,536,562,588,613,637,661,685,707,729,750,771,790,809,827,
//844,861,876,891,905,918,930,941,951,960,969,976,982,988,992,996,
//998,1000,1000,1000,998,996,992,988,982,976,969,960,951,941,930,918,
//905,891,876,861,844,827,809,790,771,750,729,707,685,661,637,613,
//588,562,536,509,482,454,426,397,368,339,309,279,249,218,187,156,
//125,94,63,31};
u1 n=0; //计数计时
u1 time=0;
u1 fangxiang; //高低标志位
u1 gao=0;
sbit PWM=P2^0;
void time0Init()
{
TMOD|=0X01;
TH0=(65536-1)/256;
TL0=(65536-1)%256;
ET0=1;
TR0=1;
EA=1;
}
void main()
{
time0Init(); //t0初始化
while(1)
{
if(n>1000)
{
n=0;
if(fangxiang==0)
gao++;
if(fangxiang==1)
gao--;
}
if(gao==100)
fangxiang=1;
if(gao==0)
fangxiang=0;
if(time>1000) //周期为1000us
time=0;
if(time<tiaozhi[gao])
PWM=1;
else
PWM=0;
}
}
void time0() interrupt 1 //1us
{
TH0=(65536-1)/256;
TL0=(65536-1)%256;
n++;
time++;
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>