#include "reg51.h"
#define GPIO_KEY P1
typedef unsigned int u16;
typedef unsigned char u8;
u8 code smgduan[17]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
u8 KeyDown(void)
{
u8 KeyValue = 0;
if(GPIO_KEY!=0x0f)
{
GPIO_KEY=0X0F;
switch(GPIO_KEY)
{
case(0X07): KeyValue=0;break;
case(0X0b): KeyValue=1;break;
case(0X0d): KeyValue=2;break;
case(0X0e): KeyValue=3;break;
}
GPIO_KEY = 0xf0;
switch(GPIO_KEY)
{
case(0X70): KeyValue=KeyValue;break;
case(0Xb0): KeyValue=KeyValue+4;break;
case(0Xd0): KeyValue=KeyValue+8;break;
case(0Xe0): KeyValue=KeyValue+12;break;
}
while(GPIO_KEY!=0xf0)
{
}
}
return KeyValue;
}
void timer1Init(void)
{
TMOD |= 0x10;
TH1 = 0xff;
TL1 = 0xff;
TR1 = 1;
ET1 = 1;
EA = 1;
}
void timer1() interrupt 3 using 3
{
static u16 i = 0;
static u8 key = 0;
TH1 = 0xff;
TL1 = 0xff;
GPIO_KEY = 0x0f;
if (GPIO_KEY != 0x0f)
{
i++;
if (i >= 10000)
{
key = KeyDown();
i = 0;
}
}
P0 = ~smgduan[key];
}
int mian(void)
{
timer1Init();
while (1) ;
}
|