程序是这样的
#include<reg52.h>
typedef unsigned char u8;
typedef unsigned int u16;
sbit LSA = P2^2;
sbit LSB = P2^3;
sbit LSC = P2^4;
#define GPI_DIG=P0;
#define GPI_KEY=P1;
u8 Keynum;
u8 code smgduan[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71
};
void delay(u16 i)
{
while(i--);
}
void Keydown()
{
u8 Keynum;
GPI_KEY=0x0f;
if(GPI_KEY!=0x0f)
{
delay(1000);
if(GPI_KEY!=0x0f)
{
u8 a;
GPI_KEY=0x0f;
switch(GPI_KEY)
{
case(0x0e):Keynum=0; break;
case(0x0d):Keynum=4; break;
case(0x0b):Keynum=8; break;
case(0x07):Keynum=12;break;//na yi hang
}
GPI_KEY=0xf0;
switch(GPI_KEY)
{
case(0xe0):Keynum=Keynum; break;
case(0xd0):Keynum=Keynum+1;break;
case(0xb0):Keynum=Keynum+2;break;
case(0x70):Keynum=Keynum+3;break;//na yi lie
}
while((a<50)&&(GPI_KEY!=0xf0)
{
delay(500);
a++;
}
}
}
}
void main()
{
GPI_DIG=0;
while(1)
{
LSA=0;
LSB=0;
LSC=0;
Keydown();
GPI_DIG=smgduan[Keynum];
}
} |