cpp
复制代码
#include <reg52.h>
//毫秒级延时函数
void delay(int z)
{
int x,y;
for(x = z; x > 0; x--)
for(y = 114; y > 0 ; y--);
}
sbit LED1 = P1^0x0;
sbit LED2 = P1^0x1;
sbit LED3 = P1^0x2;
sbit LED4 = P1^0x3;
sbit LED5 = P1^0x4;
sbit LED6 = P1^0x5;
sbit LED7 = P1^0x6;
sbit LED8 = P1^0x7;
void show(int num,int state){ //state = 0 是亮 1是不亮
switch(num){
case 1:LED1=state;break;
case 2:LED2=state;break;
case 3:LED3=state;break;
case 4:LED4=state;break;
case 5:LED5=state;break;
case 6:LED6=state;break;
case 7:LED7=state;break;
case 8:LED8=state;break;
}
}
void allshow(int *arr){
int i;
for(i=1;i<=8;i++)
show(i,arr[i-1]);
}
void setArr(int *a,int n1,int n2,int n3,int n4,int n5,int n6,int n7,int n8){
a[0]=n1;a[1]=n2;a[2]=n3;a[3]=n4;a[4]=n5;a[5]=n6;a[6]=n7;a[7]=n8;
}
void main(){
int j,a[8]={0,1,1,1,0,1,1,1},c[8]={1,1,1,1,1,1,1,1,};
short b[4][8]={
1,1,1,1,1,1,1,1,
1,1,1,1,0,0,0,0,
0,0,0,0,1,1,1,1,
1,1,0,0,0,0,1,1,
};
for(;;){
delay(2000);
for(j=0;j<4;j++){
allshow(b[j]);
delay(1000+100*j);
}
allshow(a);
delay(1000);
a[0]=1;
a[4]=1;
a[1]=0;
a[5]=0;
allshow(a);
delay(1000);
a[1]=1;
a[5]=1;
a[2]=0;
a[6]=0;
allshow(a);
delay(1000);
a[2]=1;
a[6]=1;
a[3]=0;
a[7]=0;
allshow(a);
delay(1000);
a[3]=1;
a[7]=1;
allshow(a);
delay(1000);
allshow(c);
delay(1000);
for(j=0;j<8;j++){
c[j]=0;
if(j!=0)
c[j-1]=1;
allshow(c);
delay(1000);
}
c[j-1]=1;
allshow(c);
delay(1000);
for(j=0;j<2;j++){
setArr(c,0,0,1,1,1,1,1,1);
allshow(c);
delay(1000);
setArr(c,1,0,0,1,1,1,1,1);
allshow(c);
delay(1000);
setArr(c,1,1,0,0,1,1,1,1);
allshow(c);
delay(1000);
setArr(c,1,1,1,0,0,1,1,1);
allshow(c);
delay(1000);
setArr(c,1,1,1,1,0,0,1,1);
allshow(c);
delay(1000);
setArr(c,1,1,1,1,1,0,0,1);
allshow(c);
delay(1000);
setArr(c,1,1,1,1,1,1,0,0);
allshow(c);
delay(1000);
setArr(c,0,1,1,1,1,1,1,0);
allshow(c);
delay(1000);
}
setArr(c,1,1,1,1,1,1,1,1);
allshow(c);
delay(1000);
for(j=0;j<2;j++){
setArr(c,0,1,1,1,1,1,1,0);
allshow(c);
delay(500);
setArr(c,0,0,1,1,1,1,0,0);
allshow(c);
delay(500);
setArr(c,0,0,0,1,1,0,0,0);
allshow(c);
delay(500);
setArr(c,0,0,0,0,0,0,0,0);
allshow(c);
delay(1000);
setArr(c,0,0,0,1,1,0,0,0);
allshow(c);
delay(500);
setArr(c,0,0,1,1,1,1,0,0);
allshow(c);
delay(500);
setArr(c,0,1,1,1,1,1,1,0);
allshow(c);
delay(500);
setArr(c,1,1,1,1,1,1,1,1);
allshow(c);
delay(1000);
}
for(j=0;j<5;j++){
setArr(c,0,0,0,0,1,1,1,1);
allshow(c);
delay(500);
setArr(c,1,0,0,0,0,1,1,1);
allshow(c);
delay(500);
setArr(c,1,1,0,0,0,0,1,1);
allshow(c);
delay(500);
setArr(c,1,1,1,0,0,0,0,1);
allshow(c);
delay(500);
setArr(c,1,1,1,1,0,0,0,0);
allshow(c);
delay(500);
setArr(c,0,1,1,1,1,0,0,0);
allshow(c);
delay(500);
setArr(c,0,0,1,1,1,1,0,0);
allshow(c);
delay(500);
setArr(c,0,0,0,1,1,1,1,0);
allshow(c);
delay(500);
}
setArr(c,1,1,1,1,1,1,1,1);
allshow(c);
delay(1000);
}
}