前面一篇文章里我們介紹了單片機遠程同步燈的電路和主程序,地址:http://m.raoushi.com/mcu/1171.html ,根據大家都要求我把燈光效果子程序也在此公開,大家在制作的過程中遇到什么問題可在本文評論中提出,我會盡量為大家解決。
void zhuizhu(void)
{
uchar i;
for(i=0;i<8;i++)
{P0=zhui;delay();}
for(i=0;i<8;i++)
{
if(i+8<12)
P0=zhui;
P1=zhui;
delay();
}
for(i=0;i<13;i++)
{
if(i+8<12)
P1=zhui;
P2=zhui;
delay();
}
P2=0x00;
}
void liushui(void)
{
uchar i,j,k;
P0=0x00;
P1=0x00;
P2=0x00;
delay();
for(i=0;i<8;i++)
{ P0|=SET(i); delay();}
for(j=0;j<8;j++)
{ P1|=SET(j); delay();}
for(k=0;k<8;k++)
{ P2|=SET(k); delay();}
for(k=0;k<8;k++)
{ P2&=CLR_TO_R(k); delay();}
for(j=0;j<8;j++)
{ P1&=CLR_TO_R(j); delay();}
for(i=0;i<8;i++)
{ P0&=CLR_TO_R(i); delay();}
}
void RGBjianbian(void)
{
uchar x;
uchar i,j;
//=================紅燈漸亮又漸暗
for(x=0;x<LOG;x++)
{ for(i=0;i<LOG;i++)
{
P0=0x49;
P1=0x92;
P2=0x24;
}
for(j=0;j<LOG-x;j++)
{
P0=0x00;
P1=0x00;
P2=0x00;
}
} //燈從不亮到最亮
P36=1;
for(x=0;x<LOG;x++)
{ for(i=0;i<LOG;i++)
{
P0=0x00;
P1=0x00;
P2=0x00;
}
for(j=0;j<LOG-x;j++)
{
P0=0x49;
P1=0x92;
P2=0x24;
}
} //從最亮又到暗
P0=0x00;
P1=0x00;
P2=0x00;
//================================
//================綠燈漸亮又漸暗
for(x=0;x<LOG;x++)
{ for(i=0;i<LOG;i++)
{
P0=0x92;
P1=0x24;
P2=0x49;
}
for(j=0;j<LOG-x;j++)
{
P0=0x00;
P1=0x00;
P2=0x00;
}
} //燈從不亮到最亮
for(x=0;x<LOG;x++)
{ for(i=0;i<LOG;i++)
{
P0=0x00;
P1=0x00;
P2=0x00;
}
for(j=0;j<LOG-x;j++)
{
P0=0x92;
P1=0x24;
P2=0x49;
}
}
//==============藍燈變化
P0=0x00;
P1=0x00;
P2=0x00;
for(x=0;x<LOG;x++)
{ for(i=0;i<LOG;i++)
{
P0=0x24;
P1=0x49;
P2=0x92;
}
for(j=0;j<LOG-x;j++)
{
P0=0x00;
P1=0x00;
P2=0x00;
}
} //燈從不亮到最亮
for(x=0;x<LOG;x++)
{ for(i=0;i<LOG;i++)
{
P0=0x00;
P1=0x00;
P2=0x00;
}
for(j=0;j<LOG-x;j++)
{
P0=0x24;
P1=0x49;
P2=0x92;
}
}
P0=0x00;
P1=0x00;
P2=0x00;
}
void shanshuo(void)
{
P0=0x0f;
P1=0x0f;
P2=0x0f;
delay2();
P0=0x00;
P1=0x00;
P2=0x00;
delay2();
P0=0xf0;
P1=0xf0;
P2=0xf0;
delay2();
P0=0x00;
P1=0x00;
P2=0x00;
delay2();
}
void delay2(void)
{
uchar i,j,k;
for(i=0;i<50;i++)
for(j=0;j<80;j++)
for(k=0;k<100;k++)
;
}
void kaolong(void)
{
P0=0x00;
P1=0x00;
P2=0x00;
P0=0x11;
P1=0x81;
P2=0x88;
delay2();
P0=0x22;
P1=0x42;
P2=0x44;
delay2();
P0=0x44;
P1=0x24;
P2=0x22;
delay2();
P0=0x88;
P1=0x18;
P2=0x11;
delay2();
}
void liushui2(void)
{
P0=0x00;
P1=0x00;
P2=0x00;
P0=0x01;
delay();
P0=0x08;
delay();
P0=0x40;
delay();
P0=0x00;
P1=0x02;
delay();
P1=0x10;
delay();
P1=0x80;
delay();
P1=0x00;
P2=0x04;
delay();
P2=0x20;
delay();
P2=0x00; //===================red
P0=0x02;
delay();
P0=0x010;
delay();
P0=0x80;
delay();
P0=0x00;
P1=0x04;
delay();
P1=0x20;
delay();
P1=0x00;
P2=0x01;
delay();
P2=0x08;
delay();
P2=0x40;
delay();
P2=0x00; //===================green
P0=0x04;
delay();
P0=0x20;
delay();
P0=0x00;
P1=0x01;
delay();
P1=0x08;
delay();
P1=0x40;
delay();
P1=0x00;
P2=0x02;
delay();
P2=0x10;
delay();
P2=0x80;
delay();
P2=0x00; //======================blue
}
