Mercurial > public > mk2
annotate code_part1/OSTC_code_asm_part1/surfmode.asm @ 118:a5eacfafd37f
add p2_deco.o
author | heinrichsweikamp |
---|---|
date | Sun, 26 Dec 2010 17:02:59 +0100 |
parents | 14a074e1a375 |
children | 2907b42c195b |
rev | line source |
---|---|
0 | 1 |
2 ; OSTC - diving computer code | |
3 ; Copyright (C) 2008 HeinrichsWeikamp GbR | |
4 | |
5 ; This program is free software: you can redistribute it and/or modify | |
6 ; it under the terms of the GNU General Public License as published by | |
7 ; the Free Software Foundation, either version 3 of the License, or | |
8 ; (at your option) any later version. | |
9 | |
10 ; This program is distributed in the hope that it will be useful, | |
11 ; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 ; GNU General Public License for more details. | |
14 | |
15 ; You should have received a copy of the GNU General Public License | |
16 ; along with this program. If not, see <http://www.gnu.org/licenses/>. | |
17 | |
18 | |
19 ; routines for Surface mode | |
20 ; written by: Matthias Heinrichs, info@heinrichsweikamp.com | |
21 ; written: 10/01/05 | |
22 ; last updated: 080905 | |
23 ; known bugs: | |
24 ; ToDo: | |
25 | |
26 surfloop: | |
27 ; Boot tasks for all modes | |
28 call restart_set_modes_and_flags ; Sets decomode flags | |
29 clrf lo | |
30 movff lo,char_I_const_ppO2 ; reset to standard mode, OSTC assumes Air breathing at the surface! | |
31 | |
32 call PLED_brightness_full ;max. brightness | |
33 | |
34 call I2CReset | |
35 call enable_rs232 | |
36 call PLED_boot | |
37 call PLED_serial ; Show OSTC serial and firmware version | |
38 call PLED_clock ; display time | |
39 call update_date ; display date | |
40 movff last_surfpressure_30min+0,int_I_pres_respiration+0 ; copy surface air pressure to deco routine | |
41 movff last_surfpressure_30min+1,int_I_pres_respiration+1 ; 30min old values | |
42 movff last_surfpressure_30min+0,int_I_pres_surface+0 ; copy surface air pressure to deco routine | |
43 movff last_surfpressure_30min+1,int_I_pres_surface+1 ; 30min old values | |
44 | |
45 btfsc gauge_mode ; Ignore in gauge mode | |
46 bra surfloop1 | |
47 btfsc FLAG_apnoe_mode ; Ignore in Apnoe mode | |
48 bra surfloop1 | |
49 | |
50 ; Startup tasks for decompression modes | |
43 | 51 call PLED_display_cns_surface ; Update surface CNS display (If allowed by CF15) |
0 | 52 call PLED_desaturation_time ; display desaturation time |
53 call PLED_nofly_time ; display nofly time | |
13 | 54 |
0 | 55 call PLED_active_gas_surfmode ; Show start gas |
56 call PLED_display_decotype_surface ; Show deco mode (ZH-L16, const. ppO2 or Multi-GF) | |
57 | |
58 surfloop1: | |
59 btfss gauge_mode ; Display only in gauge mode | |
60 bra surfloop2 | |
61 DISPLAYTEXT d'103' ; Gauge mode | |
62 surfloop2: | |
63 btfss FLAG_apnoe_mode ; Display only in Apnoe mode | |
64 bra surfloop3 | |
65 DISPLAYTEXT d'116' ; Apnoe mode | |
66 | |
67 surfloop3: | |
68 ; Startup tasks for all modes | |
69 clrf timeout_counter2 | |
70 clrf timeout_counter3 | |
71 bcf premenu ; clear premenu flag | |
72 bcf menubit ; clear menu flag | |
73 bcf pressure_refresh | |
74 clrf last_pressure+0 | |
75 clrf last_pressure+1 | |
76 clrf last_temperature+0 | |
77 clrf last_temperature+1 | |
78 | |
79 movlw d'5' | |
80 movwf timeout_counter ; reload counter | |
81 | |
21 | 82 bcf LED_blue |
83 bcf LED_red | |
0 | 84 bcf simulatormode_active ; Quit simulator mode (if active) |
85 bcf standalone_simulator ; Quit simulator mode (if active) | |
86 WIN_TOP .0 | |
87 WIN_LEFT .0 | |
88 WIN_FONT FT_SMALL | |
89 WIN_INVERT .0 ; Init new Wordprocessor | |
3 | 90 call PLED_standard_color |
91 | |
0 | 92 bcf switch_left |
93 bcf switch_right | |
4 | 94 call PLED_active_gas_surfmode ; Show start gas / SetPoint |
0 | 95 call PLED_custom_text ; Displays custom text |
100 | 96 clrf cf_checker_counter ; next cf to check |
0 | 97 ostc_debug 'G' ; Sends debug-information to screen if debugmode active |
98 GETCUSTOM8 d'12' ; Desaturation multiplier % | |
99 movwf wait_temp | |
100 movff wait_temp,char_I_desaturation_multiplier | |
101 GETCUSTOM8 d'11' ; Saturation multiplier % | |
102 movwf wait_temp | |
103 movff wait_temp,char_I_saturation_multiplier | |
116 | 104 call deco_calc_desaturation_time ; calculate desaturation time |
0 | 105 movlb b'00000001' ; select ram bank 1 |
106 ostc_debug 'H' ; Sends debug-information to screen if debugmode active | |
107 | |
108 call wait_switches ; Waits until switches are released, resets flag if button stays pressed! | |
109 | |
110 surfloop_loop: | |
111 btfss onesecupdate ; do every second tasks? | |
112 bra surfloop_loop2 ; no, loop | |
113 | |
114 btfss FLAG_const_ppO2_mode ; are we in const. ppO2 mode? | |
115 bra surfloop_loop1 ; No | |
116 ; One Second tasks for ppO2 modes | |
117 | |
118 bra surfloop_loop1 ; Do not search for sensor in CC mode | |
119 | |
120 | |
121 surfloop_loop1: | |
122 ; One Second tasks for all modes | |
123 call PLED_clock ; update clock | |
124 call test_charger ; check if charger IC is active | |
125 call timeout_surfmode ; check timeout | |
126 call get_battery_voltage ; get battery voltage | |
127 call update_batt_voltage ; display battery voltage | |
128 call timeout_premenu ; timeout premenu | |
129 call set_leds_surfmode ; Sets Warning and No-Fly LEDs | |
94 | 130 call check_customfunctions ; Checks CF functions and displays warning symbol if something critical is wrong |
0 | 131 call PLED_display_decotype_surface ; Show deco mode |
107 | 132 call surfcustomview_second ; Do every-second tasks for the custom view area |
110 | 133 call dive_type_icons ; Draw Air/Nitrox/Trimix color icon. |
0 | 134 btfsc enter_error_sleep ; Enter Fatal Error Routine? |
86
b40a0a6284da
adding custom functions with limits (jeando)
heinrichsweikamp
parents:
70
diff
changeset
|
135 call fatal_error_sleep ; Yes (In Sleepmode.asm!) |
0 | 136 bcf onesecupdate ; every second tasks done |
137 | |
138 surfloop_loop2: | |
139 ; Tasks approx. every 50ms for all modes | |
140 call test_switches_surfmode ; check switches | |
141 | |
142 ; Sensor tasks for all modes | |
143 btfsc pressure_refresh ; new pressure available? | |
144 call update_surf_press ; display surface pressure | |
145 btfsc pressure_refresh ; new temperature available? | |
146 call PLED_temp_surfmode ; Displays temperature | |
147 btfsc pressure_refresh ; new pressure available? | |
148 call set_dive_modes ; tests if depth>threshold | |
149 bcf pressure_refresh ; until new pressure is available | |
150 | |
151 ; One minute tasks for all modes | |
152 btfsc oneminupdate ; do every minute tasks | |
153 call update_surfloop60 ; yes, e.g. update time and date | |
154 | |
155 ; Mode tasks | |
156 btfsc menubit ; Menu? | |
157 goto menu ; Menu! | |
158 btfsc divemode ; Divemode active? | |
159 goto diveloop ; Yes, switch into Divemode! | |
160 btfsc sleepmode ; Sleepmode active? | |
161 goto sleeploop ; Yes, switch into sleepmode! | |
107 | 162 |
163 btfsc toggle_customview ; Next view? | |
164 call surfcustomview_toggle ; Yes, show next customview (and delete this flag) | |
165 | |
0 | 166 ; Check for the different UART flags |
167 btfsc dump_external_eeprom ; Start interface (dumps EEPROM BANK 0 + additional data)? | |
168 goto menu_interface ; Yes! | |
169 btfsc uart_settime ; Sync clock with PC? | |
170 goto sync_clock ; Yes! | |
171 btfsc internal_eeprom_write ; Access internal EEPROM BANK 0 via UART module | |
172 goto internal_eeprom_access_b0 ; Yes! | |
173 btfsc internal_eeprom_write2 ; Access internal EEPROM BANK 1 via UART module | |
174 goto internal_eeprom_access_b1 ; Yes! | |
175 btfsc uart_send_hash ; Send MD2 hash values | |
176 goto send_md2_hash ; Yes! | |
177 btfsc uart_send_int_eeprom ; Send internal EEPROM BANK 0 | |
178 goto send_int_eeprom_b0 ; Yes! | |
179 btfsc uart_reset_decodata ; Reset Deco Data? | |
180 goto reset_decodata ; Yes! | |
181 btfsc uart_send_int_eeprom2 ; Send internal EEPROM BANK 1 | |
182 goto send_int_eeprom_b1 ; Yes! | |
183 btfsc uart_store_tissue_data ; Store tissue data?` | |
184 goto uart_store_tissues ; Yes! | |
185 | |
186 bra surfloop_loop ; loop surfacemode | |
187 | |
188 | |
189 update_surfloop60: | |
190 ; One minute tasks for all modes | |
4 | 191 ; call PLED_active_gas_surfmode ; Show start gas / SetPoint |
0 | 192 call update_date ; and date in divemode |
193 call calc_deko_surfmode ; calculate desaturation every minute | |
194 call check_temp_extrema ; check for new temperature extremas | |
195 call PLED_custom_text ; Displays custom text | |
196 call calc_surface_interval ; Increases Surface-Interval time | |
107 | 197 call surfcustomview_minute ; Do every-minute tasks for the custom view area |
0 | 198 |
199 btfsc gauge_mode ; Ignore in gauge mode | |
200 bra update_surfloop60_2 | |
201 btfsc FLAG_apnoe_mode ; Ignore in Apnoe mode | |
202 bra update_surfloop60_2 | |
203 | |
204 ; One Minute tasks for deco modes | |
43 | 205 call PLED_display_cns_surface ; Update surface CNS display (If allowed by CF15) |
0 | 206 call PLED_nofly_time ; display nofly time |
207 call PLED_desaturation_time ; display desaturation time | |
13 | 208 btfsc premenu ; Not when "Menu?" is displayed! |
209 bra update_surfloop60_2 | |
210 | |
0 | 211 update_surfloop60_2: |
212 call nofly_timeout60 ; checks if nofly time is > 0 | |
213 bcf oneminupdate | |
214 return | |
215 | |
216 nofly_timeout60: | |
217 bsf nofly_active ; Set flag | |
218 movlw d'1' | |
219 subwf nofly_time+0,F | |
220 movlw d'0' | |
221 subwfb nofly_time+1,F ; reduce by one | |
222 tstfsz nofly_time+0 ; =0? | |
223 return | |
224 tstfsz nofly_time+1 ; =0? | |
225 return | |
226 bcf nofly_active ; Clear flag | |
21 | 227 bcf LED_blue |
0 | 228 incf nofly_time+0,F ; =1 |
229 return | |
230 | |
231 calc_surface_interval: | |
232 movff int_O_desaturation_time+0,lo ; divide by 60... | |
233 movff int_O_desaturation_time+1,hi | |
234 tstfsz lo ;=0? | |
235 bra calc_surface_interval2 ; No | |
236 tstfsz hi ;=0? | |
237 bra calc_surface_interval2 ; No | |
238 clrf surface_interval+0 | |
239 clrf surface_interval+1 ; Clear surface interval timer | |
240 return | |
241 | |
242 calc_surface_interval2: ; Increase surface interval timer | |
243 movlw d'1' | |
244 addwf surface_interval+0,F | |
245 movlw d'0' | |
246 addwfc surface_interval+1,F | |
247 return | |
248 | |
249 set_leds_surfmode: | |
250 btfsc nofly_active | |
21 | 251 btg LED_blue |
0 | 252 return |
253 | |
254 calc_deko_surfmode: | |
21 | 255 bsf LED_red |
0 | 256 ostc_debug 'I' ; Sends debug-information to screen if debugmode active |
257 | |
258 movff last_surfpressure+0,int_I_pres_surface+0 ; copy surface air pressure to deco routine | |
259 movff last_surfpressure+1,int_I_pres_surface+1 | |
260 clrf wait_temp ; Use as buffer | |
261 movff wait_temp,char_I_He_ratio ; No He at the Surface | |
262 movlw d'79' ; 79% N2 | |
263 movwf wait_temp ; Use as buffer | |
264 movff wait_temp,char_I_N2_ratio ; No He at the Surface | |
265 | |
266 movff amb_pressure+0,int_I_pres_respiration+0 ; copy surface air pressure to deco routine | |
267 movff amb_pressure+1,int_I_pres_respiration+1 | |
268 GETCUSTOM8 d'11' ; Saturation multiplier % | |
269 movwf wait_temp | |
270 movff wait_temp,char_I_saturation_multiplier | |
271 GETCUSTOM8 d'12' ; Desaturation multiplier % | |
272 movwf wait_temp | |
273 movff wait_temp,char_I_desaturation_multiplier | |
274 | |
116 | 275 call deco_calc_wo_deco_step_1_min ; calculate deco in surface mode |
0 | 276 movlb b'00000001' ; select ram bank 1 |
277 ostc_debug 'J' ; Sends debug-information to screen if debugmode active | |
21 | 278 bcf LED_red |
0 | 279 return |
280 | |
281 | |
282 test_charger: | |
283 bcf TRISC,1 ; CHRG_OUT output | |
284 bsf CHRG_OUT | |
285 | |
286 bcf cc_active ; Constant Current mode active? | |
287 btfss CHRG_IN ; If CHRG_IN=0 -> CC active | |
288 bsf cc_active ; Constant Current mode Active! | |
289 | |
290 bcf CHRG_OUT | |
291 bsf TRISC,1 ; CHRG_OUT high impedance | |
292 | |
293 WAIT10US d'10' | |
294 | |
295 bcf cv_active ; Constant Voltage mode Active? | |
296 btfss CHRG_IN ; If CHRG_IN=0 -> CV active | |
297 bsf cv_active ; Constant Voltage mode active! | |
298 | |
299 bcf TRISC,1 ; CHRG_OUT output | |
300 bcf CHRG_OUT | |
301 | |
302 btfsc cc_active | |
303 bra show_cc_active | |
304 btfsc cv_active | |
305 bra show_cv_active | |
306 | |
307 bsf TRISC,1 ; CHRG_OUT high impedance | |
308 | |
309 ; Charger inactive or ready | |
310 btfss charge_done ; charge done? | |
311 bra test_charger2 ; No, add incomplete cycle! | |
312 | |
313 ; Yes, store all data for complete cycle | |
314 bcf charge_started ; Clear flag | |
315 bcf charge_done ; Clear flag | |
316 ; Store incomplete/total cycles | |
317 read_int_eeprom d'50' ; Read byte (stored in EEDATA) | |
318 movff EEDATA,temp1 ; Low byte | |
319 read_int_eeprom d'51' ; Read byte (stored in EEDATA) | |
320 movff EEDATA,temp2 ; high byte | |
321 bcf STATUS,C | |
322 movlw d'1' | |
323 addwf temp1 | |
324 movlw d'0' | |
325 addwfc temp2 | |
326 movff temp1,EEDATA | |
327 write_int_eeprom d'50' ; write byte stored in EEDATA | |
328 movff temp2,EEDATA | |
329 write_int_eeprom d'51' ; write byte stored in EEDATA | |
330 | |
331 ; Store complete cycles | |
332 read_int_eeprom d'52' ; Read byte (stored in EEDATA) | |
333 movff EEDATA,temp1 ; Low byte | |
334 read_int_eeprom d'53' ; Read byte (stored in EEDATA) | |
335 movff EEDATA,temp2 ; high byte | |
336 bcf STATUS,C | |
337 movlw d'1' | |
338 addwf temp1 | |
339 movlw d'0' | |
340 addwfc temp2 | |
341 movff temp1,EEDATA | |
342 write_int_eeprom d'52' ; write byte stored in EEDATA | |
343 movff temp2,EEDATA | |
344 write_int_eeprom d'53' ; write byte stored in EEDATA | |
345 ; Store date of complete cycle | |
346 movff month,EEDATA | |
347 write_int_eeprom d'47' | |
348 movff day,EEDATA | |
349 write_int_eeprom d'48' | |
350 movff year,EEDATA | |
351 write_int_eeprom d'49' | |
352 | |
353 return | |
354 | |
355 test_charger2: | |
356 btfss charge_started ; Did the charger ever start? | |
357 return ; No, quit! | |
358 | |
359 bcf charge_started ; Clear flag | |
360 ; Store incomplete/total cycles | |
361 read_int_eeprom d'50' ; Read byte (stored in EEDATA) | |
362 movff EEDATA,temp1 ; Low byte | |
363 read_int_eeprom d'51' ; Read byte (stored in EEDATA) | |
364 movff EEDATA,temp2 ; high byte | |
365 bcf STATUS,C | |
366 movlw d'1' | |
367 addwf temp1 | |
368 movlw d'0' | |
369 addwfc temp2 | |
370 movff temp1,EEDATA | |
371 write_int_eeprom d'50' ; write byte stored in EEDATA | |
372 movff temp2,EEDATA | |
373 write_int_eeprom d'51' ; write byte stored in EEDATA | |
374 return | |
375 | |
376 show_cv_active: ; CV mode | |
21 | 377 bsf LED_red |
0 | 378 WAITMS d'100' |
21 | 379 bcf LED_red |
0 | 380 WAITMS d'100' |
21 | 381 bsf LED_red |
0 | 382 bsf charge_done ; Charge cycle finished |
383 return | |
384 | |
385 show_cc_active: ; CC mode | |
21 | 386 bsf LED_red |
0 | 387 bsf charge_started ; Charger started in CC mode |
388 bcf charge_done ; Charge cycle not finished | |
389 return | |
390 | |
391 | |
392 timeout_premenu: | |
393 btfss premenu ; is "Menu?" displayed? | |
394 return ; No | |
395 incf timeout_counter3,F ; Yes... | |
396 GETCUSTOM8 d'4' ; loads premenu_timeout into WREG | |
397 cpfsgt timeout_counter3 ; ... longer then premenu_timeout | |
398 return ; No! | |
399 bcf premenu ; Yes, so clear "Menu?" and clear pre_menu bit | |
400 | |
401 call PLED_topline_box_clear ; Clears Bar at the top | |
402 | |
403 btfsc gauge_mode | |
404 bra timeout_premenu2 ; Skip in Gauge mode | |
405 btfsc FLAG_apnoe_mode | |
406 bra timeout_premenu2 ; Skip in Apnoe mode | |
13 | 407 |
0 | 408 timeout_premenu2: |
409 call update_surf_press ; rewrite serial number | |
410 call PLED_serial ; rewrite serial number | |
411 clrf timeout_counter3 ; Also clear timeout | |
412 bcf switch_left ; and debounce switches | |
413 bcf switch_right | |
414 return | |
415 | |
416 test_switches_surfmode: ; checks switches in surfacemode | |
417 btfsc switch_left | |
418 bra test_switches_surfmode2 | |
419 btfsc switch_right | |
420 bra test_switches_surfmode3 | |
421 | |
422 ; No button press, reset timer0 | |
423 bcf T0CON,TMR0ON ; Stop Timer 0 | |
424 bcf INTCON,TMR0IF ; Clear flag | |
425 clrf TMR0H | |
426 clrf TMR0L | |
427 bcf INTCON,INT0IF ; Clear flag | |
428 bcf INTCON3,INT1IF ; Clear flag | |
429 return | |
430 | |
431 test_switches_surfmode3: | |
432 bcf switch_right | |
433 call PLED_topline_box ; Write a filled bar at the top | |
434 WIN_INVERT .1 ; Init new Wordprocessor | |
435 DISPLAYTEXT .4 ;Menu? | |
436 WIN_INVERT .0 ; Init new Wordprocessor | |
437 bsf premenu | |
438 clrf timeout_counter2 | |
439 return | |
440 | |
441 test_switches_surfmode2: | |
442 bcf switch_left | |
443 btfss premenu | |
13 | 444 bra test_switches_surfmode4 |
0 | 445 bsf menubit ; Enter Menu! |
446 return | |
447 | |
13 | 448 test_switches_surfmode4: |
107 | 449 bsf toggle_customview ; Toggle customview (Cleared in customview.asm) |
13 | 450 return |
0 | 451 |
452 timeout_surfmode: | |
453 incf timeout_counter2,F ; increase timeout counter | |
454 GETCUSTOM8 d'3' ; loads surfloop_timeout into WREG | |
455 addlw d'5' ; adds five seconds in case timout=zero! | |
456 btfsc STATUS,C ; > 255? | |
457 movlw d'255' ; Set to 255... | |
458 decf WREG,F ; Limit to 254 | |
459 cpfsgt timeout_counter2 ; Compare with timeout_counter2 | |
460 return ; return, no timeout | |
461 bsf sleepmode ; Set Flag | |
462 return ; Return |