|
#include<reg52.h>
//#include "MacroAndConst.h"
#define uint unsigned int
#define uchar unsigned char
//#define LED_PWM_LIMIT_MAX 9999
//#define LED_PWM_LIMIT_MIN 0
#define uchar unsigned char
sbit ledr=P1^0;
sbit ledg=P1^1;
sbit ledb=P1^2;
bit LEDDirection=0;//LED控制方向0:漸亮1:漸滅
uchar pwm=0;
uchar pwmr=0;
uchar scw=0;//中斷記數(shù)
uchar tt=0;
//void dealy(uint z);
void Timer0Init(void)
{
TMOD=0x01;
TH0=0xff;
TL0=0x47;
ET0=1;
TR0=1;
EA=1;
}
void main()
{
Timer0Init();
while(1);
}
void Time0Isr(void) interrupt 1
{ static uint
pwm=0;
TH0=0xff;
TL0=0x47;
scw++;
if(scw>100)
{
scw=0;
tt++;
if(tt>5)
{
tt=0;
if((pwmr<=99)&&(0==LEDDirection))
{
pwmr++;
if(pwmr>99)
{
LEDDirection=1;
pwmr=99;
}
}
if((pwmr>=0 )&&(1==LEDDirection))
{
pwmr--;
if(pwmr<0 )
{
LEDDirection=0;
pwmr=0 ;
}
}
}
pwm=pwmr;
}
if(pwm>0)
{
ledr=0;
pwm--;
}
else
{
ledr=1;
}
求大神指點(diǎn),這個(gè)程序先由暗漸變亮,再由亮漸變暗,之后怎么由暗直接變?nèi),是哪里的問題 |
|