#include<STC15.H>
#define GPIO_DIG P0
#define GPIO_KEY P2
unsigned char code DSY_BUF[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,
0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
unsigned char KeyValue;
void KeyDown();
void delayms(unsigned char z )
{
unsigned char i,j;
for(i=z;i>0;i--)
for(j=115;j>0;j--);
}
void main()
{
while(1)
{
KeyDown();
GPIO_DIG =~DSY_BUF[KeyValue];
}
}
void KeyDown(void)
{
char a = 0;
GPIO_KEY=0x0f;
if(GPIO_KEY!=0x0f)
{
delayms(10);
if(GPIO_KEY!=0x0f)
{
GPIO_KEY=0x0f;
switch(GPIO_KEY)
{
case(0X0e):KeyValue=0;break;
case(0X0d):KeyValue=4;break;
case(0X0b):KeyValue=8;break;
case(0X07):KeyValue=12;break;
}
GPIO_KEY=0xf0;
switch(GPIO_KEY)
{
case(0Xe0): KeyValue=KeyValue+0;break;
case(0Xd0): KeyValue=KeyValue+1;break;
case(0Xb0): KeyValue=KeyValue+2;break;
case(0X70): KeyValue=KeyValue+3;break;
}
while((a<50) && (GPIO_KEY!=0xf0))
{
delayms(10);
a++;
}
}
}
} |