-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathasm.s43
206 lines (154 loc) · 5.64 KB
/
asm.s43
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
#include "msp430.h" ; #define controlled include file
NAME main ; module name
PUBLIC main, highBytes, lowBytes, beats, ticks, log, logSize, logCurr, logPos, currentBpm ; make the main label vissible
; outside this module
ORG 0FFDAh ; Set interrupt vector for input in P1.
DC16 PORT_1_ISR ; Interrupts generated by Port 1 will
; be serviced by routine which address
; is stored at address 0FFDAh of the
; Interrupt Vector Table (IVT).
ORG 0FFE8h ; vector for TIMER_A0
DC16 TIMER_A0_ISR ; set vector for 'TIMER_A0_ISR' routine
ORG 0FFDEh
DC16 TIMER_A1_ISR
ORG 001980h
; Logging vriables
log DW 0,0,0
ALIGN 1
logSize DB 6
ALIGN 1
logCurr DW 0
logPos DB 0
ALIGN 1
// High Bytes and low bytes for numbers
// 0 1 2 3 4 5 6 7 8 9
highBytes db 0xFC, 0x60, 0xDB, 0xF1, 0x67, 0xB7, 0xBF, 0xE0, 0xFF, 0xF7 ; High Bytes for Numbers
lowBytes db 0x28, 0, 0, 0, 0, 0, 0, 0, 0, 0 ; Low Bytes for Numbers
ORG 0FFFEh
DC16 init ; set reset vector to 'init' label
ORG 01C00H
state db 0
align 1
ticks DW 0 ; TIMER_A0 interrupts counter
beats DW 0
currentBpm DW 0
RSEG CSTACK ; pre-declaration of segment
RSEG CODE ; place program in 'CODE' segment
; IO
EXTERN S1InterruptWithCallback, S2InterruptWithCallback, activateLed1, deactivateLed1
; Timer
EXTERN stopTimer, startTimer, stopTimerA1
; Drawing
EXTERN displayLog, displayOption, displayRead, displayClock, displaybattery, clearHeart
; Setup
EXTERN SetupLCD, SetupPins, UnlockGPIO, SetupInterruptsS1, SetupInterruptsS2, SetupTimer, SetupTimerA1
; transitionHandling
EXTERN handleTransitionS1, handleTransitionS2, handleTransitionTick
init: MOV #SFE(CSTACK), SP ; set up stack
bic.b #00000001b, &P1OUT ; Turn off red and green LEDs
bic.b #10000000b, &P9OUT
call #SetupPins
call #UnlockGPIO
call #SetupLCD
call #SetupInterruptsS1
call #SetupInterruptsS2
call #SetupTimer
call #SetupTimerA1
call #stopTimer
call #stopTimerA1
mov.b #0, state
mov #0, ticks ; Clear intsCounter
mov #0, beats
mov #0, currentBpm
call #displayOption
bic.b #0xFF, &P1IFG ; To erase a flag raised before
; activating the GIE. This help to
; avoid responding to a push on button
; previous to program start.
NOP
main: NOP ; main program
MOV.W #WDTPW+WDTHOLD,&WDTCTL ; Stop watchdog timer
NOP
bis.b #GIE+LPM0, SR ; Enable interrupts and enter Low Power mode 0
; that doesn't disable timers
NOP ; Required after enabling interrupts
jmp main
;Objetivo: Interrupt subroutine para manejar interrupciones en el puerto 1
;Precondiciones: Ninguna
;Postcondiciones: Ninguna
;Autor: Kenneth J. Rosario
;Fecha: 18/abril/2021
PORT_1_ISR:
;bic.b #06h, &P1IE ; Disable interrupt at P1.1, P1.2
call #delay
push R5
push R6
mov #state, R6
mov #handleTransitionS2, R5
call #S2InterruptWithCallback
mov #handleTransitionS1, R5
call #S1InterruptWithCallback
bic.b #0xFF, &P1IFG
pop R6
pop R5
;bis.b #06h, &P1IE ; Enable interrupts at P1.1, P1.2
reti
;Objetivo: Interrupt subroutine para manejar timer a0
;Precondiciones: Ninguna
;Postcondiciones: Ninguna
;Autor: Kenneth J. Rosario
;Fecha: 18/abril/2021
TIMER_A0_ISR: ;After every interrupt increase the intsCounter
push r5
push r6
xor.b #BIT0,&P1OUT ; Toggle P1.0 (Red LED)
inc ticks
mov #state, r6
call #handleTransitionTick
cmp #150, ticks
jge FINISH_TIMER
RETI_TIMER:
pop r6
pop r5
reti
FINISH_TIMER:
call #displayClock
mov #12, state
mov #0, ticks
mov #0, beats
push r12
mov #6, r12
call #displaybattery
call #stopTimer
pop r12
jmp RETI_TIMER
;Objetivo: Interrupt subroutine para manejar timer a1
;Precondiciones: Ninguna
;Postcondiciones: Ninguna
;Autor: Kenneth J. Rosario
;Fecha: 18/abril/2021
TIMER_A1_ISR:
call #clearHeart
call #stopTimerA1
reti
;Objetivo: Subrutina para crear un delay, usando r9 y dandole un valor fijo, y luego llama DEC para bajar hasta 0, en donde se termina el dalay.
;Precondiciones: Ninguna
;Postcondiciones: Ninguna
;Autor: Ebdiel
;Fecha: 10/marzo/2021
break:
ret
delay:
MOV #0x4fff, R9
CALL #decr
JMP break
decr:
CMP #0, R9
JEQ break
DEC R9
JMP decr
// ----------------------------------------------------------------------------
final:
JMP $ ; jump to current location '$'
NOP ; (endless loop)
END