为什么我用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;
}
#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;
}
#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)
{
time0++;
count++;
if(count>=200)
{
count=0;
if(DIR==0)
time1++;
else
time1--;
}
if(time1>=500)
DIR=1;
if(time1==0)
DIR=0;
if(time0>=500)
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;
}
*/
一周热门 更多>