#include<reg52.h>
#include<intrins.h>
#define uchar unsigned char
#define uint unsigned int
sbit DU = P2^6;
sbit WE = P2^7;
uint keyvalue = 13;
//1 2 3 A
uchar code table[]={ 0x06, 0x5b, 0x4f, 0x77,
//4 5 6 B
0x66, 0x6d, 0x7d, 0x7c,
//7 8 9 C
0x07, 0x7f, 0x6f, 0x39,
//- 0 点 D
0x40, 0x3f, 0x80, 0x5e,
//E H L U
0x79, 0x76, 0x38, 0x3e,
//N F 熄灭
0x37, 0x71, 0x00};
//延时函数
void delay(uint z)
{
uint x, y;
for(x=z; x>0; x–)
for(y=114; y>0; y–);
}
//按键扫描
void keyscan()
{
//矩阵键盘
P3 = 0xf0;//1111 0000列扫描
delay(10);//软件消抖
/按键按下会使得P3的值发生改变,先通过比较P3值来
检测是哪一列发生了改变,再将P3值改变进行列扫描,
通过比较P3值来检测是哪一行,最后进行松手检测/
if(P3 != 0xf0)
{
switch(P3)
{
case 0xe0: keyvalue = 0