51单片机流水灯C语言源代码.docx
《51单片机流水灯C语言源代码.docx》由会员分享,可在线阅读,更多相关《51单片机流水灯C语言源代码.docx(22页珍藏版)》请在冰豆网上搜索。
51单片机流水灯C语言源代码
#include
#include
#defineuintunsignedint
#defineucharunsignedchar
ucharz=50,e=0x00,f=0xff;
ucharcodetable1[]={
0x80,0xc0,0xe0,0xf0,
0xf8,0xfc,0xfe,0xff};
ucharcodetable2[]={
0x7f,0x3f,0x1f,0x0f,
0x07,0x03,0x01,0x00};
ucharcodetable3[]={
0x01,0x03,0x07,0x0f,
0x1f,0x3f,0x7f,0xff};
ucharcodetable4[]={
0xe7,0xdb,0xbd,0x7e,
0xbd,0xdb,0xe7,0xff};
ucharcodetable5[]={
0xe7,0xc3,0x81,0x00,
0x81,0xc3,0xe7,0xff};
ucharcodetable6[]={
0x7e,0x3c,0x18,0x00,
0x18,0x3c,0x7e,0xff};
voiddelay(uchar);
voidlsd1();
voidlsd2();
voidlsd3();
voidlsd4();
voidlsd5();
voidlsd6();
voidlsd7();
voidlsd8();
voidlsd9();
voidlsd10();
voidlsd11();
voidlsd12();
main()
{
while
(1)
{
lsd1();
lsd2();
lsd3();
lsd4();
lsd5();
lsd6();
lsd7();
lsd8();
lsd9();
lsd10();
lsd11();
lsd12();
}
}
voiddelay(ucharx)//延时函数
{
uinti,j;
for(i=x;i>0;i--)
for(j=250;j>0;j--);
}
voidlsd1()//lsd1单个流水灯双程模式1
{
uchara,i,j,k,l,l1,k1,j1,i1;
a=0xfe;
P0=a;
delay(z);
for(i=0;i<7;i++)//仅单个灯亮从上往下流
{
a=_crol_(a,1);
P0=a;
delay(z);
}
P0=0xff;
a=0xfe;
P2=a;
delay(z);
for(j=0;j<7;j++)
{
a=_crol_(a,1);
P2=a;
delay(z);
}
P2=0xff;
a=0xfe;
P3=a;
delay(z);
for(k=0;k<7;k++)
{
a=_crol_(a,1);
P3=a;
delay(z);
}
P3=0xff;
a=0xfe;
P1=a;
delay(z);
for(l=0;l<7;l++)
{
a=_crol_(a,1);
P1=a;
delay(z);
}
a=0xbf;
P1=a;
delay(z);
for(l1=0;l1<6;l1++)//l1==6仅单个灯亮从下往上流
{
a=_cror_(a,1);
P1=a;
delay(z);
}
P1=0xff;
a=0x7f;
P3=a;
delay(z);
for(k1=0;k1<7;k1++)
{
a=_cror_(a,1);
P3=a;
delay(z);
}
P3=0xff;
a=0x7f;
P2=a;
delay(z);
for(j1=0;j1<7;j1++)
{
a=_cror_(a,1);
P2=a;
delay(z);
}
P2=0xff;
a=0x7f;
P0=a;
delay(z);
for(i1=0;i1<7;i1++)
{
a=_cror_(a,1);
P0=a;
delay(z);
}
P0=0xff;
}
voidlsd2()//lsd2两个灯流水双程模式1
{
uchara,i,j,k,l,l1,k1,j1,i1;
a=0xfe;
P0=a;
delay(z);
a=a<<1;
P0=a;
delay(z);
for(i=0;i<6;i++)
{
a=_crol_(a,1);
P0=a;
delay(z);
}
P0=0x7f;
P2=0xfe;
delay(z);
P0=0xff;
a=0xfc;
P2=a;
delay(z);
for(j=0;j<6;j++)
{
a=_crol_(a,1);
P2=a;
delay(z);
}
P2=0x7f;
P3=0xfe;
delay(z);
P2=0xff;
a=0xfc;
P3=a;
delay(z);
for(k=0;k<6;k++)
{
a=_crol_(a,1);
P3=a;
delay(z);
}
P3=0x7f;
P1=0xfe;
delay(z);
P3=0xff;
a=0xfc;
P1=a;
delay(z);
for(l=0;l<6;l++)
{
a=_crol_(a,1);
P1=a;
delay(z);
}
P1=0x7f;
delay(z);
P1=0xff;
delay(z);
a=0x7f;
P1=a;
delay(z);
a=a>>1;
P1=a;
delay(z);
for(l1=0;l1<6;l1++)
{
a=_cror_(a,1);
P1=a;
delay(z);
}
P1=0xfe;
P3=0x7f;
delay(z);
P1=0xff;
a=0x3f;
P3=a;
delay(z);
for(k1=0;k1<6;k1++)
{
a=_cror_(a,1);
P3=a;
delay(z);
}
P3=0xfe;
P2=0x7f;
delay(z);
P3=0xff;
a=0x3f;
P2=a;
delay(z);
for(j1=0;j1<6;j1++)
{
a=_cror_(a,1);
P2=a;
delay(z);
}
P2=0xfe;
P0=0x7f;
delay(z);
P2=0xff;
a=0x3f;
P0=a;
delay(z);
for(i1=0;i1<6;i1++)
{
a=_cror_(a,1);
P0=a;
delay(z);
}
P0=0xfe;
delay(z);
P0=0xff;
delay(z);
}
voidlsd3()//lsd3两个灯流水双程模式2
{
uchara,i,j,k,l,l1,k1,j1,i1;
a=0xfe;
P0=a;
delay(z);
a=a<<1;
P0=a;
delay(z);
for(i=0;i<6;i++)//_crol_与_cror_混合使用
{
a=_crol_(a,1);
P0=a;
delay(z);
}
P0=0x7f;
a=0x7f;
P2=a;
delay(z);
P0=f;
a=a>>1;
P2=a;
delay(z);
for(j=0;j<6;j++)
{
a=_cror_(a,1);
P2=a;
delay(z);
}
P2=0xfe;
a=0xfe;
P3=a;
delay(z);
P2=f;
a=a<<1;
P3=a;
delay(z);
for(k=0;k<6;k++)
{
a=_crol_(a,1);
P3=a;
delay(z);
}
P3=0x7f;
a=0x7f;
P1=a;
delay(z);
P3=f;
a=a>>1;
P1=a;
delay(z);
for(l=0;l<6;l++)
{
a=_cror_(a,1);
P1=a;
delay(z);
}
P1=0xfe;
delay(z);
P1=f;
delay(z);
a=0xfe;
P1=a;
delay(z);
a=a<<1;
P1=a;
delay(z);
for(l1=0;l1<6;l1++)//l1==6
{
a=_crol_(a,1);
P1=a;
delay(z);
}
P1=0x7f;
a=0x7f;
P3=a;
delay(z);
P1=f;
a=a>>1;
P3=a;
for(k1=0;k1<6;k1++)
{
a=_cror_(a,1);
P3=a;
delay(z);
}
P3=0xfe;
a=0xfe;
P2=a;
delay(z);
P3=f;
a=a<<1;
P2=a;
delay(z);
for(j1=0;j1<6;j1++)
{
a=_crol_(a,1);
P2=a;
delay(z);
}
P2=0x7f;
a=0x7f;
P0=a;
delay(z);
P2=f;
a=a>>1;
P0=a;
delay(z);
for(i1=0;i1<6;i1++)
{
a=_cror_(a,1);
P0=a;
delay(z);
}
P0=0xfe;
delay(z);
P0=f;
delay(z);
}
voidlsd4()//lsd4
{
uchara,i,j,k,l,l1,k1,j1,i1;
a=0xfe;
P0=a;
delay(z);
for(i=0;i<7;i++)
{
a=a<<1;//单个灯依次点亮所有灯,从上往下
P0=a;
delay(z);
}
a=0xfe;
P2=a;
delay(z);
for(j=0;j<7;j++)
{
a=a<<1;
P2=a;
delay(z);
}
a=0xfe;
P3=a;
delay(z);
for(k=0;k<7;k++)
{
a=a<<1;
P3=a;
delay(z);
}
a=0