-
Notifications
You must be signed in to change notification settings - Fork 0
/
Keypad_Prog.c
138 lines (108 loc) · 1.86 KB
/
Keypad_Prog.c
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#include "types.h"
#include "utl.h"
#include "DIO_Config.h"
#include "DIO_Interface.h"
#include "Keypad_Config.h"
#include "Keypad_Interface.h"
extern u8 Keypad_Read(u8 *keypad_value)
{
u8 PtrValue=0,keypad_value2=0;
for (u8 i=Row_A; i<=Row_D; i++)
{
DIO_WritePin(Row_A, LOW);
DIO_WritePin(Row_B, LOW);
DIO_WritePin(Row_C, LOW);
DIO_WritePin(Row_D, LOW);
DIO_WritePin(i, HIGH);
for (u8 j=Col_1; j<=Col_4; j++)
{
PtrValue=0;
DIO_ReadPin(j, &PtrValue);
if (PtrValue==1)
{
Keypad_Char(i, j, &keypad_value2);
*keypad_value=keypad_value2;
return OK;
}
}
}
return Not_Available;
}
extern u8 Keypad_Char(u8 i, u8 j, u8 *keypad_value2)
{
switch (i)
{
case Row_A:
switch (j)
{
case Col_1:
*keypad_value2=Num_7;
break;
case Col_2:
*keypad_value2=Num_8;
break;
case Col_3:
*keypad_value2=Num_9;
break;
case Col_4:
*keypad_value2=Div;
break;
}
break;
case Row_B:
switch (j)
{
case Col_1:
*keypad_value2=Num_4;
break;
case Col_2:
*keypad_value2=Num_5;
break;
case Col_3:
*keypad_value2=Num_6;
break;
case Col_4:
*keypad_value2=Mult;
break;
}
break;
case Row_C:
switch (j)
{
case Col_1:
*keypad_value2=Num_1;
break;
case Col_2:
*keypad_value2=Num_2;
break;
case Col_3:
*keypad_value2=Num_3;
break;
case Col_4:
*keypad_value2=Min;
break;
}
break;
case Row_D:
switch (j)
{
case Col_1:
*keypad_value2=ON_C;
break;
case Col_2:
*keypad_value2=Num_0;
break;
case Col_3:
*keypad_value2=Equal;
break;
case Col_4:
*keypad_value2=Plus;
break;
}
break;
default:
return ERROR;
break;
}
return OK;
}