关于呼吸灯问题,请教。
时间:10-02
整理:3721RD
点击:
本人是51单片机的初学者,想把家里的电视指示灯,更换成呼吸灯,开机常亮,关机呼吸,现在编程如下(问题是,呼吸状态时,由暗变亮没问题,接着由亮变暗看不到,基本是只有变亮的过程,没有变暗的过程)请大家帮忙分析是哪出问题了:
#include <reg52.h>
#include <intrins.h>
sbit OutPut=P3^0;
unsigned char FLAG0,FLAG1;
void Delay(unsigned int t);
void main()
{
unsigned int CYCLE=1000,PWM_LOW=0;
FLAG0=0;
FLAG1=0;
INT0=1;
IT0=0;
EX0=1;
INT1=1;
IT1=0;
EX1=1;
EA=1;
OutPut=0;
while (1)
{
if(FLAG0==1)
{
OutPut = 1;
Delay(800);
for(PWM_LOW=1;PWM_LOW<CYCLE;PWM_LOW++)
{
OutPut=0;
Delay(PWM_LOW);
OutPut=1;
Delay(CYCLE-PWM_LOW);
}
OutPut=0;
for(PWM_LOW=CYCLE-1;PWM_LOW>0;PWM_LOW--)
{
OutPut=0;
Delay(PWM_LOW);
OutPut=1;
Delay(CYCLE-PWM_LOW);
}
}
else if(FLAG1==1)
{
OutPut=0;
}
}
}
void Delay(unsigned int t)
{
while(--t);
}
void exint0() interrupt 0
{
unsigned int a=0;
FLAG0=0;
for(a=0;a<1000;a++);
if(INT0==1)
{
FLAG1=1;
}
else if(INT0==0)
{
FLAG1=0;
}
}
void exint1() interrupt 2
{
unsigned int b=0;
for(b=0;b<1000;b++);
FLAG1=0;
if(INT1==1)
{
FLAG0=1;
}
else if(INT1==0)
{
FLAG0=0;
}
}
#include <reg52.h>
#include <intrins.h>
sbit OutPut=P3^0;
unsigned char FLAG0,FLAG1;
void Delay(unsigned int t);
void main()
{
unsigned int CYCLE=1000,PWM_LOW=0;
FLAG0=0;
FLAG1=0;
INT0=1;
IT0=0;
EX0=1;
INT1=1;
IT1=0;
EX1=1;
EA=1;
OutPut=0;
while (1)
{
if(FLAG0==1)
{
OutPut = 1;
Delay(800);
for(PWM_LOW=1;PWM_LOW<CYCLE;PWM_LOW++)
{
OutPut=0;
Delay(PWM_LOW);
OutPut=1;
Delay(CYCLE-PWM_LOW);
}
OutPut=0;
for(PWM_LOW=CYCLE-1;PWM_LOW>0;PWM_LOW--)
{
OutPut=0;
Delay(PWM_LOW);
OutPut=1;
Delay(CYCLE-PWM_LOW);
}
}
else if(FLAG1==1)
{
OutPut=0;
}
}
}
void Delay(unsigned int t)
{
while(--t);
}
void exint0() interrupt 0
{
unsigned int a=0;
FLAG0=0;
for(a=0;a<1000;a++);
if(INT0==1)
{
FLAG1=1;
}
else if(INT0==0)
{
FLAG1=0;
}
}
void exint1() interrupt 2
{
unsigned int b=0;
for(b=0;b<1000;b++);
FLAG1=0;
if(INT1==1)
{
FLAG0=1;
}
else if(INT1==0)
{
FLAG0=0;
}
}
见过用LM358搞的呼吸灯 简单