-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.s
240 lines (203 loc) · 4.76 KB
/
main.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
INCLUDE core_cm4_constants.s ; Load Constant Definitions
INCLUDE stm32l476xx_constants.s
IMPORT System_Clock_Init
IMPORT UART2_Init
IMPORT USART2_Write
IMPORT hex_update
IMPORT light_update
IMPORT parser
IMPORT floors
IMPORT motor_up
IMPORT motor_down
IMPORT keypad_scan
IMPORT door_open
IMPORT door_close
AREA main, CODE, READONLY
EXPORT __main ; make __main visible to linker
ENTRY
__main PROC
BL System_Clock_Init
BL UART2_Init
clock_init
; Set up all GPIO Clocks - ABCD
LDR r0, =RCC_BASE
LDR r1, [r0, #RCC_AHB2ENR]
BIC r1, #0x0000000F
ORR r1, #0x0000000F
STR r1, [r0, #RCC_AHB2ENR]
LDR r1, [r0, #RCC_APB2ENR]
ORR r1, #RCC_APB2ENR_SYSCFGEN
STR r1, [r0, #RCC_APB2ENR]
hex_init
; Set pins as output
LDR r0, =GPIOA_BASE
LDR r1, [r0, #GPIO_MODER]
BIC r1, #0x0000000F
ORR r1, #0x00000005
STR r1, [r0, #GPIO_MODER]
LDR r0, =GPIOC_BASE
LDR r1, [r0, #GPIO_MODER]
BIC r1, #0x00F00000
ORR r1, #0x00400000
STR r1, [r0, #GPIO_MODER]
LDR r0, =GPIOD_BASE
LDR r1, [r0, #GPIO_MODER]
BIC r1, #0x000000F0
ORR r1, #0x00000010
STR r1, [r0, #GPIO_MODER]
led_init
; Set pins as output
LDR r0, =GPIOC_BASE
LDR r1, [r0, #GPIO_MODER]
BIC r1, #0x0000000F
BIC r1, #0x000000F0
ORR r1, #0x00000005
ORR r1, #0x00000050
STR r1, [r0, #GPIO_MODER]
; Set pins to push pull
LDR r0, =GPIOC_BASE
LDR r1, [r0, #GPIO_OTYPER]
BIC r1, #0xF
STR r1, [r0, #GPIO_OTYPER]
callButton_init
; Set pins as input
LDR r0, =GPIOA_BASE
LDR r1, [r0, #GPIO_MODER]
BIC r1, #0x00000300
STR r1, [r0, #GPIO_MODER]
LDR r0, =GPIOC_BASE
LDR r1, [r0, #GPIO_MODER]
BIC r1, #0x0C000000
STR r1, [r0, #GPIO_MODER]
LDR r0, =GPIOB_BASE
LDR r1, [r0, #GPIO_MODER]
BIC r1, #0x0000C000
BIC r1, #0x00000003
STR r1, [r0, #GPIO_MODER]
; Set pins to pull up
LDR r0, =GPIOC_BASE
LDR r1, [r0, #GPIO_PUPDR]
BIC r1, #0x0C000000
ORR r1, #0x04000000
STR r1, [r0, #GPIO_PUPDR]
LDR r0, =GPIOB_BASE
LDR r1, [r0, #GPIO_PUPDR]
BIC r1, #0x0000C000
BIC r1, #0x00000003
ORR r1, #0x00004000
ORR r1, #0x00000001
STR r1, [r0, #GPIO_PUPDR]
LDR r0, =GPIOA_BASE
LDR r1, [r0, #GPIO_PUPDR]
BIC r1, #0x00000300
ORR r1, #0x00000100
STR r1, [r0, #GPIO_PUPDR]
stepper1_init
; Set pins as output
LDR r0, =GPIOA_BASE
LDR r1, [r0, #GPIO_MODER]
BIC r1, #0x00003000
ORR r1, #0x00001000
STR r1, [r0, #GPIO_MODER]
LDR r0, =GPIOB_BASE
LDR r1, [r0, #GPIO_MODER]
BIC r1, #0x000F0000
ORR r1, #0x00050000
STR r1, [r0, #GPIO_MODER]
LDR r0, =GPIOC_BASE
LDR r1, [r0, #GPIO_MODER]
BIC r1, #0x000C0000
ORR r1, #0x00040000
STR r1, [r0, #GPIO_MODER]
stepper2_init
; Set pins as output
LDR r0, =GPIOA_BASE
LDR r1, [r0, #GPIO_MODER]
BIC r1, #0x30000000
BIC r1, #0x0C000000
ORR r1, #0x10000000
ORR r1, #0x04000000
STR r1, [r0, #GPIO_MODER]
LDR r0, =GPIOC_BASE
LDR r1, [r0, #GPIO_MODER]
BIC r1, #0x03000000
BIC r1, #0x00300000
ORR r1, #0x01100000
STR r1, [r0, #GPIO_MODER]
special_button_init
; Set pins as input
LDR r0, =GPIOC_BASE
LDR r1, [r0, #GPIO_MODER]
BIC r1, #0x00002000
BIC r1, #0x00000C00
STR r1, [r0, #GPIO_MODER]
; Set as "no pull up and no pull down"
LDR r0, =GPIOC_BASE
LDR r1, [r0, #GPIO_PUPDR]
BIC r1, #0x00002000
BIC r1, #0x00000C00
STR r1, [r0, #GPIO_PUPDR]
row_int
;output
;R1 C4,R2 B13, R3 B14, R4 B15
LDR r0, =GPIOB_BASE
LDR r1, [r0, #GPIO_MODER]
BIC r1, #0xFC000000
ORR r1, #0x54000000
STR r1, [r0, #GPIO_MODER]
LDR r0, =GPIOC_BASE
LDR r1, [r0, #GPIO_MODER]
BIC r1, #0x00000300
ORR r1, #0x00000100
STR r1, [r0, #GPIO_MODER]
col_int
;input pull up
;C4 A11, C3 B12, C2 B11, C1 B2
LDR r0, =GPIOB_BASE
LDR r1, [r0, #GPIO_MODER]
BIC r1, #0x03C00000
BIC r1, #0x00000030
STR r1, [r0, #GPIO_MODER]
LDR r1, [r0, #GPIO_PUPDR]
BIC r1, #0x03C00000
BIC r1, #0x00000030
ORR r1, #0x01400000
ORR r1, #0x00000010
STR r1, [r0, #GPIO_PUPDR]
LDR r0, =GPIOA_BASE
LDR r1, [r0, #GPIO_MODER]
BIC r1, #0x00C00000
STR r1, [r0, #GPIO_MODER]
LDR r1, [r0, #GPIO_PUPDR]
BIC r1, #0x00C00000
ORR r1, #0x00400000
STR r1, [r0, #GPIO_PUPDR]
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; --------- Main Program
MOV r10, #0x00000000 ; queue
MOV r11, #0x00000001 ; current floor
BL hex_update
; BL door_open
; BL door_close
myMain
CMP r10, #0x00000000
BNE floors_function
BEQ parser_function
floors_function
B floors
CMP r10, #0xFFFFFFFF
BEQ stop
B myMain
parser_function
B parser
; BL keypad_scan
B myMain
; LDR r0, =str ; First argument
; MOV r1, #11 ; Second argument
; BL USART2_Write
stop B stop ; dead loop & program hangs here
ENDP
ALIGN
AREA myData, DATA, READWRITE
ALIGN
str DCB "ECE202\r\n", 0
END