#include <reg52.h>
typedef unsigned int u16;
sbit LSA=P2^2;
sbit LSB=P2^3;
sbit LSC=P2^4;
u16 D_tube[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71}; //显示0~F的值
void delay(u16 n)
{
while(n--);
}
void roll(u16 data1,u16 data2)
{
u16 num,i;
for(num=0;num<7;num++)
{
for(i=0;i<10;i++) //移动的速度,可调
{
switch (num)
{
case 0:
LSA=0;LSB=0;LSC=0;break;
case 1:
LSA=1;LSB=0;LSC=0;break;
case 2:
LSA=0;LSB=1;LSC=0;break;
case 3:
LSA=1;LSB=1;LSC=0;break;
case 4:
LSA=0;LSB=0;LSC=1;break;
case 5:
LSA=1;LSB=0;LSC=1;break;
case 6:
LSA=0;LSB=1;LSC=1;break;
case 7:
LSA=1;LSB=1;LSC=1;break;
}
P0=D_tube[data1];
delay(1000);
P0=0x00;
num+=1;
switch (num)
{
case 0:
LSA=0;LSB=0;LSC=0;break;
case 1:
LSA=1;LSB=0;LSC=0;break;
case 2:
LSA=0;LSB=1;LSC=0;break;
case 3:
LSA=1;LSB=1;LSC=0;break;
case 4:
LSA=0;LSB=0;LSC=1;break;
case 5:
LSA=1;LSB=0;LSC=1;break;
case 6:
LSA=0;LSB=1;LSC=1;break;
case 7:
LSA=1;LSB=1;LSC=1;break;
}
P0=D_tube[data2];
delay(1000);
num--;
}
}
}
void bomb()
{
u16 i;
for(i=0;i<8;i++)
{
switch (i)
{
case 0:
LSA=0;LSB=0;LSC=0;break;
case 1:
LSA=1;LSB=0;LSC=0;break;
case 2:
LSA=0;LSB=1;LSC=0;break;
case 3:
LSA=1;LSB=1;LSC=0;break;
case 4:
LSA=0;LSB=0;LSC=1;break;
case 5:
LSA=1;LSB=0;LSC=1;break;
case 6:
LSA=0;LSB=1;LSC=1;break;
case 7:
LSA=1;LSB=1;LSC=1;break;
}
P0=0x7f;
delay(100);
}
}
void main()
{
u16 data1=1; //data1:右边一位显示的数字,可改变
u16 data2=2; //data1:左边一位显示的数字
roll(data1,data2);
while(1)
bomb();
}
|