-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathKeyMatrix.c
121 lines (119 loc) · 2.25 KB
/
KeyMatrix.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
#include <pic.h>
#include "KeyMatrix.h"
//Simple delay
void Key_Delay(int k){
unsigned int i,j;
for (i= 0; i < k; i++)
for(j = 0; j < 100; j++);
}
//Initialise the Keypad
void Init_Keypad(void)
{
PORTC = 0x00;
TRISC = 0xF;
}
//This checks in each row which columns are active and returns a character
int Keypad_Scan(void)
{
row1 = 1; row2 = 0; row3 = 0; row4 = 0;
if(clmn1 == 1)
{
Key_Delay(50);
while(clmn1 == 1)
return 1;
}
if(clmn2 == 1)
{
Key_Delay(50);
while(clmn2 == 1)
return 2;
}
if(clmn3 == 1)
{
Key_Delay(50);
while(clmn3 == 1)
return 3;
}
if(clmn4 == 1)
{
Key_Delay(50);
while(clmn4 == 1)
return 4;
}
row1 = 0; row2 = 1; row3 = 0; row4 = 0;
if(clmn1 == 1)
{
Key_Delay(50);
while(clmn1 == 1)
return 5;
}
if(clmn2 == 1)
{
Key_Delay(50);
while(clmn2 == 1)
return 6;
}
if(clmn3 == 1)
{
Key_Delay(50);
while(clmn3 == 1)
return 7;
}
if(clmn4 == 1)
{
Key_Delay(50);
while(clmn4 == 1)
return 8;
}
row1 = 0; row2 = 0; row3 = 1; row4 = 0;
if(clmn1 == 1)
{
Key_Delay(50);
while(clmn1 == 1)
return 9;
}
if(clmn2 == 1)
{
Key_Delay(50);
while(clmn2 == 1)
return 10;
}
if(clmn3 == 1)
{
Key_Delay(50);
while(clmn3 == 1)
return 11;
}
if(clmn4 == 1)
{
Key_Delay(50);
while(clmn4 == 1)
return 12;
}
row1 = 0; row2 = 0; row3 = 0; row4 = 1;
if(clmn1 == 1)
{
Key_Delay(50);
while(clmn1 == 1)
return 13;
}
if(clmn2 == 1)
{
Key_Delay(50);
while(clmn2 == 1)
return 14;
}
if(clmn3 == 1)
{
Key_Delay(50);
while(clmn3 == 1)
return 15;
}
if(clmn4 == 1)
{
Key_Delay(50);
while(clmn4 == 1)
return 16;
}
return 0;
}