-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkeypadScan.s
300 lines (264 loc) · 4.47 KB
/
keypadScan.s
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
INCLUDE core_cm4_constants.s ; Load Constant Definitions
INCLUDE stm32l476xx_constants.s
IMPORT light_update
AREA keypadScan, CODE, READONLY
EXPORT keypad_scan ; make __main visible to linker
ENTRY
keypad_scan PROC
MOV r9, #0x00000FF0
loop
; Set all row outputs to 0
LDR r0, =GPIOB_BASE
LDR r1, [r0, #GPIO_ODR]
BIC r1, #0xE000
STR r1, [r0, #GPIO_ODR]
LDR r0, =GPIOC_BASE
LDR r1, [r0, #GPIO_ODR]
BIC r1, #0x10
STR r1, [r0, #GPIO_ODR]
SUB r9, #1
CMP r9,#0
BEQ return_keypad
BNE keep_going
return_keypad
BX LR
keep_going
MOV r0, #9999
delay1
SUB r0, r0, #1
CMP r0, #0
BNE delay1
; Check if all column inputs are 1
LDR r2, =GPIOB_BASE
MOV r0, #0x1804
LDR r3, [r2, #GPIO_IDR]
AND r3, r0
LDR r2, =GPIOA_BASE
LDR r4, [r2, #GPIO_IDR]
AND r4, #0x800
ADD r5, r4,r3
MOV r0, #0x2004
CMP r5, r0
BEQ loop ; no keys are pressed
BNE testRow1
testRow1
; Set the first row to 0
LDR r0, =GPIOB_BASE
LDR r1, [r0, #GPIO_ODR]
BIC r1, #0xE000
ORR r1, #0xE000
STR r1, [r0, #GPIO_ODR]
LDR r0, =GPIOC_BASE
LDR r1, [r0, #GPIO_ODR]
BIC r1, #0x10
ORR r1, #0x00
STR r1, [r0, #GPIO_ODR]
;software debouncing
MOV r0, #9999
delay2
SUB r0, r0, #1
CMP r0, #0
BNE delay2
; reading col values
LDR r2, =GPIOB_BASE
MOV r0, #0x1804
LDR r3, [r2, #GPIO_IDR]
AND r3, r0
LDR r2, =GPIOA_BASE
LDR r4, [r2, #GPIO_IDR]
AND r4, #0x800
ADD r5, r4,r3
MOV r0, #0x2004
CMP r5, r0
MOV r6, #0x00
; if value is equal that means nothing is being presssed down in row 1
BEQ testRow2
; somthing is being presed in row 1, must check what col it is
BNE testCols
testRow2
; Set the second row to 0
LDR r0, =GPIOB_BASE
LDR r1, [r0, #GPIO_ODR]
BIC r1, #0xE000
ORR r1, #0xC000
STR r1, [r0, #GPIO_ODR]
LDR r0, =GPIOC_BASE
LDR r1, [r0, #GPIO_ODR]
BIC r1, #0x10
ORR r1, #0x10
STR r1, [r0, #GPIO_ODR]
MOV r0, #9999
delay3
SUB r0, r0, #1
CMP r0, #0
BNE delay3
LDR r2, =GPIOB_BASE
MOV r0, #0x1804
LDR r3, [r2, #GPIO_IDR]
AND r3, r0
LDR r2, =GPIOA_BASE
LDR r4, [r2, #GPIO_IDR]
AND r4, #0x800
ADD r5, r4,r3
MOV r0, #0x2004
CMP r5, r0
MOV r6, #0x10
BEQ testRow3
BNE testCols
testRow3
; Set the third row to 0
LDR r0, =GPIOB_BASE
LDR r1, [r0, #GPIO_ODR]
BIC r1, #0xE000
ORR r1, #0xA000
STR r1, [r0, #GPIO_ODR]
LDR r0, =GPIOC_BASE
LDR r1, [r0, #GPIO_ODR]
BIC r1, #0x10
ORR r1, #0x10
STR r1, [r0, #GPIO_ODR]
MOV r4, #9999
delay4
SUB r4, r4, #1
CMP r4, #0
BNE delay4
LDR r2, =GPIOB_BASE
MOV r0, #0x1804
LDR r3, [r2, #GPIO_IDR]
AND r3, r0
LDR r2, =GPIOA_BASE
LDR r4, [r2, #GPIO_IDR]
AND r4, #0x800
ADD r5, r4,r3
MOV r0, #0x2004
CMP r5, r0
MOV r6, #0x20
BEQ testRow4
BNE testCols
testRow4
; Set the third row to 0
LDR r0, =GPIOB_BASE
LDR r1, [r0, #GPIO_ODR]
BIC r1, #0xE000
ORR r1, #0x6000
STR r1, [r0, #GPIO_ODR]
LDR r0, =GPIOC_BASE
LDR r1, [r0, #GPIO_ODR]
BIC r1, #0x10
ORR r1, #0x10
STR r1, [r0, #GPIO_ODR]
MOV r4, #9999
delay5
SUB r4, r4, #1
CMP r4, #0
BNE delay5
LDR r2, =GPIOB_BASE
MOV r0, #0x1804
LDR r3, [r2, #GPIO_IDR]
AND r3, r0
LDR r2, =GPIOA_BASE
LDR r4, [r2, #GPIO_IDR]
AND r4, #0x800
ADD r5, r4,r3
MOV r0, #0x2004
CMP r5, r0
MOV r6, #0x30
BEQ loop
BNE testCols
testCols
testCol1
LDR r2, =GPIOB_BASE
LDR r3, [r2, #GPIO_IDR]
AND r3, #0x4
CMP r3, #0x0
MOV r7, #0x00 ; setting col val for later
BEQ keyPressed ; if CMP is true a col 1 key is pressed
BNE testCol2
; same logic is used just differnt masks
testCol2
LDR r2, =GPIOB_BASE
LDR r3, [r2, #GPIO_IDR]
AND r3, #0x800
CMP r3, #0x000
MOV r7, #0x01
BEQ keyPressed
BNE testCol3
testCol3
LDR r2, =GPIOB_BASE
LDR r3, [r2, #GPIO_IDR]
AND r3, #0x1000
CMP r3, #0x0000
MOV r7, #0x02
BEQ keyPressed
BNE testCol4
testCol4
LDR r2, =GPIOA_BASE
LDR r3, [r2, #GPIO_IDR]
AND r3, #0x800
CMP r3, #0x000
MOV r7, #0x03
BEQ keyPressed
BNE loop
keyPressed
; row and col left bit is row and right bit is col
ADD r8,r6,r7
CMP r8,#0x00
BEQ B1
CMP r8,#0x01
BEQ B2
CMP r8,#0x02
BEQ B3
CMP r8,#0x03
BEQ BA
CMP r8,#0x10
BEQ B4
CMP r8,#0x11
BEQ B5
CMP r8,#0x12
BEQ B6
CMP r8,#0x13
BEQ BB
CMP r8,#0x20
BEQ B7
CMP r8,#0x21
BEQ B8
CMP r8,#0x22
BEQ B9
CMP r8,#0x23
BEQ BC
CMP r8,#0x30
BEQ Bstar
CMP r8,#0x31
BEQ B0
CMP r8,#0x32
BEQ Bhash
CMP r8,#0x33
BEQ BD
; ASCII
B1
ORR r10, #0x00000001
B BD
B2
ORR r10, #0x00000002
B BD
B3
ORR r10, #0x00000004
B BD
B4
ORR r10, #0x00000008
B BD
BA
B5
B6
BB
B7
B8
B9
BC
Bstar
B0
Bhash
BD
BX LR
ENDP
END