#include<reg52.h>
#include<intrins.h>
typedef unsigned int u16;
typedef unsigned char u8;
int math;
u8 a;
#define GPIO_DIG P0
#define GPIO_KEY P1
sbit LSA=P2^2;
sbit LSB=P2^3;
sbit LSC=P2^4;
unsigned char code x[10]={0x3f,0x06,0x5b,0x4f,0x66,
0x6d,0x7d,0x07,0x7f,0x6f};
void delay(int s)
{
int i,k;
for(k=0; k<s;k++)
{
for(i=0;i<50;i++);
}
}
u8 KeyValue;
void KeyDown()
{
char a=0;
GPIO_KEY=0x0f;
if(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((a<50)&&(GPIO_KEY!=0xf0))
{
delay(100);
a++;
}
}
}
void main()
{
while(1)
{
KeyDown();
LSA=0;LSB=0;LSC=0;
GPIO_DIG=x[KeyValue];
}
}
void hh(u16 m)
{
switch(KeyValue)
{
case(1):m = 0x3f;break;
case(2):m = 0x06;break;
case(3):m = 0x5b;break;
case(4):m = 0x4f;break;
case(5):m = 0x66;break;
case(6):m = 0x6d;break;
case(7):m = 0x7d;break;
case(8):m = 0x07;break;
case(9):m = 0x7f;break;
case(10):m = 0x6f;break;
}
}
还应该写什么
|