51单片机的七彩LED灯渐变调光调色程序
//***********************************************************************
//Pattern4() 花样函数4-------------7彩渐变
//***********************************************************************
void Pattern34()
{
Gra = 1; //渐变位 = 1
}
/*********************************************************/
// 定时器0中断服务程序
/*********************************************************/
void time0(void) interrupt 1
{
TR1 =0;
TF0 =0;
TH0=0xdb; //重新写入初值
TL0=0xff;
if(!Gra) //执行跳变程序
{
count ++;
if(count > Speed)
{
LEDdelay = 1;
count = 0;
}
}
if(Gra)
{
TR1 = 1; //开启TR1;
if(!BP) //
{
if(Gra7)
{
P1 = led1[ledcount1]; //10ms到,亮相应的LED
}
if(Gra3)
{
P1 = led3[ledcount1]; //10ms到,亮相应的LED
}
Pulse++;
value();
if(Pulse >= Period)
{
Pulse = Period;
BP = 1; //一个周期完成转换模式
}
}
if(BP)
{
if(Gra7)
{
P1 = led1[ledcount1]; //10ms到,亮相应的LED
}
if(Gra3)
{
P1 = led3[ledcount1]; //10ms到,亮相应的LED
}
value();
Pulse--; //脉冲个数
if(Pulse == 0)
{
Pulse = 0;
BP = 0; //一个周期完成转换模式
ledcount1++;
if(Gra7)
{
if(ledcount1 > 11)
{
ledcount1 = 0;
}
Gra7 = 0;
}
if(Gra3)
{
if(ledcount1 > 2)
{
ledcount1 = 0;
}
Gra3 = 0;
}
}
}
}
}
/*********************************************************/
// 定时器1中断服务程序
/*********************************************************/
void timer1() interrupt 3
{
PWM --;
TH1 = 0xff; //0.05ms(20000分之一秒)
TL1 = 0xD1;
if(PWM == 0)
{
P1 = 0;
TR1 = 0;
}
}
/*********************************************************/
// 外部中断0中断服务程序 下降沿触发
/*********************************************************/
void extern0(void) interrupt 0
{
IE0 = 0; // 清标志位
excount++;
if(excount>50) // 50大约3秒
{
EA = 0;
//P1_5 = 1;
excount = 0;
Reset();
}
}
评论