#include "reg52.h"
unsigned char smg[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
sbit a=P2^2;
sbit b=P2^3;
sbit c=P2^4;
#define smgled P0
#define keynumber P1
unsigned char backvalue;
void delay(unsigned int i)
{
while(i--);
}
void scan(void)
{
unsigned int k=0;
keynumber=0x0f;
if(keynumber!=0x0f)
{
delay(1000);
keynumber=0x0f;
switch(keynumber)
{
case(0x07):backvalue=0;break;
case(0x0b):backvalue=1;break;
case(0x0d):backvalue=2;break;
case(0x0e):backvalue=3;break;
}
keynumber=0xf0;
switch(keynumber)
{
case(0x70):backvalue=backvalue;break;
case(0xb0):backvalue=backvalue+4;break;
case(0xd0):backvalue=backvalue+8;break;
case(0xe0):backvalue=backvalue+12;break;
}
}
while((k<50)&&(keynumber!=0xf0))
{
delay(1000);
k++;
}
}
void main()
{
a=0;
b=0;
c=0;
while(1)
{
scan();
smgled=smg[backvalue];
}
}
说明:
矩阵按键显示前4位按下点阵显示不同汉字,后12为显示X
|