Mercurial > public > mk2
comparison code_part1/OSTC_code_asm_part1/divemode.asm @ 0:96a35aeda5f2
Initial setup
author | heinrichsweikamp |
---|---|
date | Tue, 12 Jan 2010 15:05:59 +0100 |
parents | |
children | d11ef8dc4b2c |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:96a35aeda5f2 |
---|---|
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 ; Mainroutines for divemode | |
20 ; written by: Matthias Heinrichs, info@heinrichsweikamp.com | |
21 ; written: 10/01/05 | |
22 ; last updated: 15/05/08 | |
23 ; known bugs: | |
24 ; ToDo: | |
25 | |
26 diveloop: | |
27 call diveloop_boot ; Boot tasks for all modes | |
28 | |
29 ; Startup Tasks for all modes | |
30 ostc_debug 'R' ; Sends debug-information to screen if debugmode active | |
31 call PLED_ClearScreen ; clean up OLED | |
32 call PLED_divemode_mask ; Display mask | |
33 call PLED_active_gas_divemode ; Display gas, if required | |
34 call PLED_temp_divemode ; Displays temperature | |
35 | |
36 btfsc FLAG_apnoe_mode | |
37 bsf realdive ; Set Realdive flag in Apnoe mode | |
38 | |
39 btfsc gauge_mode | |
40 bra diveloop_loop ; Skip in gauge mode | |
41 btfsc FLAG_apnoe_mode | |
42 bra diveloop_loop ; Skip in apnoe mode | |
43 | |
44 ; Startup Tasks for deco modes | |
45 call PLED_display_ndl_mask ; display "no stop" if not in gauge or apnoe mode | |
46 | |
47 diveloop_loop: ; The diveloop starts here | |
48 btfss onesecupdate ; tasks any new second | |
49 bra diveloop_loop2 | |
50 | |
51 btfsc gauge_mode ; Only in gauge mode | |
52 bra diveloop_loop1a ; One Second Tasks in Gauge mode | |
53 btfsc FLAG_apnoe_mode ; Only in apnoe mode | |
54 bra diveloop_loop1b ; One Second Tasks in Apnoe mode | |
55 btfsc FLAG_const_ppO2_mode ; only in const_ppO2_mode | |
56 bra diveloop_loop1c ; One Second Tasks in const_ppO2 mode | |
57 | |
58 ; Tasks only for OC modes | |
59 call check_ppO2 ; check ppO2 and displays warning if required | |
60 call calc_deko_divemode ; calculate decompression and display result (any two seconds) | |
61 bra diveloop_loop1x ; Common Tasks | |
62 | |
63 ; Tasks only for Gauge mode | |
64 diveloop_loop1a: | |
65 btfss premenu ; Is the divemode menu active? | |
66 call PLED_divemins ; display (new) divetime! | |
67 call timeout_divemode ; dive finished? This routine sets the required flags | |
68 | |
69 btfsc stopwatch_active ; =1: Show Average Depth instead of Temperature | |
70 call PLED_stopwatch_show ; Show stopwatch only in Average mode | |
71 | |
72 btfsc twosecupdate ; two seconds after the last call | |
73 bra diveloop_loop1a2 ; Common Tasks | |
74 | |
75 bsf twosecupdate ; Routines used in the "other second" | |
76 call calc_average_depth ; calculate average depth | |
77 | |
78 bra diveloop_loop1x ; Common Tasks | |
79 | |
80 diveloop_loop1a2: | |
81 bcf twosecupdate | |
82 bra diveloop_loop1x ; Common Tasks | |
83 | |
84 ; Tasks only for Apnoe mode | |
85 diveloop_loop1b: | |
86 call divemode_apnoe_tasks ; 1 sec. Apnoe tasks | |
87 bra diveloop_loop1x ; Common Tasks | |
88 | |
89 ; Tasks only for ppO2 mode | |
90 diveloop_loop1c: | |
91 call PLED_const_ppO2_value ; display const ppO2 setting in [Bar] | |
92 call calc_deko_divemode ; calculate decompression and display result (any two seconds) | |
93 bra diveloop_loop1x ; Common Tasks | |
94 | |
95 ; Common Tasks for all modes | |
96 diveloop_loop1x: | |
97 call timeout_divemode ; dive finished? This routine sets the required flags | |
98 btfsc low_battery_state ; If battery is low, then... | |
99 call update_batt_voltage_divemode ; Display Battery Symbol/Voltage! | |
100 btfsc premenu ; is Menu? displayed? | |
101 call timeout_premenu_divemode ; No, so check for timeout premenu | |
102 btfsc menubit ; is the Dive mode menu displayed? | |
103 call timeout_divemenu ; Yes, so check for timeout divemenu | |
104 call set_leds_divemode ; Sets warnings, if required. Also Sets buzzer | |
105 btfsc enter_error_sleep ; Enter Fatal Error Routine? | |
106 goto fatal_error_sleep ; Yes (In Sleepmode_vxx.asm!) | |
107 | |
108 btfsc stopwatch_active ; =1: Show Average Depth instead of Temperature | |
109 call PLED_stopwatch_show ; Show stopwatch only in Average mode | |
110 | |
111 bcf onesecupdate ; one seconds update done | |
112 | |
113 GETCUSTOM8 d'38' ; Show seconds (=1?) | |
114 movwf lo | |
115 movlw d'1' | |
116 cpfseq lo ; =1? | |
117 bra diveloop_loop2 ; No, minutes only | |
118 bsf update_divetime ; Set Update flag | |
119 | |
120 | |
121 diveloop_loop2: | |
122 btfss update_divetime ; display new divetime? | |
123 bra diveloop_loop3 ; No | |
124 btfsc premenu ; Is the divemode menu active? | |
125 bra diveloop_loop2a ; Yes | |
126 call PLED_divemins ; Display (new) divetime! | |
127 btfsc FLAG_const_ppO2_mode ; only in const_ppO2_mode | |
128 call PLED_const_ppO2_value ; display const ppO2 setting in [Bar] | |
129 btfsc ppO2_show_value ; show ppO2? | |
130 call check_ppO2 ; check ppO2 and displays warning if required | |
131 | |
132 diveloop_loop2a: | |
133 bcf update_divetime ; clear flag | |
134 | |
135 | |
136 diveloop_loop3: | |
137 btfss menubit ; Divemode menu active? | |
138 call test_switches_divemode ; No, Check switches normal | |
139 | |
140 btfsc menubit ; Divemode menu active? | |
141 call test_switches_divemode_menu ; Yes, check switches divemode menu | |
142 | |
143 btfss divemode ; Dive finished? | |
144 bra end_dive ; Dive finished! | |
145 | |
146 btfsc pressure_refresh ; new pressure available? | |
147 call update_divemode1 ; Yes, display new depth | |
148 bcf pressure_refresh ; until new pressure is available | |
149 | |
150 btfsc oneminupdate ; one minute tasks | |
151 call update_divemode60 ; Update clock, etc. | |
152 | |
153 btfsc store_sample ; store new sample? | |
154 call store_dive_data ; Store profile data | |
155 | |
156 btfss menubit ; Sleep only with inactive menu... | |
157 sleep | |
158 | |
159 nop | |
160 bra diveloop_loop ; Loop the divemode | |
161 | |
162 timeout_premenu_divemode: | |
163 incf timeout_counter3,F ; Yes... | |
164 | |
165 GETCUSTOM8 d'4' ; loads premenu_timeout into WREG | |
166 cpfsgt timeout_counter3 ; ... longer then premenu_timeout | |
167 return ; No! | |
168 | |
169 bcf premenu ; Yes, so clear "Menu?" and clear pre_menu bit | |
170 call PLED_menu_clear ; Remove "Menu?" | |
171 return | |
172 | |
173 divemode_apnoe_tasks: ; 1 sec. Apnoe tasks | |
174 call PLED_display_apnoe_descent ; Show descent timer | |
175 | |
176 btfsc divemode2 ; Time running? | |
177 bra divemode_apnoe_tasks2 ; New descent, reset data if flag is set | |
178 | |
179 call PLED_display_apnoe_surface | |
180 incf apnoe_surface_secs,F | |
181 movlw d'60' | |
182 cpfseq apnoe_surface_secs | |
183 bra divemode_apnoe_tasks1 | |
184 clrf apnoe_surface_secs | |
185 incf apnoe_surface_mins,F | |
186 | |
187 divemode_apnoe_tasks1: | |
188 bcf FLAG_active_descent ; Clear flag | |
189 btfsc divemode2 ; Time running? | |
190 return ; Yes, return | |
191 | |
192 bsf FLAG_active_descent ; Set Flag | |
193 return | |
194 | |
195 divemode_apnoe_tasks2: | |
196 btfss FLAG_active_descent ; Are descending? | |
197 return ; No, We are at the surface | |
198 rcall apnoe_calc_maxdepth ; Yes! | |
199 | |
200 divemode_apnoe_tasks3: | |
201 call PLED_apnoe_clear_surface ; Clear Surface timer | |
202 | |
203 clrf apnoe_timeout_counter ; Delete timeout | |
204 clrf apnoe_surface_secs | |
205 clrf apnoe_surface_mins | |
206 clrf apnoe_secs | |
207 clrf apnoe_mins ; Reset Descent time | |
208 clrf max_pressure+0 | |
209 clrf max_pressure+1 ; Reset Max. Depth | |
210 bcf FLAG_active_descent ; Clear flag | |
211 return | |
212 | |
213 apnoe_calc_maxdepth: | |
214 movff apnoe_max_pressure+0,sub_a+0 | |
215 movff apnoe_max_pressure+1,sub_a+1 | |
216 movff max_pressure+0,sub_b+0 | |
217 movff max_pressure+1,sub_b+1 | |
218 call sub16 ; sub_c = sub_a - sub_b | |
219 ; apnoe_max_pressure<max_pressure -> neg_flag=1 | |
220 ; max_pressure<=apnoe_max_pressure -> neg_flag=0 | |
221 btfss neg_flag | |
222 return | |
223 ;apnoe_max_pressure<max_pressure | |
224 movff max_pressure+0,apnoe_max_pressure+0 | |
225 movff max_pressure+1,apnoe_max_pressure+1 | |
226 return | |
227 | |
228 set_leds_divemode: | |
229 call clear_LEDy ; LEDy OFF | |
230 movff char_O_gradient_factor,lo ; gradient factor absolute | |
231 | |
232 GETCUSTOM8 d'14' ; threshold for LED warning | |
233 cpfslt lo ; | |
234 call warn_gf1 ; show warning, set flags | |
235 | |
236 btfsc ppO2_warn_value ; warn because of too high ppO2? | |
237 call set_LEDy ; Yes | |
238 | |
239 movff char_I_deco_model,lo | |
240 decfsz lo,W ; jump over return if char_I_deco_model == 1 | |
241 return | |
242 | |
243 movff char_O_relative_gradient_GF,lo ; gradient factor relative (GF model) | |
244 | |
245 GETCUSTOM8 d'14' ; threshold for LED warning | |
246 cpfslt lo ; | |
247 call warn_gf1 ; show warning, set flags | |
248 | |
249 btfsc ppO2_warn_value ; warn because of too high ppO2? | |
250 call set_LEDy ; Yes | |
251 | |
252 return | |
253 | |
254 warn_gf1: | |
255 call set_LEDy ; LED Yellow on | |
256 movlw d'2' ; Type of Alarm | |
257 movwf AlarmType ; Copy to Alarm Register | |
258 bsf event_occured ; Set Event Flag | |
259 return | |
260 | |
261 calc_deko_divemode: | |
262 btfsc twosecupdate ; two seconds after the last call | |
263 bra calc_deko_divemode2 ; Yes, calculate and display deco data ("first second") | |
264 | |
265 ; Routines used in the "other second" | |
266 | |
267 bsf twosecupdate ; No, but next second! | |
268 call calc_average_depth ; calculate average depth | |
269 call calc_velocity ; calculate vertical velocity and display if > threshold (every two seconds) | |
270 | |
271 ; calculate ppO2 in 0.1Bar (e.g. 150 = 1.50Bar ppO2) | |
272 movff amb_pressure+0,xA+0 | |
273 movff amb_pressure+1,xA+1 | |
274 movlw LOW d'10' | |
275 movwf xB+0 | |
276 movlw HIGH d'10' | |
277 clrf xB+1 | |
278 call div16x16 ; xC=p_amb/10 | |
279 movff xC+0,xA+0 | |
280 movff xC+1,xA+1 | |
281 movff char_I_O2_ratio,xB+0 | |
282 clrf xB+1 | |
283 call mult16x16 ; char_I_O2_ratio * p_amb/10 | |
284 movff xC+0,xA+0 | |
285 movff xC+1,xA+1 | |
286 movlw LOW d'100' | |
287 movwf xB+0 | |
288 movlw HIGH d'100' | |
289 clrf xB+1 | |
290 call div16x16 ; xC=(char_I_O2_ratio * p_amb/10)/100 | |
291 | |
292 ; Copy ppO2 for CNS calculation | |
293 movff xC+0, char_I_actual_ppO2 ; copy last ppO2 to buffer register | |
294 btfsc FLAG_const_ppO2_mode ; do in const_ppO2_mode | |
295 movff char_I_const_ppO2, char_I_actual_ppO2 ; copy last ppO2 to buffer register | |
296 | |
297 ; Calculate CNS | |
298 call main_calc_CNS_fraction ; calculate CNS | |
299 movlb b'00000001' ; rambank 1 selected | |
300 | |
301 ; Check if CNS should be displayed | |
302 movff char_O_CNS_fraction,lo ; copy into bank1 | |
303 GETCUSTOM8 d'27' ; cns_display_high | |
304 subwf lo,W | |
305 btfsc STATUS,C | |
306 call PLED_display_cns ; Show CNS | |
307 | |
308 ; Check for decompression gases if in decomode | |
309 divemode_check_decogases: ; CALLed from Simulator | |
310 btfss dekostop_active | |
311 bra reset_decompression_gases ; While in NDL, do not set deompression gas | |
312 ; 1. Find active gas with deepest change depth < current depth | |
313 ; 2. Set Decogas | |
314 | |
315 movff rel_pressure+0,xA+0 | |
316 movff rel_pressure+1,xA+1 | |
317 movlw d'100' | |
318 movwf xB+0 | |
319 clrf xB+1 | |
320 call div16x16 ; compute depth in full m -> result in xC+0 | |
321 clrf lo ; clear depth for comparison | |
322 | |
323 ; check gas1 | |
324 read_int_eeprom d'27' ; read flag register | |
325 btfss EEDATA,0 ; check active flag | |
326 bra check_decogas2 ; skip inactive gases! | |
327 read_int_eeprom d'28' ; read gas_change_depth | |
328 movf xC+0,W ; load depth in m into WREG | |
329 cpfslt EEDATA ; gas_change_depth > current depth? | |
330 bra check_decogas2 ; W < EEDATA -> current depth lower then gas_change_depth | |
331 | |
332 movff EEDATA,lo ; deepest gas_change_depth in lo | |
333 movlw d'1' | |
334 movwf hi ; Decogas # in hi (1-5) | |
335 | |
336 check_decogas2: | |
337 read_int_eeprom d'27' ; read flag register | |
338 btfss EEDATA,1 ; check active flag | |
339 bra check_decogas3 ; skip inactive gases! | |
340 read_int_eeprom d'29' ; read gas_change_depth | |
341 movf xC+0,W ; load depth in m into WREG | |
342 cpfslt EEDATA ; gas_change_depth > current depth? | |
343 bra check_decogas3 ; W < EEDATA -> current depth lower then gas_change_depth | |
344 | |
345 read_int_eeprom d'29' ; read gas_change_depth | |
346 movf lo,W ; load current gas_change_depth into WREG | |
347 cpfsgt EEDATA ; last gas_change_depth > current gas_change_depth ? | |
348 bra check_decogas3 ; W < lo -> last gas_change_depth > current gas_change_depth | |
349 movff EEDATA,lo ; deepest gas_change_depth in lo | |
350 movlw d'2' | |
351 movwf hi ; Decogas # in hi (1-5) | |
352 | |
353 check_decogas3: | |
354 read_int_eeprom d'27' ; read flag register | |
355 btfss EEDATA,2 ; check active flag | |
356 bra check_decogas4 ; skip inactive gases! | |
357 read_int_eeprom d'30' ; read gas_change_depth | |
358 movf xC+0,W ; load depth in m into WREG | |
359 cpfslt EEDATA ; gas_change_depth > current depth? | |
360 bra check_decogas4 ; W < EEDATA -> current depth lower then gas_change_depth | |
361 | |
362 read_int_eeprom d'30' ; read gas_change_depth | |
363 movf lo,W ; load current gas_change_depth into WREG | |
364 cpfsgt EEDATA ; last gas_change_depth > current gas_change_depth ? | |
365 bra check_decogas4 ; W < lo -> last gas_change_depth > current gas_change_depth | |
366 movff EEDATA,lo ; deepest gas_change_depth in lo | |
367 movlw d'3' | |
368 movwf hi ; Decogas # in hi (1-5) | |
369 | |
370 check_decogas4: | |
371 read_int_eeprom d'27' ; read flag register | |
372 btfss EEDATA,3 ; check active flag | |
373 bra check_decogas5 ; skip inactive gases! | |
374 read_int_eeprom d'31' ; read gas_change_depth | |
375 movf xC+0,W ; load depth in m into WREG | |
376 cpfslt EEDATA ; gas_change_depth > current depth? | |
377 bra check_decogas5 ; W < EEDATA -> current depth lower then gas_change_depth | |
378 | |
379 read_int_eeprom d'31' ; read gas_change_depth | |
380 movf lo,W ; load current gas_change_depth into WREG | |
381 cpfsgt EEDATA ; last gas_change_depth > current gas_change_depth ? | |
382 bra check_decogas5 ; W < lo -> last gas_change_depth > current gas_change_depth | |
383 movff EEDATA,lo ; deepest gas_change_depth in lo | |
384 movlw d'4' | |
385 movwf hi ; Decogas # in hi (1-5) | |
386 | |
387 check_decogas5: | |
388 read_int_eeprom d'27' ; read flag register | |
389 btfss EEDATA,4 ; check active flag | |
390 bra check_decogas_done ; skip inactive gases! | |
391 read_int_eeprom d'32' ; read gas_change_depth | |
392 movf xC+0,W ; load depth in m into WREG | |
393 cpfslt EEDATA ; gas_change_depth > current depth? | |
394 bra check_decogas_done ; W < EEDATA -> current depth lower then gas_change_depth | |
395 | |
396 read_int_eeprom d'32' ; read gas_change_depth | |
397 movf lo,W ; load current gas_change_depth into WREG | |
398 cpfsgt EEDATA ; last gas_change_depth > current gas_change_depth ? | |
399 bra check_decogas_done ; W < lo -> last gas_change_depth > current gas_change_depth | |
400 movff EEDATA,lo ; deepest gas_change_depth in lo | |
401 movlw d'5' | |
402 movwf hi ; Decogas # in hi (1-5) | |
403 | |
404 check_decogas_done: | |
405 ostc_debug 'E' ; Sends debug-information to screen if debugmode active | |
406 | |
407 decf hi,F ; Gas 0-4 | |
408 movff lo, char_I_deco_gas_change ; copy change_depth | |
409 | |
410 movf hi,W ; Gas 0-4 | |
411 mullw d'4' | |
412 movf PRODL,W | |
413 addlw d'7' ; = address for He ratio | |
414 movwf EEADR | |
415 call read_eeprom ; Read He ratio | |
416 movff EEDATA,char_I_deco_He_ratio ; And copy into hold register | |
417 | |
418 | |
419 movf hi,W ; Gas 0-4 | |
420 mullw d'4' | |
421 movf PRODL,W | |
422 addlw d'6' ; = address for O2 ratio | |
423 movwf EEADR | |
424 call read_eeprom ; Read O2 ratio | |
425 | |
426 movff char_I_deco_He_ratio, wait_temp ; copy into bank1 register | |
427 bsf STATUS,C ; Borrow bit | |
428 movlw d'100' ; 100% | |
429 subfwb wait_temp,W ; minus He | |
430 bsf STATUS,C ; Borrow bit | |
431 subfwb EEDATA,F ; minus O2 | |
432 movff EEDATA, char_I_deco_N2_ratio ; = N2! | |
433 bra skip_decompression_gases | |
434 | |
435 reset_decompression_gases: ; reset the deco gas while in NDL | |
436 ostc_debug 'F' ; Sends debug-information to screen if debugmode active | |
437 clrf lo | |
438 movff lo, char_I_deco_gas_change ; clear | |
439 movff lo, char_I_deco_N2_ratio ; clear | |
440 movff lo, char_I_deco_He_ratio ; clear | |
441 skip_decompression_gases: | |
442 ;call PLED_gaschange_DEBUG | |
443 return | |
444 | |
445 calc_deko_divemode2: | |
446 bcf twosecupdate | |
447 | |
448 btfsc gauge_mode ; ignore decompression calculation in gauge mode | |
449 return | |
450 btfsc FLAG_apnoe_mode ; ignore decompression calculation in apnoe mode | |
451 return | |
452 | |
453 ostc_debug 'B' ; Sends debug-information to screen if debugmode active | |
454 call divemode_prepare_flags_for_deco | |
455 call deco_main_calc_hauptroutine ; calc_tissue | |
456 movlb b'00000001' ; rambank 1 selected | |
457 ostc_debug 'C' ; Sends debug-information to screen if debugmode active | |
458 | |
459 movff char_O_deco_status,deco_status ; | |
460 tstfsz deco_status ; deco_status=0 if decompression calculation done | |
461 return ; calculation not yet finished! | |
462 | |
463 movff char_O_array_decodepth+0,wait_temp ; copy ceiling to temp register | |
464 tstfsz wait_temp ; Ceiling<0m? | |
465 bra calc_deko_divemode3 ; Yes! | |
466 | |
467 btfsc dekostop_active | |
468 call PLED_display_ndl_mask ; Clear deco data, display nostop time | |
469 bcf dekostop_active ; clear flag | |
470 | |
471 clrf decodata+0 ; for profile memory | |
472 movff char_O_nullzeit,decodata+1 ; nostop time | |
473 | |
474 call PLED_display_ndl ; display no deco limit | |
475 return | |
476 | |
477 divemode_prepare_flags_for_deco: | |
478 movff amb_pressure+0,int_I_pres_respiration+0 ; lo and copy result to deco routine | |
479 movff amb_pressure+1,int_I_pres_respiration+1 ; hi | |
480 GETCUSTOM8 d'11' ; Saturation multiplier % | |
481 movwf wait_temp | |
482 movff wait_temp,char_I_saturation_multiplier | |
483 GETCUSTOM8 d'12' ; Desaturation multiplier % | |
484 movwf wait_temp | |
485 movff wait_temp,char_I_desaturation_multiplier | |
486 GETCUSTOM8 d'16' ; Deco distance to decostop in 1/10 meter for simulation | |
487 movwf wait_temp | |
488 movff wait_temp,char_I_deco_distance | |
489 GETCUSTOM8 d'29' ; Depth Last Deco in meter for simulation | |
490 movwf wait_temp | |
491 movff wait_temp,char_I_depth_last_deco | |
492 call restart_set_modes_and_flags ; Sets decomode (char_I_deco_model) and flags (again) | |
493 return | |
494 | |
495 calc_deko_divemode3: | |
496 btfss dekostop_active | |
497 call PLED_display_deko_mask ; clear nostop time, display decodata | |
498 bsf dekostop_active ; Set flag | |
499 | |
500 movff char_O_array_decodepth+0,decodata+0 ; ceiling | |
501 movff char_O_array_decotime,decodata+1 ; length of first stop in minues | |
502 | |
503 call PLED_display_deko ; display decodata | |
504 return | |
505 | |
506 store_dive_data: ; CF20 seconds gone | |
507 bcf store_sample ; update only any CF20 seconds | |
508 bsf update_divetime ; update divemins every CF20 seconds | |
509 | |
510 call clear_LEDg ; LEDg off | |
511 | |
512 btfsc header_stored ; Header already stored? | |
513 bra store_dive_data2 ; Yes, store only profile data | |
514 bsf header_stored ; Store header | |
515 | |
516 movff eeprom_address+0, eeprom_header_address+0 ; store startposition | |
517 movff eeprom_address+1, eeprom_header_address+1 ; store startposition | |
518 | |
519 ; shift address for header | |
520 ; the header will be stored after the dive | |
521 incf_eeprom_address d'47' ; Macro, that adds 8Bit to eeprom_address:2 with banking at 0x8000 | |
522 | |
523 store_dive_data2: | |
524 movf rel_pressure+0,W ; store depth with every sample | |
525 call write_external_eeprom | |
526 movf rel_pressure+1,W | |
527 call write_external_eeprom | |
528 | |
529 ;First, find out how many bytes will append to this sample.... | |
530 clrf ProfileFlagByte ; clear number of bytes to append | |
531 | |
532 ; Check Extented informations | |
533 decfsz divisor_temperature,W ; Check divisor | |
534 bra check_extended1 | |
535 movlw d'2' ; Information length | |
536 addwf ProfileFlagByte,F ; add to ProfileFlagByte | |
537 check_extended1: | |
538 decfsz divisor_deco,W ; Check divisor | |
539 bra check_extended2 | |
540 movlw d'2' ; Information length | |
541 addwf ProfileFlagByte,F ; add to ProfileFlagByte | |
542 check_extended2: | |
543 decfsz divisor_tank,W ; Check divisor | |
544 bra check_extended3 | |
545 movlw d'2' ; Information length | |
546 addwf ProfileFlagByte,F ; add to ProfileFlagByte | |
547 check_extended3: | |
548 decfsz divisor_ppo2,W ; Check divisor | |
549 bra check_extended4 | |
550 movlw d'3' ; Information length | |
551 addwf ProfileFlagByte,F ; add to ProfileFlagByte | |
552 check_extended4: | |
553 decfsz divisor_deco_debug,W; Check divisor | |
554 bra check_extended5 | |
555 movlw d'9' ; Information length | |
556 addwf ProfileFlagByte,F ; add to ProfileFlagByte | |
557 check_extended5: | |
558 decfsz divisor_nuy2,W ; Check divisor | |
559 bra check_extended6 | |
560 movlw d'0' ; Information length | |
561 addwf ProfileFlagByte,F ; add to ProfileFlagByte | |
562 check_extended6: | |
563 | |
564 ; Second, check global event flag | |
565 btfss event_occured ; Check global event flag | |
566 bra store_dive_data3 ; No Event | |
567 movlw d'1' | |
568 addwf ProfileFlagByte,F ; add one byte (The EventByte) | |
569 | |
570 clrf EventByte ; reset EventByte | |
571 | |
572 movf AlarmType,W ; Type of Alarm Bit 0-3 | |
573 addwf EventByte,F ; Copy to EventByte Bit 0-3 | |
574 clrf AlarmType ; Reset AlarmType | |
575 | |
576 ; Third, check events and add aditional bytes | |
577 btfss manual_gas_changed ; Check flag | |
578 bra check_event1 | |
579 movlw d'2' ; Information length | |
580 addwf ProfileFlagByte,F ; add to ProfileFlagByte | |
581 bsf EventByte,4 ; Also set Flag in EventByte! | |
582 check_event1: | |
583 btfss stored_gas_changed ; Check flag | |
584 bra check_event2 | |
585 movlw d'1' ; Information length | |
586 addwf ProfileFlagByte,F ; add to ProfileFlagByte | |
587 bsf EventByte,5 ; Also set Flag in EventByte! | |
588 check_event2: | |
589 bsf ProfileFlagByte,7 ; Set EventByte Flag in ProfileFlagByte | |
590 | |
591 store_dive_data3: | |
592 movf ProfileFlagByte,W ; finally, write ProfileFlagByte! | |
593 call write_external_eeprom | |
594 | |
595 btfss event_occured ; Check global event flag (again) | |
596 bra store_dive_data4 ; No Event | |
597 | |
598 ; Store the EventByte + additional bytes now | |
599 movf EventByte,W | |
600 call write_external_eeprom | |
601 | |
602 btfss manual_gas_changed ; Check flag | |
603 bra store_dive_data3a | |
604 read_int_eeprom d'24' ; % O2 Gas6 | |
605 movf EEDATA,W | |
606 call write_external_eeprom | |
607 read_int_eeprom d'25' ; % He Gas6 | |
608 movf EEDATA,W | |
609 call write_external_eeprom | |
610 | |
611 store_dive_data3a: | |
612 btfss stored_gas_changed ; Check flag | |
613 bra store_dive_data3b | |
614 movf active_gas,W ; Store active gas | |
615 call write_external_eeprom | |
616 | |
617 store_dive_data3b: | |
618 | |
619 store_dive_data4: | |
620 bcf event_occured ; Clear the global event flag | |
621 bcf manual_gas_changed ; Clear all events | |
622 bcf stored_gas_changed ; Clear all events | |
623 | |
624 ; Store extended informations | |
625 decfsz divisor_temperature,F ; Check divisor | |
626 bra store_extended1 | |
627 rcall store_dive_temperature | |
628 store_extended1: | |
629 decfsz divisor_deco,F ; Check divisor | |
630 bra store_extended2 | |
631 rcall store_dive_decodata | |
632 store_extended2: | |
633 decfsz divisor_tank,F ; Check divisor | |
634 bra store_extended3 | |
635 rcall store_dive_tankdata | |
636 store_extended3: | |
637 decfsz divisor_ppo2,F ; Check divisor | |
638 bra store_extended4 | |
639 rcall store_dive_ppo2 | |
640 store_extended4: | |
641 decfsz divisor_deco_debug,F; Check divisor | |
642 bra store_extended5 | |
643 rcall store_dive_decodebug | |
644 store_extended5: | |
645 decfsz divisor_nuy2,F ; Check divisor | |
646 bra store_extended6 | |
647 rcall store_dive_nuy2 | |
648 store_extended6: | |
649 | |
650 ; The next block is required to take care of "store never" | |
651 btfsc divisor_temperature,7 ; Test highest Bit (Register must have been zero before the "decfsz" command!) | |
652 clrf divisor_temperature ; And clear register again, so it will never reach zero... | |
653 btfsc divisor_deco,7 ; Test highest Bit (Register must have been zero before the "decfsz" command!) | |
654 clrf divisor_deco ; And clear register again, so it will never reach zero... | |
655 btfsc divisor_tank,7 ; Test highest Bit (Register must have been zero before the "decfsz" command!) | |
656 clrf divisor_tank ; And clear register again, so it will never reach zero... | |
657 btfsc divisor_ppo2,7 ; Test highest Bit (Register must have been zero before the "decfsz" command!) | |
658 clrf divisor_ppo2 ; And clear register again, so it will never reach zero... | |
659 btfsc divisor_deco_debug,7 ; Test highest Bit (Register must have been zero before the "decfsz" command!) | |
660 clrf divisor_deco_debug ; And clear register again, so it will never reach zero... | |
661 btfsc divisor_nuy2,7 ; Test highest Bit (Register must have been zero before the "decfsz" command!) | |
662 clrf divisor_nuy2 ; And clear register again, so it will never reach zero... | |
663 | |
664 ostc_debug 'D' ; Sends debug-information to screen if debugmode active | |
665 return ; Done. | |
666 | |
667 store_dive_nuy2: | |
668 GETCUSTOM8 d'26' | |
669 movwf divisor_nuy2 ; Reload divisor from CF | |
670 return | |
671 | |
672 store_dive_decodebug: | |
673 movff 0x931,divisor_deco_debug ; Used as temp | |
674 movf divisor_deco_debug,W ; copy to WREG | |
675 call write_external_eeprom ; Store in EEPROM | |
676 movff 0x930,divisor_deco_debug ; Used as temp | |
677 movf divisor_deco_debug,W ; copy to WREG | |
678 call write_external_eeprom ; Store in EEPROM | |
679 movff 0x933,divisor_deco_debug ; Used as temp | |
680 movf divisor_deco_debug,W ; copy to WREG | |
681 call write_external_eeprom ; Store in EEPROM | |
682 movff 0x932,divisor_deco_debug ; Used as temp | |
683 movf divisor_deco_debug,W ; copy to WREG | |
684 call write_external_eeprom ; Store in EEPROM | |
685 movff 0x935,divisor_deco_debug ; Used as temp | |
686 movf divisor_deco_debug,W ; copy to WREG | |
687 call write_external_eeprom ; Store in EEPROM | |
688 movff 0x934,divisor_deco_debug ; Used as temp | |
689 movf divisor_deco_debug,W ; copy to WREG | |
690 call write_external_eeprom ; Store in EEPROM | |
691 movff 0x937,divisor_deco_debug ; Used as temp | |
692 movf divisor_deco_debug,W ; copy to WREG | |
693 call write_external_eeprom ; Store in EEPROM | |
694 movff 0x936,divisor_deco_debug ; Used as temp | |
695 movf divisor_deco_debug,W ; copy to WREG | |
696 call write_external_eeprom ; Store in EEPROM | |
697 movff 0x938,divisor_deco_debug ; Used as temp | |
698 movf divisor_deco_debug,W ; copy to WREG | |
699 call write_external_eeprom ; Store in EEPROM | |
700 GETCUSTOM8 d'25' | |
701 movwf divisor_deco_debug ; Reload divisor from CF | |
702 return | |
703 | |
704 store_dive_ppo2: | |
705 movlw 0x00 ; Dummy | |
706 call write_external_eeprom | |
707 movlw 0x00 ; Dummy | |
708 call write_external_eeprom | |
709 movlw 0x00 ; Dummy | |
710 call write_external_eeprom | |
711 GETCUSTOM8 d'24' | |
712 movwf divisor_ppo2 ; Reload divisor from CF | |
713 return | |
714 | |
715 store_dive_tankdata: | |
716 movlw d'0' ; Dummy Tank1 | |
717 call write_external_eeprom | |
718 movlw d'0' ; Dummy Tank2 | |
719 call write_external_eeprom | |
720 GETCUSTOM8 d'23' | |
721 movwf divisor_tank ; Reload divisor from CF | |
722 return | |
723 | |
724 store_dive_decodata: | |
725 movf decodata+0,W ; =0:no stop dive, if in deco mode: ceiling in m | |
726 call write_external_eeprom | |
727 movf decodata+1,W ; no stop time of length of first stop | |
728 call write_external_eeprom | |
729 GETCUSTOM8 d'22' | |
730 movwf divisor_deco ; Reload divisor from CF | |
731 return | |
732 | |
733 store_dive_temperature: | |
734 movf temperature+0,W ; append temperature to current sample! | |
735 call write_external_eeprom | |
736 movf temperature+1,W | |
737 call write_external_eeprom | |
738 GETCUSTOM8 d'21' | |
739 movwf divisor_temperature ; Reload divisor from CF | |
740 return | |
741 | |
742 calc_velocity: ; called every two seconds | |
743 btfss divemode | |
744 bra do_not_display_velocity ; display velocity only in divemode | |
745 | |
746 calc_velocity2: | |
747 movff amb_pressure+0,sub_a+0 | |
748 movff amb_pressure+1,sub_a+1 | |
749 movff last_pressure+0,sub_b+0 | |
750 movff last_pressure+1,sub_b+1 | |
751 movff amb_pressure+0,last_pressure+0 ; store old value for velocity | |
752 movff amb_pressure+1,last_pressure+1 | |
753 | |
754 call sub16 ; sub_c = amb_pressure - last_pressure | |
755 | |
756 movff sub_c+0,xA+0 | |
757 movff sub_c+1,xA+1 | |
758 movlw d'39' ;77 when called every second.... | |
759 movwf xB+0 | |
760 clrf xB+1 | |
761 call mult16x16 ; differential pressure in mBar*77... | |
762 movff xC+0,divA+0 | |
763 movff xC+1,divA+1 | |
764 movlw d'7' | |
765 movwf divB | |
766 call div16 ; devided by 2^7 equals velocity in m/min | |
767 | |
768 movlw d'99' | |
769 cpfsgt divA | |
770 bra calc_velocity3 | |
771 movwf divA ; divA=99 | |
772 | |
773 calc_velocity3: | |
774 | |
775 GETCUSTOM8 d'5' ; threshold for display vertical velocity | |
776 subwf divA+0,W ; | |
777 | |
778 btfss STATUS,C | |
779 bra do_not_display_velocity | |
780 | |
781 update_velocity: | |
782 bsf display_velocity | |
783 call PLED_display_velocity | |
784 return | |
785 | |
786 do_not_display_velocity: | |
787 btfss display_velocity ; Velocity was not displayed, do not delete | |
788 return | |
789 | |
790 bcf display_velocity ; Velocity was displayed, delete velocity now | |
791 call PLED_display_velocity_clear | |
792 return | |
793 | |
794 check_ppO2: ; check current ppO2 and display warning if required | |
795 btfsc FLAG_const_ppO2_mode ; ignore in ppO2 mode.... | |
796 return | |
797 | |
798 movff amb_pressure+0,xA+0 | |
799 movff amb_pressure+1,xA+1 | |
800 movlw d'10' | |
801 movwf xB+0 | |
802 clrf xB+1 | |
803 call div16x16 ; xC=p_amb/10 | |
804 movff xC+0,xA+0 | |
805 movff xC+1,xA+1 | |
806 movff char_I_O2_ratio,xB+0 | |
807 clrf xB+1 | |
808 call mult16x16 ; char_I_O2_ratio * p_amb/10 | |
809 | |
810 ; Check if ppO2 should be displayed | |
811 movff xC+0,sub_b+0 | |
812 movff xC+1,sub_b+1 | |
813 GETCUSTOM8 d'19' ; ppo2_display_high | |
814 mullw d'100' ; ppo2_display_high*100 | |
815 movff PRODL,sub_a+0 | |
816 movff PRODH,sub_a+1 | |
817 call sub16 | |
818 bcf ppO2_show_value ; clear flag | |
819 btfsc neg_flag | |
820 bsf ppO2_show_value ; set flag if required | |
821 | |
822 ;check if we are within our warning thresholds! | |
823 bcf ppO2_warn_value ; clear flag | |
824 movff xC+0,sub_b+0 | |
825 movff xC+1,sub_b+1 | |
826 GETCUSTOM8 d'18' ; ppo2_warning_high | |
827 mullw d'100' ; ppo2_warning_high*100 | |
828 movff PRODL,sub_a+0 | |
829 movff PRODH,sub_a+1 | |
830 call sub16 | |
831 btfss neg_flag | |
832 bra check_ppO2_0 ; Not too high | |
833 | |
834 bsf ppO2_warn_value ; set flag | |
835 movlw d'5' ; Type of Alarm | |
836 movwf AlarmType ; Copy to Alarm Register | |
837 bsf event_occured ; Set Event Flag | |
838 | |
839 check_ppO2_0: | |
840 movff xC+0,sub_b+0 | |
841 movff xC+1,sub_b+1 | |
842 GETCUSTOM8 d'17' ; ppo2_warning_low | |
843 mullw d'100' ; ppo2_warning_low*100 | |
844 movff PRODL,sub_a+0 | |
845 movff PRODH,sub_a+1 | |
846 call sub16 | |
847 btfsc neg_flag | |
848 bra check_ppO2_1 ; Not too low | |
849 | |
850 bsf ppO2_warn_value ; set flag | |
851 bsf ppO2_show_value ; show ppO2 if below threshold! | |
852 movlw d'4' ; Type of Alarm | |
853 movwf AlarmType ; Copy to Alarm Register | |
854 bsf event_occured ; Set Event Flag | |
855 | |
856 check_ppO2_1: | |
857 btfsc ppO2_show_value ; show value? | |
858 bra check_ppO2_2 ; yes! | |
859 | |
860 btfss ppO2_display_active ; is the value displayed? | |
861 bra check_ppO2_3 ; No, so clear not required | |
862 | |
863 call PLED_show_ppO2_clear; Clear ppO2 value | |
864 bcf ppO2_display_active ; clear flag | |
865 bra check_ppO2_3 ; done | |
866 | |
867 check_ppO2_2: | |
868 call PLED_show_ppO2 ; Display ppO2 (stored in xC) | |
869 bsf ppO2_display_active ; Set flag | |
870 | |
871 check_ppO2_3: | |
872 return ; done | |
873 | |
874 | |
875 calculate_noflytime: | |
876 ; calculate nofly time | |
877 movff int_O_desaturation_time+0,xA+0 | |
878 movff int_O_desaturation_time+1,xA+1 | |
879 tstfsz xA+0 ; Desat=0? | |
880 bra calculate_noflytime2 | |
881 tstfsz xA+1 ; Desat=0? | |
882 bra calculate_noflytime2 | |
883 ; Desaturation time = zero | |
884 movlw d'1' | |
885 movwf nofly_time+0 ; Clear nofly time | |
886 clrf nofly_time+1 ; Clear nofly time | |
887 bcf nofly_active ; Clear flag | |
888 return | |
889 | |
890 calculate_noflytime2: | |
891 movff xA+0,int_I_temp+0 | |
892 movff xA+1,int_I_temp+1 | |
893 GETCUSTOM8 .13 ; nofly_time_ratio | |
894 movwf xB+0 | |
895 movff xB,char_I_temp | |
896 ostc_debug 'K' ; Sends debug-information to screen if debugmode active | |
897 call main_calc_percentage | |
898 movlb b'00000001' ; select ram bank 1 | |
899 ostc_debug 'L' ; Sends debug-information to screen if debugmode active | |
900 movff int_I_temp+0,xA+0 | |
901 movff int_I_temp+1,xA+1 | |
902 tstfsz xA+0 ; Desat=0? | |
903 bra calculate_noflytime_2_final | |
904 tstfsz xA+1 ; Desat=0? | |
905 bra calculate_noflytime_2_final | |
906 ; noflytime = zero | |
907 movlw d'1' | |
908 movwf nofly_time+0 ; Clear nofly time | |
909 clrf nofly_time+1 ; Clear nofly time | |
910 bcf nofly_active ; Clear flag | |
911 return | |
912 calculate_noflytime_2_final: | |
913 movff xA+0,nofly_time+0 | |
914 movff xA+1,nofly_time+1 | |
915 bsf nofly_active ; Set flag | |
916 return | |
917 | |
918 end_dive: | |
919 btfss realdive ; dive longer then one minute | |
920 goto end_dive_common ; No, discard everything | |
921 | |
922 ; Dive finished (and longer then one minute or Apnoe timeout occured) | |
923 | |
924 btfsc FLAG_apnoe_mode ; Calc max. depth (again) for very short apnoe dives | |
925 rcall apnoe_calc_maxdepth | |
926 | |
927 ; calculate desaturation time | |
928 movff last_surfpressure_30min+0,int_I_pres_respiration+0 ; copy surface air pressure to deco routine | |
929 movff last_surfpressure_30min+1,int_I_pres_respiration+1 ; 30min old values | |
930 | |
931 GETCUSTOM8 d'12' ; Desaturation multiplier % | |
932 movwf wait_temp | |
933 movff wait_temp,char_I_desaturation_multiplier | |
934 | |
935 ostc_debug 'G' ; Sends debug-information to screen if debugmode active | |
936 call deco_main_calc_desaturation_time ; calculate desaturation time | |
937 movlb b'00000001' ; select ram bank 1 | |
938 rcall calculate_noflytime ; Calc NoFly time | |
939 ostc_debug 'H' ; Sends debug-information to screen if debugmode active | |
940 ; store header and ... | |
941 movlw 0xFD ; .... End-of-Profile Bytes | |
942 call write_external_eeprom | |
943 movlw 0xFD | |
944 call write_external_eeprom | |
945 movlw 0xFE ; This positon will be overwritten for the next profile | |
946 call write_external_eeprom ; and is required to find the newest dive after a firmware reset | |
947 | |
948 movff eeprom_header_address+0, eeprom_address+0 ; set header adress | |
949 movff eeprom_header_address+1, eeprom_address+1 ; write header | |
950 | |
951 movlw 0xFA ; Header start | |
952 call write_external_eeprom | |
953 movlw 0xFA | |
954 call write_external_eeprom | |
955 movlw logbook_profile_version ; Defined in definitions_vxyy.asm | |
956 call write_external_eeprom | |
957 movf month,W ; Date | |
958 call write_external_eeprom | |
959 movf day,W | |
960 call write_external_eeprom | |
961 movf year,W | |
962 call write_external_eeprom | |
963 movf hours,W ; End of dive time | |
964 call write_external_eeprom | |
965 movf mins,W | |
966 call write_external_eeprom | |
967 | |
968 btfss FLAG_apnoe_mode ; Store apnoe max or normal max (Which is only max from the last descent) | |
969 bra end_dive1 ; Store normal depth | |
970 | |
971 movff apnoe_max_pressure+0,lo | |
972 movff apnoe_max_pressure+1,hi | |
973 call adjust_depth_with_salinity ; computes salinity setting into lo:hi [mBar] | |
974 movff lo,apnoe_max_pressure+0 | |
975 movff hi,apnoe_max_pressure+1 | |
976 | |
977 movf apnoe_max_pressure+0,W ; Max. depth | |
978 call write_external_eeprom | |
979 movf apnoe_max_pressure+1,W | |
980 call write_external_eeprom | |
981 bra end_dive2 ; skip | |
982 | |
983 end_dive1: | |
984 movff max_pressure+0,lo | |
985 movff max_pressure+1,hi | |
986 call adjust_depth_with_salinity ; computes salinity setting into lo:hi [mBar] | |
987 movff lo,max_pressure+0 | |
988 movff hi,max_pressure+1 | |
989 | |
990 movf max_pressure+0,W ; Max. depth | |
991 call write_external_eeprom | |
992 movf max_pressure+1,W | |
993 call write_external_eeprom | |
994 | |
995 end_dive2: | |
996 movf divemins+0,W ; divetime minutes | |
997 call write_external_eeprom | |
998 movf divemins+1,W | |
999 call write_external_eeprom | |
1000 movf divesecs,W ; divetime seconds | |
1001 call write_external_eeprom | |
1002 movf mintemp+0,W ; minimum temperature | |
1003 call write_external_eeprom | |
1004 movf mintemp+1,W | |
1005 call write_external_eeprom | |
1006 movf last_surfpressure_30min+0,W ; airpressure before dive | |
1007 call write_external_eeprom | |
1008 movf last_surfpressure_30min+1,W | |
1009 call write_external_eeprom | |
1010 movff int_O_desaturation_time+0,lo ; | |
1011 movff int_O_desaturation_time+1,hi | |
1012 movf lo,W ; desaturation time in minutes | |
1013 call write_external_eeprom | |
1014 movf hi,W ; | |
1015 call write_external_eeprom | |
1016 | |
1017 ; Gases.... | |
1018 read_int_eeprom d'6' ; Read byte (stored in EEDATA) | |
1019 movf EEDATA,W | |
1020 call write_external_eeprom | |
1021 read_int_eeprom d'7' ; Read byte (stored in EEDATA) | |
1022 movf EEDATA,W | |
1023 call write_external_eeprom | |
1024 | |
1025 read_int_eeprom d'10' ; Read byte (stored in EEDATA) | |
1026 movf EEDATA,W | |
1027 call write_external_eeprom | |
1028 read_int_eeprom d'11' ; Read byte (stored in EEDATA) | |
1029 movf EEDATA,W | |
1030 call write_external_eeprom | |
1031 | |
1032 read_int_eeprom d'14' ; Read byte (stored in EEDATA) | |
1033 movf EEDATA,W | |
1034 call write_external_eeprom | |
1035 read_int_eeprom d'15' ; Read byte (stored in EEDATA) | |
1036 movf EEDATA,W | |
1037 call write_external_eeprom | |
1038 | |
1039 read_int_eeprom d'18' ; Read byte (stored in EEDATA) | |
1040 movf EEDATA,W | |
1041 call write_external_eeprom | |
1042 read_int_eeprom d'19' ; Read byte (stored in EEDATA) | |
1043 movf EEDATA,W | |
1044 call write_external_eeprom | |
1045 | |
1046 read_int_eeprom d'22' ; Read byte (stored in EEDATA) | |
1047 movf EEDATA,W | |
1048 call write_external_eeprom | |
1049 read_int_eeprom d'23' ; Read byte (stored in EEDATA) | |
1050 movf EEDATA,W | |
1051 call write_external_eeprom | |
1052 | |
1053 read_int_eeprom d'24' ; % O2 Gas6 | |
1054 movf EEDATA,W | |
1055 call write_external_eeprom | |
1056 read_int_eeprom d'25' ; % He Gas6 | |
1057 movf EEDATA,W | |
1058 call write_external_eeprom | |
1059 read_int_eeprom d'33' ; start gas | |
1060 movf EEDATA,W | |
1061 call write_external_eeprom | |
1062 | |
1063 movlw softwareversion_x ; Firmware version | |
1064 call write_external_eeprom | |
1065 movlw softwareversion_y | |
1066 call write_external_eeprom | |
1067 movf batt_voltage+0,W ; Battery voltage | |
1068 call write_external_eeprom | |
1069 movf batt_voltage+1,W | |
1070 call write_external_eeprom | |
1071 | |
1072 GETCUSTOM8 d'20' ; sampling rate in WREG | |
1073 btfsc FLAG_apnoe_mode ; Apnoe mode? | |
1074 movlw d'1' ; Apnoe sampling rate | |
1075 call write_external_eeprom | |
1076 | |
1077 movlw d'2' ; information size temperature | |
1078 movwf temp1 ; copy to bits 0-3 | |
1079 swapf temp1,F ; swap nibbels 0-3 with 4-7 | |
1080 GETCUSTOM8 d'21' ; Divisor temperature | |
1081 addwf temp1,W ; copy to bits 0-3, result in WREG | |
1082 call write_external_eeprom | |
1083 | |
1084 movlw d'2' ; information size deco | |
1085 movwf temp1 ; copy to bits 0-3 | |
1086 swapf temp1,F ; swap nibbels 0-3 with 4-7 | |
1087 GETCUSTOM8 d'22' ; Divisor deco | |
1088 addwf temp1,W ; copy to bits 0-3, result in WREG | |
1089 call write_external_eeprom | |
1090 | |
1091 movlw d'2' ; information size tank | |
1092 movwf temp1 ; copy to bits 0-3 | |
1093 swapf temp1,F ; swap nibbels 0-3 with 4-7 | |
1094 GETCUSTOM8 d'23' ; Divisor Tank | |
1095 addwf temp1,W ; copy to bits 0-3, result in WREG | |
1096 call write_external_eeprom | |
1097 | |
1098 movlw d'3' ; information size pp02 | |
1099 movwf temp1 ; copy to bits 0-3 | |
1100 swapf temp1,F ; swap nibbels 0-3 with 4-7 | |
1101 GETCUSTOM8 d'24' ; Divisor pp02 | |
1102 addwf temp1,W ; copy to bits 0-3, result in WREG | |
1103 call write_external_eeprom | |
1104 | |
1105 movlw d'9' ; information size Decodebug | |
1106 movwf temp1 ; copy to bits 0-3 | |
1107 swapf temp1,F ; swap nibbels 0-3 with 4-7 | |
1108 GETCUSTOM8 d'25' ; Divisor Decodebug | |
1109 addwf temp1,W ; copy to bits 0-3, result in WREG | |
1110 call write_external_eeprom | |
1111 | |
1112 movlw d'0' ; information size nuy2 | |
1113 movwf temp1 ; copy to bits 0-3 | |
1114 swapf temp1,F ; swap nibbels 0-3 with 4-7 | |
1115 GETCUSTOM8 d'26' ; Divisor nuy2 | |
1116 addwf temp1,W ; copy to bits 0-3, result in WREG | |
1117 call write_external_eeprom | |
1118 | |
1119 read_int_eeprom d'26' ; Read Salinity from EEPROM | |
1120 movf EEDATA,W | |
1121 call write_external_eeprom ; Store Salinity to Dive | |
1122 | |
1123 movlw d'0' ; Spare | |
1124 call write_external_eeprom | |
1125 | |
1126 movlw 0xFB ; Header stop | |
1127 call write_external_eeprom | |
1128 movlw 0xFB | |
1129 call write_external_eeprom | |
1130 | |
1131 ; Increase total dive counter | |
1132 read_int_eeprom d'2' ; Read byte (stored in EEDATA) | |
1133 movff EEDATA,temp1 ; Low byte | |
1134 read_int_eeprom d'3' ; Read byte (stored in EEDATA) | |
1135 movff EEDATA,temp2 ; high byte | |
1136 bcf STATUS,C | |
1137 movlw d'1' | |
1138 addwf temp1 | |
1139 movlw d'0' | |
1140 addwfc temp2 | |
1141 movff temp1,EEDATA | |
1142 write_int_eeprom d'2' ; write byte stored in EEDATA | |
1143 movff temp2,EEDATA | |
1144 write_int_eeprom d'3' ; write byte stored in EEDATA | |
1145 | |
1146 GETCUSTOM15 .28 ; Logbook Offset -> lo, hi | |
1147 tstfsz lo ; lo=0? | |
1148 bra change_logbook_offset1 ; No, adjust offset | |
1149 tstfsz hi ; hi=0? | |
1150 bra change_logbook_offset1 ; No, adjust offset | |
1151 bra change_logbook_offset2 ; lo=0 and hi=0 -> skip Offset routine | |
1152 change_logbook_offset1: | |
1153 movlw d'1' | |
1154 addwf lo | |
1155 movlw d'0' | |
1156 addwfc hi | |
1157 movlw d'112' ; CF28 *4 Bytes... | |
1158 addlw 0x82 | |
1159 movwf EEADR | |
1160 movff lo,EEDATA | |
1161 call write_eeprom ; Lowbyte | |
1162 movlw d'112' ; CF28 *4 Bytes... | |
1163 addlw 0x83 | |
1164 movwf EEADR | |
1165 movff hi,EEDATA | |
1166 call write_eeprom ; Highbyte | |
1167 | |
1168 change_logbook_offset2: | |
1169 bcf simulatormode_active ; if we were in simulator mode | |
1170 call clear_LEDusb | |
1171 | |
1172 end_dive_common: | |
1173 btfsc restore_deco_data ; Restore decodata? | |
1174 call simulator_restore_tissue_data ; Yes! | |
1175 | |
1176 call deco_main_gradient_array | |
1177 movlb b'00000001' ; select ram bank 1 | |
1178 | |
1179 clrf surface_interval+0 | |
1180 clrf surface_interval+1 ; Clear surface interval timer | |
1181 | |
1182 goto surfloop ; and return to surfaceloop | |
1183 | |
1184 timeout_divemode: | |
1185 btfss realdive ; Dive longer then one minute | |
1186 return | |
1187 | |
1188 btfsc FLAG_apnoe_mode ; In Apnoe mode? | |
1189 bra timeout_divemode2 ; Yes, use CF30 [min] for timeout | |
1190 | |
1191 btfsc simulatormode_active ; In Simulator mode? | |
1192 bra timeout_divemode3 ; Yes, use fixed 5 seconds timeout | |
1193 | |
1194 bcf divemode | |
1195 incf timeout_counter,F | |
1196 GETCUSTOM8 d'2' ; diveloop_timeout | |
1197 addlw d'2' ; adds two seconds in case timout=zero! | |
1198 btfsc STATUS,C ; > 255? | |
1199 movlw d'255' ; Set to 255... | |
1200 decf WREG,F ; Limit to 254 | |
1201 cpfsgt timeout_counter | |
1202 bsf divemode | |
1203 return | |
1204 | |
1205 timeout_divemode2: | |
1206 incf timeout_counter,F ; seconds... | |
1207 movlw d'60' | |
1208 cpfseq timeout_counter ; timeout_counter=60? | |
1209 return ; No. | |
1210 | |
1211 clrf timeout_counter | |
1212 bcf divemode | |
1213 incf apnoe_timeout_counter,F | |
1214 GETCUSTOM8 d'30' ; apnoe timeout [min] | |
1215 cpfseq apnoe_timeout_counter | |
1216 bsf divemode | |
1217 return | |
1218 | |
1219 timeout_divemode3: | |
1220 bcf divemode | |
1221 incf timeout_counter,F | |
1222 movlw d'5' ; Fixed timeout of 5 seconds | |
1223 cpfsgt timeout_counter | |
1224 bsf divemode | |
1225 return | |
1226 | |
1227 update_divemode1: ; update any second | |
1228 call set_dive_modes ; tests if depth>threshold | |
1229 | |
1230 btfsc divemode | |
1231 call set_max_depth ; update max. depth if required | |
1232 | |
1233 btfsc divemode | |
1234 call set_min_temp ; store min. temp if required | |
1235 | |
1236 bcf temp_changed ; Display temperature? | |
1237 movf temperature+0,W | |
1238 cpfseq last_temperature+0 | |
1239 bsf temp_changed ; Yes | |
1240 movf temperature+1,W | |
1241 cpfseq last_temperature+1 | |
1242 bsf temp_changed ; Yes | |
1243 btfsc temp_changed | |
1244 call PLED_temp_divemode ; Displays temperature | |
1245 | |
1246 bcf pres_changed ; Display new depth? | |
1247 movf amb_pressure+0,W | |
1248 cpfseq last_pressure+0 | |
1249 bsf pres_changed ; Yes | |
1250 movf amb_pressure+1,W | |
1251 cpfseq last_pressure+1 | |
1252 bsf pres_changed ; Yes | |
1253 | |
1254 btfsc simulatormode_active ; always update depth when in simulator mode | |
1255 bsf pres_changed | |
1256 | |
1257 btfsc pres_changed | |
1258 call PLED_depth ; Displays new depth | |
1259 return | |
1260 | |
1261 update_divemode60: ; update any minute | |
1262 call get_battery_voltage ; gets battery voltage | |
1263 call set_powersafe ; red LED blinking if battery is low | |
1264 call PLED_max_pressure ; No, use normal max. depth | |
1265 call check_temp_extrema ; check for new temperature extremas | |
1266 bcf oneminupdate | |
1267 return | |
1268 | |
1269 set_max_depth: | |
1270 movff max_pressure+0,sub_a+0 | |
1271 movff max_pressure+1,sub_a+1 | |
1272 movff rel_pressure+0,sub_b+0 | |
1273 movff rel_pressure+1,sub_b+1 | |
1274 call sub16 ; sub_c = sub_a - sub_b | |
1275 ; max_pressure<rel_pressure -> neg_flag=1 | |
1276 ; rel_pressure<=max_pressure -> neg_flag=0 | |
1277 btfss neg_flag | |
1278 return | |
1279 ;max_pressure<rel_pressure | |
1280 movff rel_pressure+0,max_pressure+0 | |
1281 movff rel_pressure+1,max_pressure+1 | |
1282 call PLED_max_pressure ; No, use normal max. depth | |
1283 return | |
1284 | |
1285 set_min_temp: | |
1286 movff mintemp+0,sub_a+0 | |
1287 movff mintemp+1,sub_a+1 | |
1288 movff temperature+0,sub_b+0 | |
1289 movff temperature+1,sub_b+1 | |
1290 call sub16 ; sub_c = sub_a - sub_b | |
1291 ; mintemp<T -> neg_flag=1 | |
1292 ; T<=mintemp -> neg_flag=0 | |
1293 btfsc neg_flag | |
1294 return | |
1295 ;mintemp>=T | |
1296 movff temperature+0,mintemp+0 | |
1297 movff temperature+1,mintemp+1 | |
1298 return | |
1299 | |
1300 set_dive_modes: | |
1301 bcf divemode2 ; Stop time | |
1302 | |
1303 GETCUSTOM8 .0 ; loads dive_threshold in WREG | |
1304 movwf sub_a+0 ; dive_treshold is in cm | |
1305 clrf sub_a+1 | |
1306 | |
1307 movff rel_pressure+0,sub_b+0 | |
1308 movff rel_pressure+1,sub_b+1 | |
1309 | |
1310 call sub16 ; sub_c = sub_a - sub_b | |
1311 | |
1312 btfss neg_flag | |
1313 bra set_dive_modes2 ; too shallow (rel_pressure<dive_threshold) | |
1314 | |
1315 btfsc realdive ; Dive longer than one minute? | |
1316 clrf timeout_counter | |
1317 | |
1318 bsf divemode | |
1319 bsf divemode2 ; displayed divetime is running | |
1320 return | |
1321 | |
1322 set_dive_modes2: | |
1323 btfss realdive ; dive longer then one minute? | |
1324 bcf divemode ; no -> this was no real dive | |
1325 return | |
1326 | |
1327 set_powersafe: | |
1328 btfsc low_battery_state ; battery warning alread active? | |
1329 bra set_powersafe2 ; Yes, but is it still required? | |
1330 ; battery voltage in mV (value*256+Lowbyte=actual treshold) | |
1331 movlw d'12' ; 3,328V | |
1332 cpfsgt batt_voltage+1 | |
1333 bra set_powersafe1 | |
1334 return | |
1335 | |
1336 set_powersafe1: | |
1337 movlw d'7' ; Type of Alarm (Battery Low) | |
1338 movwf AlarmType ; Copy to Alarm Register | |
1339 bsf event_occured ; Set Event Flag | |
1340 bsf low_battery_state ; set flag for battery warning | |
1341 return ; return | |
1342 | |
1343 set_powersafe2: | |
1344 movlw d'13' ; 3,584V | |
1345 cpfsgt batt_voltage+1 | |
1346 bra set_powersafe1 ; Still to low | |
1347 bcf low_battery_state ; clear flag for battery warning mode | |
1348 return | |
1349 | |
1350 calc_average_depth: | |
1351 ; 1. Add new 2xdepth to the Sum of depths registers | |
1352 movff rel_pressure+0,b0_lo | |
1353 movff rel_pressure+1,b0_hi | |
1354 | |
1355 movf b0_lo,w | |
1356 addwf average_depth_hold+0,F | |
1357 movf b0_hi,w | |
1358 addwfc average_depth_hold+1,F | |
1359 movlw d'0' | |
1360 addwfc average_depth_hold+2,F | |
1361 addwfc average_depth_hold+3,F ; Will work up to 9999mBar*60*60*24=863913600mBar | |
1362 | |
1363 movf b0_lo,w | |
1364 addwf average_depth_hold+0,F | |
1365 movf b0_hi,w | |
1366 addwfc average_depth_hold+1,F | |
1367 movlw d'0' | |
1368 addwfc average_depth_hold+2,F | |
1369 addwfc average_depth_hold+3,F ; Will work up to 9999mBar*60*60*24=863913600mBar | |
1370 | |
1371 ; 2. Compute Average Depth on base of average_divesecs:2 | |
1372 | |
1373 movff average_divesecs+0,xB+0 | |
1374 movff average_divesecs+1,xB+1 ; Copy | |
1375 movff average_depth_hold+0,xC+0 | |
1376 movff average_depth_hold+1,xC+1 | |
1377 movff average_depth_hold+2,xC+2 | |
1378 movff average_depth_hold+3,xC+3 | |
1379 | |
1380 call div32x16 ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder | |
1381 movff xC+0,avr_rel_pressure+0 | |
1382 movff xC+1,avr_rel_pressure+1 | |
1383 return | |
1384 | |
1385 | |
1386 diveloop_boot: | |
1387 ostc_debug 'Q' ; Sends debug-information to screen if debugmode active | |
1388 clrf max_pressure+0 ; clear some variables | |
1389 clrf max_pressure+1 | |
1390 | |
1391 clrf avr_rel_pressure+0 | |
1392 clrf avr_rel_pressure+1 | |
1393 | |
1394 call PLED_brightness_low | |
1395 read_int_eeprom d'90' ; Brightness offset? (Dim>0, Normal = 0) | |
1396 movlw d'0' | |
1397 cpfsgt EEDATA | |
1398 call PLED_brightness_full | |
1399 | |
1400 clrf average_depth_hold+0 | |
1401 clrf average_depth_hold+1 | |
1402 clrf average_depth_hold+2 | |
1403 clrf average_depth_hold+3 ; Clear average depth register | |
1404 movlw d'1' | |
1405 movwf average_divesecs+0 | |
1406 clrf average_divesecs+1 | |
1407 | |
1408 movlw d'1' | |
1409 movwf apnoe_max_pressure+0 | |
1410 clrf apnoe_max_pressure+1 | |
1411 clrf apnoe_surface_mins | |
1412 clrf apnoe_surface_secs | |
1413 clrf apnoe_mins | |
1414 clrf apnoe_secs | |
1415 clrf divemins+0 | |
1416 clrf divemins+1 | |
1417 clrf divesecs | |
1418 clrf samplesecs | |
1419 clrf apnoe_timeout_counter ; timeout in minutes | |
1420 clrf timeout_counter ; takes care of the timeout | |
1421 clrf timeout_counter2 ; Here: counts to six, then store deco data and temperature | |
1422 clrf AlarmType ; Clear all alarms | |
1423 bcf event_occured ; clear flag | |
1424 bcf depth_greater_100m ; clear flag | |
1425 setf last_diluent ; to be displayed after first calculation (range: 0 to 100 [%]) | |
1426 clrf char_last_pointer | |
1427 bcf dekostop_active | |
1428 call get_free_EEPROM_location ; get last position in external EEPROM, may be up to 2 secs! | |
1429 | |
1430 movff last_surfpressure_30min+1,int_I_pres_surface+1 ; HIGH copy surfacepressure to deco routine | |
1431 movff last_surfpressure_30min+0,int_I_pres_surface+0 ; LOW copy surfacepressure to deco routine | |
1432 movff temperature+0,mintemp+0 ; Reset Min-Temp registers | |
1433 movff temperature+1,mintemp+1 ; Reset Min-Temp registers | |
1434 | |
1435 clrf wait_temp ; Used to clear Bankx registers | |
1436 movff wait_temp,char_O_GF_low_pointer | |
1437 movff wait_temp,char_O_actual_pointer | |
1438 lfsr FSR0,0x250 | |
1439 movlw 0x20 | |
1440 movwf wait_temp | |
1441 clear_deco_lists: ; Clear Deco list | |
1442 clrf POSTINC0 | |
1443 decfsz wait_temp,F | |
1444 bra clear_deco_lists | |
1445 lfsr FSR0,0x270 | |
1446 movlw 0x20 | |
1447 movwf wait_temp | |
1448 set_no_forced_stops: ; Init Deco list | |
1449 movlw 0x01 | |
1450 movwf POSTINC0 | |
1451 decfsz wait_temp,F | |
1452 bra set_no_forced_stops | |
1453 lfsr FSR0,0x290 ; clear int_O_calc_tissue_call_counter (DEBUG) | |
1454 clrf POSTINC0 | |
1455 clrf POSTINC0 | |
1456 | |
1457 ; Load GF values into RAM | |
1458 GETCUSTOM8 d'32' ; GF low | |
1459 movff EEDATA,char_I_GF_Lo_percentage | |
1460 GETCUSTOM8 d'33' ; GF high | |
1461 movff EEDATA,char_I_GF_Hi_percentage | |
1462 | |
1463 ; Start with active Stopwatch? | |
1464 bsf stopwatch_active | |
1465 GETCUSTOM8 d'41' ; =1: Start with active Stopwatch | |
1466 movwf lo | |
1467 movlw d'1' | |
1468 cpfseq lo ; CF41=1? | |
1469 bcf stopwatch_active ; No! | |
1470 | |
1471 ; Init profile recording parameters | |
1472 GETCUSTOM8 d'20' ; sample rate | |
1473 movwf samplesecs_value ; to avoid EEPROM access in the ISR | |
1474 GETCUSTOM8 d'21' | |
1475 movwf divisor_temperature ; load divisors for profile storage | |
1476 GETCUSTOM8 d'22' | |
1477 movwf divisor_deco | |
1478 GETCUSTOM8 d'23' | |
1479 movwf divisor_tank | |
1480 GETCUSTOM8 d'24' | |
1481 movwf divisor_ppo2 | |
1482 GETCUSTOM8 d'25' | |
1483 movwf divisor_deco_debug | |
1484 GETCUSTOM8 d'26' | |
1485 movwf divisor_nuy2 | |
1486 | |
1487 btfss FLAG_apnoe_mode ; In Apnoe mode? | |
1488 bra divemode1 | |
1489 ; Overwrite some parameters in Apnoe mode.... | |
1490 movlw d'1' | |
1491 movwf samplesecs_value ; to avoid EEPROM access in the ISR | |
1492 | |
1493 divemode1: | |
1494 read_int_eeprom d'36' ; Read mix 1 ppO2 | |
1495 btfsc FLAG_const_ppO2_mode | |
1496 movff EEDATA,char_I_const_ppO2 ; Set ppO2 setpoint if in ppO2 mode | |
1497 | |
1498 call clear_LEDnofly ; Clear flags | |
1499 bcf low_battery_state ; clear flag for battery warning mode | |
1500 bcf header_stored | |
1501 bcf premenu | |
1502 bcf realdive | |
1503 bsf update_divetime ; set flag | |
1504 btfss simulatormode_active ; do not disable in simulator mode! | |
1505 call disable_rs232 ; Disable RS232 unless in external O2 Sensor mode | |
1506 | |
1507 read_int_eeprom d'33' ; Read byte (stored in EEDATA) | |
1508 movff EEDATA,active_gas ; Read start gas (1-5) | |
1509 | |
1510 ; Read Start Gas and configure char_I_He_ratio, char_I_O2_ratio and char_I_N2_ratio | |
1511 decf active_gas,W ; Gas 0-4 | |
1512 mullw d'4' | |
1513 movf PRODL,W | |
1514 addlw d'7' ; = address for He ratio | |
1515 movwf EEADR | |
1516 call read_eeprom ; Read He ratio | |
1517 movff EEDATA,char_I_He_ratio ; And copy into hold register | |
1518 decf active_gas,W ; Gas 0-4 | |
1519 mullw d'4' | |
1520 movf PRODL,W | |
1521 addlw d'6' ; = address for O2 ratio | |
1522 movwf EEADR | |
1523 call read_eeprom ; Read O2 ratio | |
1524 movff EEDATA, char_I_O2_ratio ; O2 ratio | |
1525 movff char_I_He_ratio, wait_temp ; copy into bank1 register | |
1526 bsf STATUS,C ; Borrow bit | |
1527 movlw d'100' ; 100% | |
1528 subfwb wait_temp,W ; minus He | |
1529 bsf STATUS,C ; Borrow bit | |
1530 subfwb EEDATA,F ; minus O2 | |
1531 movff EEDATA, char_I_N2_ratio ; = N2! | |
1532 | |
1533 ; New in 1.09 - DecoGas can be configured to achieve exact decompression proposal | |
1534 ; required variables | |
1535 ; These values are set when the OSTC is in decompression mode - will be done in routine "check_decogas" | |
1536 ; char_I_deco_gas_change; ; next gas change in meter | |
1537 ; char_I_deco_N2_ratio; ; next gas N2 | |
1538 ; char_I_deco_He_ratio; ; next gas He | |
1539 clrf lo | |
1540 movff lo, char_I_deco_gas_change ; clear | |
1541 movff lo, char_I_deco_N2_ratio ; clear | |
1542 movff lo, char_I_deco_He_ratio ; clear | |
1543 bcf multi_gf_display ; Do not display the multi-gf table screen | |
1544 return |