当前位置:
文档之家› 51单片机流水灯C语言源代码
51单片机流水灯C语言源代码
for(i=x;i>0;i--)
for(j=250;j>0;j--);
}
void lsd1()//lsd1单个流水灯双程模式1
{
uchar a,i,j,k,l,l1,k1,j1,i1;
a=0xfe;
P0=a;
delay(z);
for(i=0;i<7;i++)//仅单个灯亮从上往下流
{
a=_crol_(a,1);
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;
P3=0xff;
delay(z);
P0=0x00;
P2=0xff;
delay(z);
P0=0xff;
delay(z);
}
void lsd7()//lsd7全亮全灭
{
uchar i;
for(i=0;i<2;i++)
{
P0=0x00;
P1=0x00;
P2=0x00;
P3=0x00;
delay(z);
P0=0xff;
}
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);
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);
P1=0xff;
P2=0xff;
P3=0xff;
delay(z);
}
}
void lsd8()//每组仅两个灯,从中间往两边再往中间
{
uchar i;
for(i=0;i<8;i++)
{
P0=table4[i];
P1=table4[i];
P2=table4[i];
P3=table4[i];
delay(z);
}
void lsd6()//每组为单位同亮同灭从左向右再向左
{
P0=0x00;
delay(z);
P0=0xff;
P2=0x00;
delay(z);
P2=0xff;
P3=0x00;
delay(z);
P3=0xff;
P1=0x00;
delay(z);
P3=0x00;
P1=0xff;
delay(z);
P2=0x00;
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);
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);
void lsd12();
main()
{
while(1)
{
lsd1();
lsd2();
lsd3();
lsd4();
lsd5();
lsd6();
lsd7();
lsd8();
lsd9();
lsd10();
lsd11();
lsd12();
}
}
void delay(uchar x)//延时函数
{
uint i,j;
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);
{
uchar a,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);
}
for(j=0;j<8;j++)//单个灯依次点亮所有灯,从下往上
{
P2=table2[j];
delay(z);
}
a=0xfe;
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);
}
void lsd4()//lsd4
{
uchar a,i,j,k,l,l1,k1,j1,i1;
a=0xfe;
#include<reg52.h>
#include<intrins.h>
#define uint unsigned int
#define uchar unsigned char
uchar z=50,e=0x00,f=0xff;
uchar code table1[]={
0x80,0xc0,0xe0,0xf0,
for(k=0;k<7;k++)
{
a=a<<1;
P3=a;
delay(z);
}
a=0xfe;
P1=a;
delay(z);
for(l=0;l<7;l++)
{
a=a<<1;
P1=a;
delay(z);
}
for(l1=0;l1<8;l1++)//l1==8
{
P1=table1[l1];//单个灯依次熄灭所有灯,从下往上
delay(z);
}
for(k1=0;k1<8;k1++)
{
P3=table1[k1];
delay(z);
}
for(j1=0;j1<8;j1++)
{
P2=table1[j1];
delay(z);
}
for(i1=0;i1<8;i1++)
{
P0=table1[i1];
delay(z);
}
}
void lsd5()//lsd5
for(i1=0;i1<6;i1++)
{
a=_cror_(a,1);
P0=a;
delay(z);
}
P0=0xfe;
delay(z);
P0=0xff;
delay(z);
}
void lsd3()//lsd3两个灯流水双程模式2
{
uchar a,i,j,k,l,l1,k1,j1,i1;
a=0xfe;
P0=a;
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;