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
| // Defining the keypad settings
#define nCols 3
#define nRows 4
#define MsgLength 16
// Defining the messages for each button
char MsgTbl[nCols][nRows][MsgLength] = {
// FIRST COLUMN
{"MESSAGE: C=0 R=0", // button 1
"MESSAGE: C=0 R=1", // button 4
"MESSAGE: C=0 R=2", // button 7
"MESSAGE: C=0 R=3" // button *
},
// SECOND COLUMN
{"MESSAGE: C=1 R=0", // button 2
"MESSAGE: C=1 R=1", // button 5
"MESSAGE: C=1 R=2", // button 8
"MESSAGE: C=1 R=3" // button 0
},
// THIRD COLUMN
{"MESSAGE: C=2 R=0", // button 3
"MESSAGE: C=2 R=1", // button 6
"MESSAGE: C=2 R=2", // button 9
"MESSAGE: C=2 R=3" // button #
}
}
/* The next code is for the ISR routine */
char sel_COL, sel_ROW;
// assuming the variables for the keypad pins are named COL_0 .. 2 and ROW_0 .. 3
if (COL_0) sel_COL=0; //
if (COL_1) sel_COL=1; // reading the selected column
if (COL_2) sel_COL=2; //
if (ROW_0) sel_ROW=0; //
if (ROW_1) sel_ROW=1; // reading the selected row
if (ROW_2) sel_ROW=2; //
if (ROW_3) sel_ROW=3; //
/* the next code is to be used in your main() function or wherever you need it
to print the message corresponding to the selected row and column print the
text contained in:
MsgTbl[sel_COL][sel_ROW]
for example, with printf:
printf("%s", MsgTbl[sel_COL][sel_ROW]);
if you want to "clear" or "enter" (special key commands) you might want to
check for the selected row and column and if a particular configuration is
met, do something else than printing the message (whatever you want to do)
Example code:
*/
if ((sel_COL == 0) && (sel_ROW == 3)){
// * pressed
printf("%s", "The * key has been pressed");
} else if ((sel_COL == 2) && (sel_ROW == 3)){
// # pressed
printf("%s", "The # key has been pressed");
} else {
// any other key has been pressed, print the corresponding message
printf("%s", MsgTbl[sel_COL][sel_ROW]);
} |