#include "reg52.h"
#define uchar unsigned char
#define uint unsigned int
sbit h1=P1^4;//键盘第一行
sbit h2=P1^5;//键盘第二行
sbit h3=P1^6;//键盘第三行
sbit h4=P1^7;//键盘第四行
sbit h5=P3^0;//键盘第五行
sbit star=P3^6;//启动按键
sbit ql=P3^7;//清零键
uint code up[]={//上楼
0x0,0x66,0x99,0x19,0x29,0x49,0x89,0xF6,
0x18,0x3C,0x7E,0xFF,0x3C,0x3C,0x3C,0x3C,
0x0,0x26,0x69,0x29,0x27,0x21,0x29,0x26,
0x18,0x3C,0x7E,0xFF,0x3C,0x3C,0x3C,0x3C,
0x0,0x26,0x69,0x29,0x26,0x29,0x29,0x26,
0x18,0x3C,0x7E,0xFF,0x3C,0x3C,0x3C,0x3C,
0x0,0x2F,0x61,0x22,0x22,0x22,0x22,0x22,
0x18,0x3C,0x7E,0xFF,0x3C,0x3C,0x3C,0x3C,
0x0,0x26,0x69,0x28,0x2E,0x29,0x29,0x26,
0x18,0x3C,0x7E,0xFF,0x3C,0x3C,0x3C,0x3C,
0x0,0x2F,0x68,0x28,0x2E,0x21,0x29,0x26,
0x18,0x3C,0x7E,0xFF,0x3C,0x3C,0x3C,0x3C,
0x0,0x22,0x66,0x2A,0x32,0x3F,0x22,0x22,
0x18,0x3C,0x7E,0xFF,0x3C,0x3C,0x3C,0x3C,
0x0,0x26,0x69,0x21,0x26,0x21,0x29,0x26,
0x18,0x3C,0x7E,0xFF,0x3C,0x3C,0x3C,0x3C,
0x0,0x26,0x69,0x21,0x22,0x24,0x28,0x2F,
0x18,0x3C,0x7E,0xFF,0x3C,0x3C,0x3C,0x3C,
0x0,0x22,0x66,0x22,0x22,0x22,0x22,0x27,
0x18,0x3C,0x7E,0xFF,0x3C,0x3C,0x3C,0x3C,
0x0,0x26,0x69,0x29,0x29,0x29,0x29,0x76,
0x18,0x3C,0x7E,0xFF,0x3C,0x3C,0x3C,0x3C,
0x0,0x18,0x24,0x24,0x1C,0x4,0x24,0x18,
0x18,0x3C,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0xdf,0xef,0xf7,0xfb,0xfd,0xfe};
uchar j,key,keyed,temps;
uint i,k,l,m;
bit flag;
void delay(uint z)
{
uchar i;
for(;z>0;z--)
for(i=112;i>0;i--);
}
void move()
{
while(1)
{
if(star==0)
delay(10);
if(star==0||key==keyed)
break;
if(ql==0)
delay(10);
if(ql==0)
{
key=keyed;
break;
}
if(flag==0)
{
for(j=0,m=304-key*16;j<8;j++,m++)
{
P0=hang[j];
P2=up[m];
delay(1);
}
}
else
{
for(j=0,m=304-key*16;j<8;j++,m++)
{
P0=hang[j];
P2=down[m];
delay(1);
}
}
}
if(key>keyed)
{
flag=0;
for(i=304-16*keyed;i>304-16*key;i--)
{
l=i;
for(k=200;k>0;k--)
{
i=l;
for(j=0;j<8;j++,i++)
{
P0=hang[j];
P2=up[i];
delay(1);
}
}
i=l;
}
}
if(key<keyed)
{
flag=1;
for(i=304-16*keyed;i<304-16*key;i++)
{
l=i;
for(k=200;k>0;k--)
{
i=l;
for(j=0;j<8;j++,i++)
{
P0=hang[j];
P2=down[i];
delay(1);
}
}
i=l;
}
}
keyed=key;
}
void main()
{
flag=0;
keyed=0;
while(1)
{
if(flag==0)
{
for(j=0,m=304-keyed*16;j<8;j++,m++)
{
P0=hang[j];
P2=up[m];
delay(1);
}
}
else
{
for(j=0,m=304-keyed*16;j<8;j++,m++)
{
P0=hang[j];
P2=down[m];
delay(1);
}
}
P1=0xff;
h1=0;
temps=P1;
temps=temps&0x0f;
if (temps!=0x0f)
{
delay(10);
temps=P1;
temps=temps&0x0f;
if (temps!=0x0f)
{
temps=P1;
temps=temps&0x0f;
switch(temps)
{
case 0x07:key=0;break;
case 0x0b:key=1;break;
case 0x0d:key=2;break;
case 0x0e:key=3;break;
}
temps=P1;
temps=temps&0x0f;
while(temps!=0x0f)
{
move();
temps=P1;
temps=temps&0x0f;
}
}
}
P1=0xff;
h2=0;
temps=P1;
temps=temps&0x0f;
if (temps!=0x0f)
{
delay(10);
temps=P1;
temps=temps&0x0f;
if(temps!=0x0f)
{
temps=P1;
temps=temps&0x0f;
switch(temps)
{
case 0x07:key=4;break;
case 0x0b:key=5;break;
case 0x0d:key=6;break;
case 0x0e:key=7;break;
}
temps=P1;
temps=temps&0x0f;
while(temps!=0x0f)
{
move();
temps=P1;
temps=temps&0x0f;
}
}
}
P1=0xff;
h3=0;
temps=P1;
temps=temps&0x0f;
if(temps!=0x0f)
{
delay(10);
temps=P1;
temps=temps&0x0f;
if(temps!=0x0f)
{
temps=P1;
temps=temps&0x0f;
switch(temps)
{
case 0x07:key=8;break;
case 0x0b:key=9;break;
case 0x0d:key=10;break;
case 0x0e:key=11;break;
}
temps=P1;
temps=temps&0x0f;
while(temps!=0x0f)
{
move();
temps=P1;
temps=temps&0x0f;
}
}
}
P1=0xff;
h4=0;
temps=P1;
temps=temps&0x0f;
if (temps!=0x0f)
{
delay(10);
temps=P1;
temps=temps&0x0f;
if(temps!=0x0f)
{
temps=P1;
temps=temps&0x0f;
switch(temps)
{
case 0x07:key=12;break;
case 0x0b:key=13;break;
case 0x0d:key=14;break;
case 0x0e:key=15;break;
}
temps=P1;
temps=temps&0x0f;
while(temps!=0x0f)
{
move();
temps=P1;
temps=temps&0x0f;
}
}
}
P1=0xff;
h5=0;
temps=P1;
temps=temps&0x0f;
if (temps!=0x0f)
{
delay(10);
temps=P1;
temps=temps&0x0f;
if(temps!=0x0f)
{
temps=P1;
temps=temps&0x0f;
switch(temps)
{
case 0x07:key=16;break;
case 0x0b:key=17;break;
case 0x0d:key=18;break;
case 0x0e:key=19;break;
}
temps=P1;
temps=temps&0x0f;
while(temps!=0x0f)
{
move();
temps=P1;
temps=temps&0x0f;
}
}
}
h5=1;
}
}