我做的呼吸灯为什么不亮啊啊啊啊

2019-07-14 19:50发布

为什么我用PWM做呼吸灯,为什么不亮呢?求教各位大神

#include<reg52.h>
typedef unsigned char uchar;
typedef unsigned int uint;
sbit led0=P0^0;
uint count,time0,time1,DIR;
void unit ( );
void main( ){
unit ( );
count=0;
time0=0;
time1=0;
DIR=0;
while (1){
if(count==100){
count=0;
if(DIR==0)
time1++;
else
time1--;

}
if(time1==1000)
DIR=1;
if(time1==0)
DIR=0;
if(time0==1000)
time0=0;
if(time0<time1)
led0=1;
else
led0=0;
}
}
void unit ( ){
EA=1;
ET0=1;
TMOD=0x01;
TH0=0xFF;
TL0=0xFF;
TR0=1;

}
void zhongduan0( ) interrupt 1  
{
time0++;
count++;
TH0=0xFF;
TL0=0xFF;
}

友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
9条回答
wulinwl
2019-07-15 04:24
//改了4个运算符就可以呼吸了
#include<reg52.h>
typedef unsigned char uchar;
typedef unsigned int uint;
sbit led0=P0^0;
uint count,time0,time1,DIR;
void unit ( );

void main( )
{
        unit ( );
        count=0;
        time0=0;
        time1=0;
        DIR=0;       
        while (1)
        {
                if(count>=100)
                {
                        count=0;
                        if(DIR==0)
                        time1++;
                        else
                        time1--;               
                }
                if(time1>=1000)
                        DIR=1;
                if(time1==0)
                        DIR=0;
                if(time0>=1000)
                        time0=0;
                if(time0<=time1)
                        led0=1;
                else
                        led0=0;
        }
}
void unit ( )
{
        EA=1;
        ET0=1;
        TMOD=0x01;
        TH0=0xFF;
        TL0=0xFF;
        TR0=1;
}

void zhongduan0( ) interrupt 1  
{
        time0++;
        count++;
        TH0=0xFF;
        TL0=0xFF;
}

一周热门 更多>