1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
| /*----------------------------------------
File: key44.h
Date:Loser007 May 5, 2018 12:59
----------------------------------------*/
#ifndef __KEY44_H__
#define __KEY44_H__
#pragma SAVE
#pragma REGPARMS
extern char Matrix_keyboard(void);
/*----------------------------------------
Name: Matrix_keyboard
Features: Get a case from the 4*4 keyboard
Parameter: No
Return:Key code (char)
Instructions:Keyboard I/0 From P1^0 to P1^7
Date:Loser007 May 5, 2018 10:40
----------------------------------------*/
char Matrix_keyboard(void)
{
unsigned char Key = 0, X = 0, Y = 0;
P1 = 0xF0; //11110000
X = P1 & 0xF0; //Get row (P1 XOR 11110000) Get Height
if(X != 0xF0)
{
X = P1 ^ 0xF0;
P1 = 0x0F; //00001111
Y = P1 & 0x0F;
if(Y != 0x0F)
{
Y = P1 ^ 0x0F; //Get Column (P1 XOR 00001111) Get Low
Key = X + Y;
}
}
switch (Key)
{
// 1
case 0x81:
return 0; //1000 0001
case 0x82:
return 1; //1000 0010
case 0x84:
return 2; //1000 0100
case 0x88:
return 3; //1000 1000
// 2
case 0x41:
return 4; //0100 0001
case 0x42:
return 5; //0100 0010
case 0x44:
return 6; //0100 0100
case 0x48:
return 7; //0100 1000
// 3
case 0x21:
return 8; //0010 0001
case 0x22:
return 9; //0010 0010
case 0x24:
return 10; //0010 0100
case 0x28:
return 11; //0010 1000
//4
case 0x11:
return 12; //0001 0001
case 0x12:
return 13; //0001 0010
case 0x14:
return 14; //0001 0100
case 0x18:
return 15; //0001 1000
default:
return 255;
}
}
#endif
|