#include
#define uchar unsigned char
uchar code tab1[]={0x88,0Xbe,0Xc4,0X94,0Xb2,0X91,0X81,0Xbc,
0X80,0X90,0xff,0xfe}; //0~f字型码表
sbit lv=P2^7;
sbit hong=P2^5;
sbit qd=P3^3;
sbit zy=P2^1;
sbit yy=P2^2;
void delay(uchar x) //毫秒级延时函数
{
uchar y;
for(;x>0;x--)
for(y=110;y>0;y--);
}
scanf() //按键处理函数
{
uchar temp,temp1,i;
P0=0xf0; //给P0口赋值为oxf0,用于列扫描
if(P0!=0xf0) //判别是否有键按下
{
delay(2);
if(P0!=0xf0) //再次判别是否有键按下
{
temp1=P0; //P0值赋给temp1
P0=0x0f; //P0值赋为0x0f,用于行扫描
temp=temp1|P0; //将行列扫描值合并,赋给temp
}
switch(temp)
{
case 0xee:i=1; break;
case 0xed:i=2; break;
case 0xeb:i=3; break;
case 0xe7:i=4; break;
case 0xde:i=5; break;
case 0xdd:i=6; break;
case 0xdb:i=7; break;
case 0xd7:i=8; break;
case 0xbe:i=9; break;
case 0xbd:i=0; break;
}
}
else return 10;
return i;
}
void main(void) //主函数
{
uchar x,i,f=0,k=3;
uchar zhi[6]={10,10,10,10,10,10};
uchar zhi1[6]={6,5,4,3,2,1};
while(1)
{
for(i=0;i<6;i++)
{ if(x==i)SBUF=tab1[11];
else SBUF=tab1[zhi[ i]];
while(!TI);
TI=0;
} delay(200);
for(i=0;i<6;i++)
{
SBUF=tab1[zhi[ i]];
while(!TI);
TI=0;
} delay(200);
if(x<6&&k)
{ if(scanf()<10)
{
delay(10);
if(scanf()<10)
{
if(x==0){zhi[0]=scanf();while(scanf()!=10);}
if(x==1){zhi[1]=scanf();while(scanf()!=10);}
if(x==2){zhi[2]=scanf();while(scanf()!=10);}
if(x==3){zhi[3]=scanf();while(scanf()!=10);}
if(x==4){zhi[4]=scanf();while(scanf()!=10);}
if(x==5){zhi[5]=scanf();while(scanf()!=10);}
x++;
}
}
}
if(yy==0)
{
delay(5);
if(yy==0)
{
while(zy==0);
x++;
if(x==6)x=0;
}
}
if(zy==0)
{
delay(5);
if(zy==0)
{
while(yy==0);
if(x==0)x=6;
x--;
}
}
while(f);
while(!k);
if(qd==0)
{
delay(5);
if(x==6&&qd==0)
{
if(zhi[0]==zhi1[0]&&zhi[1]==zhi1[1]&&zhi[2]==zhi1[2]&&zhi[3]==zhi1[3]&&zhi[4]==zhi1[4]&&zhi[5]==zhi1[5])
{
lv=0;
hong=1;
P0=0xff;
for(i=0;i<6;i++)zhi[ i]=8;f=1;
}
else
{
hong=0;
k--;
x=0;P0=0xff;
for(i=0;i<6;i++)zhi[ i]=10;
}
}
}
}
}