-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSubroutines.inc
324 lines (278 loc) · 6.73 KB
/
Subroutines.inc
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
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
;**************************************************************
;*
;* Subroutine Module
;*
;**************************************************************
;* Notes
;*
;*
;**************************************************************
.DSEG
.CSEG
rjmp IO_SETUP
FORCE_RELEASE:
sbis PIND,TRIGGER ; If trigger is pulled
rjmp FORCE_RELEASE ; Loop
ret
TOP_BUTTON_LOOP:
sbis PIND, BTN_1 ; See if Top Button is still pushed
rjmp TOP_BUTTON_LOOP ; Cycle untill released
ret
BTM_BUTTON_LOOP:
sbis PIND, BTN_2 ; See if Top Button is still pushed
rjmp BTM_BUTTON_LOOP ; Cycle untill released
ret
TRIGGER_LOOP:
sbis PIND, TRIGGER ; See if Top Button is still pushed
rjmp TRIGGER_LOOP ; Cycle untill released
ret
VALID_BURST:
sbrc Optns,3
andi Optns,0b11110000
ret
VALID_BPS:
ldi Temp_1,8 ; This line defines the Min ROF
cp Temp_1,BPS
brsh RESET_BPS
ldi Temp_1,31 ; This line defines the Max ROF
cp Temp_1,BPS
brsh BPS_VALID
RESET_BPS:
ldi Temp_1,8
mov BPS,Temp_1
BPS_VALID:
ret
VALID_ACE_DELAY:
ldi Temp_1,9
cp ACEi,Temp_1
brlo DELAY_VALID
clr ACEi
DELAY_VALID:
ret
VALIDATE_FIXi:
mov Temp_1,ROFi
sub Temp_1,SOLi
cp Temp_1,FIXi
brsh FIX_VALIDATED
mov FIXi,Temp_1
FIX_VALIDATED:
ret
;VALID_FIX:
; ldi Temp_1,95
; cp Temp_1,FIXi
; brsh FIX_VALID
; mov FIXi,Temp_1
; FIX_VALID:
; ret
;VALID_DWEL:
; ldi Temp_1,5 ; This line defines the Min Dwell
; cp Temp_1,SOLi
; brsh RESET_DWEL
; ldi Temp_1,30 ; This line defines the Max Dwell
; cp Temp_1,SOLi
; brsh DWEL_VALID
; RESET_DWEL:
; ldi Temp_1,13
; mov SOLi,Temp_1
; DWEL_VALID:
; ret
;RESET_VALUES:
;clr STATE
;ldi Temp_1,8 ; Reset ROF to MIN if out of spec
;mov BPS,Temp_1
;andi Optns,0b11110000
;clr ACEi
;ldi Temp_1,95
;mov FIXi,Temp_1
;ldi Temp_1,13 ; Reset Dwell to 13 if out of spec
;mov SOLi,Temp_1
;ldi Temp_1,0b00011110
;mov DS_BR,Temp_1
;ret
CONVERT_BPS_TO_ROFi:
ldi Temp_1,250
mov Temp_2,BPS
rcall DIVIDE
mov Temp_4,Temp_3
add Temp_1,Temp_1
add Temp_1,Temp_1
rcall DIVIDE
add Temp_4,Temp_4
add Temp_4,Temp_4
add Temp_4,Temp_3
mov ROFi,Temp_4
ret
DIVIDE2:
ldi Temp_2,10
DIVIDE:
;Input
;======
;Temp_1 = Dividend(250 then 4* Remainder)
;Temp_2 = Divisor(8 to 31)
;Output
;======
; Temp_1 = Remainder(Ones)
; Temp_3 = Quotient(Tens)
clr Temp_3
DIVISION:
cp Temp_1,Temp_2
brlo DONE
ONE_MORE:
sub Temp_1,Temp_2
inc Temp_3
rjmp DIVISION
DONE:
ret
BRIGHTNESS_DISPLAY:
ldi ZL,low(2*DSBR) ; Load low part of byte address into ZL
ldi ZH,high(2*DSBR) ; Load high part of byte address into ZH
rcall DISPLAY
ret
DWELL_DISPLAY:
ldi ZL,low(2*Dwell_1) ; Load low part of byte address into ZL
ldi ZH,high(2*Dwell_1) ; Load high part of byte address into ZH
rcall LOAD_CHARACTER ; Load Message to display
mov Temp_1,SOLi
rjmp TWO_DIGIT_DISPLAY
DELAY_DISPLAY:
ldi ZL,low(2*Delay_1) ; Load low part of byte address into ZL
ldi ZH,high(2*Delay_1) ; Load high part of byte address into ZH
rcall LOAD_CHARACTER ; Load Message to display
mov Temp_1,ACEi
rjmp TWO_DIGIT_DISPLAY
BURST_DISPLAY:
ldi ZL,low(2*Burst_0) ; Load low part of byte address into ZL
ldi ZH,high(2*Burst_0) ; Load high part of byte address into ZH
rcall LOAD_CHARACTER ; Load Message to display
ldi Temp_1,0b00000111
and Temp_1,Optns
inc Temp_1
inc Temp_1
rcall TWO_DIGIT_NUMBER
ldi ZL,low(2*Burst_1) ; Load low part of byte address into ZL
ldi ZH,high(2*Burst_1) ; Load high part of byte address into ZH
rcall DISPLAY
ret
FIX_DISPLAY:
ldi ZL,low(2*Menu_4) ; Load low part of byte address into ZL
ldi ZH,high(2*Menu_4) ; Load high part of byte address into ZH
rcall LOAD_CHARACTER ; Load Message to display
mov Temp_1,FIXi
rjmp TWO_DIGIT_DISPLAY
SOLENOID_DISPLAY:
ldi ZL,low(2*Sol_1) ; Load low part of byte address into ZL
ldi ZH,high(2*Sol_1) ; Load high part of byte address into ZH
rcall LOAD_CHARACTER ; Load Message to display
sbrs STATE,SOL ; If ACE is on
rjmp TOGGLE_MENU_OFF
rjmp TOGGLE_MENU_ON
ACE_DISPLAY:
ldi ZL,low(2*Menu_3) ; Load low part of byte address into ZL
ldi ZH,high(2*Menu_3) ; Load high part of byte address into ZH
rcall LOAD_CHARACTER ; Load Message to display
sbrs STATE,ACE ; If ACE is on
rjmp TOGGLE_MENU_OFF
; rjmp TOGGLE_MENU_ON
TOGGLE_MENU_ON:
ldi ZL,low(2*ON) ; Load low part of byte address into ZL
ldi ZH,high(2*ON) ; Load high part of byte address into ZH
rjmp TOGGLE_DISPLAY_END
TOGGLE_MENU_OFF:
ldi ZL,low(2*OFF) ; Load low part of byte address into ZL
ldi ZH,high(2*OFF) ; Load high part of byte address into ZH
TOGGLE_DISPLAY_END:
rcall DISPLAY
ret
ROF_DISPLAY:
ldi ZL,low(2*Menu_2) ; Load low part of byte address into ZL
ldi ZH,high(2*Menu_2) ; Load high part of byte address into ZH
rcall LOAD_CHARACTER ; Load Message to display
mov Temp_1,BPS
rjmp TWO_DIGIT_DISPLAY
MODE_DISPLAY:
;**ZAK KILR*************************************
; ldi Temp_1,0b00001111
; and Temp_1,STATE
; cpi Temp_1, 0b0000111
; brne NORMAL_MOD_DISPLAY
; ldi ZL,low(2*Menu_1c) ; Load low part of byte address into ZL
; ldi ZH,high(2*Menu_1c) ; Load high part of byte address into ZH
; rcall DISPLAY
; clt
; ret
;
;NORMAL_MOD_DISPLAY:
;***********************************************
ldi ZL,low(2*Menu_1) ; Load low part of byte address into ZL
ldi ZH,high(2*Menu_1) ; Load high part of byte address into ZH
rcall LOAD_CHARACTER ; Load Message to display
ldi ZL,low(2*Mode) ; Load low part of byte address into ZL
ldi ZH,high(2*Mode) ; Load high part of byte address into ZH
ldi Temp_1,0b00001111
and Temp_1,STATE
CHARACTER_OFFSET:
cpi Temp_1,0 ; Temp_1 = Number of Loops/Offset
breq OFFSET_FOUND
adiw ZH:ZL,5
dec Temp_1
rjmp CHARACTER_OFFSET
VALUE_OFFSET_1:
cpi Temp_1,0 ; Temp_1 = Number of Loops/Offset
breq OFFSET_FOUND_1
adiw ZH:ZL,2
dec Temp_1
rjmp VALUE_OFFSET_1
OFFSET_FOUND_1:
ret
OFFSET_FOUND:
brts DONT_DISPLAY
rcall DISPLAY ; Load Message to display
DONT_DISPLAY:
clt
ret
CSR:
sbrs Temp_1,0
clc
sbrc Temp_1,0
sec
ror Temp_1
clc
ret
CLEAR_DISPLAY:
ldi ZL,low(2*CLEAR) ; Load low part of byte address into ZL
ldi ZH,high(2*CLEAR) ; Load high part of byte address into ZH
rcall DISPLAY ; Can be commented in this one case
ret
TWO_DIGIT_NUMBER:
rcall DIVIDE2
; Temp_1 = Remainder(Ones)
; Temp_3 = Quotient(Tens)
mov Temp_2,Temp_1
mov Temp_1,Temp_3
rcall TENS_DIGIT
mov Temp_1,Temp_2
rcall ONES_DIGIT
ret
TENS_DIGIT:
ldi ZL,low(2*Number)
ldi ZH,high(2*Number)
rcall VALUE_OFFSET_1
cpi Temp_3,0
brne TENS_LOAD
ldi ZL,low(2*ROF_1)
ldi ZH,high(2*ROF_1)
TENS_LOAD:
rcall LOAD_CHARACTER
ret
ONES_DIGIT:
ldi ZL,low(2*Number)
ldi ZH,high(2*Number)
rcall VALUE_OFFSET_1
rcall LOAD_CHARACTER
ret
TWO_DIGIT_DISPLAY:
rcall TWO_DIGIT_NUMBER
rjmp DISPLAY_ONLY
;EXIT_MENUS:
; sbis PIND,TRIGGER ; If Trigger is pulled
; ret ; Exit Menus