-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLED_MODULE.s
More file actions
169 lines (118 loc) · 4.07 KB
/
LED_MODULE.s
File metadata and controls
169 lines (118 loc) · 4.07 KB
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
; Amaar Ebrahim
; Utilities module for the LED
GET GPIO_ADR.s
AREA CLOCK_MODULE, CODE, READONLY
THUMB
ENTRY
IMPORT TURN_ON_CLOCK
;-----------------------------------------------------------------------
; Sets up the LEDs
;-----------------------------------------------------------------------
EXPORT SET_UP_LEDS
SET_UP_LEDS PROC
PUSH {R0, LR}
;PUSH {LR}
MOV R0, #2_1000 ; configuration to turn on the the clock for GPIOD
BL TURN_ON_CLOCK ; call TURN_ON_CLOCK
BL CONFIG_MODE ; make the leds output
POP {R0, LR}
ENDP
;-----------------------------------------------------------------------
; sets the mode of GPIOD pins 12 - 15 to output.
;-----------------------------------------------------------------------
EXPORT CONFIG_MODE
CONFIG_MODE PROC
PUSH {R0, R1}
LDR R0, =GPIOD ; load GPIOD's address into r0
LDR R1, [R0] ; load GPIOD's value into r1.
MOVT R1, #0x5500 ; set the mode of pins 12 - 15 to output
STR R1, [R0] ; make the changes take effect
POP {R0, R1}
BX LR ; exit
ENDP
; ------------------------------------------------------------
; Turns on or off the LEDs controlled by pins 12 - 15 of GPIOD
; @param (R0): a 4 bit number. Bit 0 corresponds to the yellow LED
; Bit 1 correponds to the green LED. Bit 2 corresponds to the
; red LED. Bit 3 corresponds to the blue LED.
; Example: 0x0000_000F means turn on all LEDs
; ------------------------------------------------------------
EXPORT SET_LEDS
SET_LEDS PROC
PUSH {R1, R2}
; clear bits 12 - 15 of the output LED pins
LDR R1, =GPIOD
LDRH R2, [R1, #GPIO_ODR]
BIC R2, #0XF000
LSL R3, R0, #12 ; shift R0 by 12 bits, to align it with GPIOD's pins
; put the new LED states into r2
ORR R2, R3
; write r2 to the pins
STR R2, [R1, #GPIO_ODR]
POP {R1, R2}
BX LR
ENDP
; ------------------------------------------------------------
; Turns on or off the blue LED (pin 15 of GPIOD)
; @param (R0): a 1 bit number. 1 if to turn it on. 0 if to turn
; it off.
; Example: 0x1 means turn on the LED
; ------------------------------------------------------------
EXPORT TOGGLE_BLUE_LED
TOGGLE_BLUE_LED PROC
PUSH {R1, R2}
; clear bit 15 of the output LED pins
LDR R1, =GPIOD
LDRH R2, [R1, #GPIO_ODR]
BIC R2, #0X8000
LSL R3, R0, #15 ; shift R0 by 15 bits, to align it with pin 15 (blue)
; put the new LED states into r2
ORR R2, R3
; write r2 to the pins
STR R2, [R1, #GPIO_ODR]
POP {R1, R2}
BX LR
ENDP
; ------------------------------------------------------------
; Turns on or off the orange LED (pin 13 of GPIOD)
; @param (R0): a 1 bit number. 1 if to turn it on. 0 if to turn
; it off.
; Example: 0x1 means turn on the LED
; ------------------------------------------------------------
EXPORT TOGGLE_ORANGE_LED
TOGGLE_ORANGE_LED PROC
PUSH {R1, R2}
; clear bit 13 of the output LED pins
LDR R1, =GPIOD
LDRH R2, [R1, #GPIO_ODR]
BIC R2, #0X2000
LSL R3, R0, #13 ; shift R0 by 13 bits, to align it with pin 13 (orange)
; put the new LED states into r2
ORR R2, R3
; write r2 to the pins
STR R2, [R1, #GPIO_ODR]
POP {R1, R2}
BX LR
ENDP
; ------------------------------------------------------------
; Turns on or off the green LED (pin 12 of GPIOD)
; @param (R0): a 1 bit number. 1 if to turn it on. 0 if to turn
; it off.
; Example: 0x1 means turn on the LED
; ------------------------------------------------------------
EXPORT TOGGLE_GREEN_LED
TOGGLE_GREEN_LED PROC
PUSH {R1, R2}
; clear bit 12 of the output LED pins
LDR R1, =GPIOD
LDRH R2, [R1, #GPIO_ODR]
BIC R2, #0X1000
LSL R3, R0, #12 ; shift R0 by 12 bits, to align it with pin 12 (green)
; put the new LED states into r2
ORR R2, R3
; write r2 to the pins
STR R2, [R1, #GPIO_ODR]
POP {R1, R2}
BX LR
ENDP
END