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
|
|
55 btfss pre_dive_screen ; Show predive screen
|
|
56 call PLED_tissue_saturation_graph ; no, display saturation graph
|
|
57 btfsc pre_dive_screen ; Show predive screen
|
|
58 call PLED_pre_dive_screen ; yes, display Pre-Dive Screen
|
|
59
|
0
|
60 call PLED_active_gas_surfmode ; Show start gas
|
|
61 call PLED_display_decotype_surface ; Show deco mode (ZH-L16, const. ppO2 or Multi-GF)
|
|
62
|
|
63 surfloop1:
|
|
64 btfss gauge_mode ; Display only in gauge mode
|
|
65 bra surfloop2
|
|
66 DISPLAYTEXT d'103' ; Gauge mode
|
|
67 surfloop2:
|
|
68 btfss FLAG_apnoe_mode ; Display only in Apnoe mode
|
|
69 bra surfloop3
|
|
70 DISPLAYTEXT d'116' ; Apnoe mode
|
|
71
|
|
72 surfloop3:
|
|
73 ; Startup tasks for all modes
|
|
74 clrf timeout_counter2
|
|
75 clrf timeout_counter3
|
|
76 bcf premenu ; clear premenu flag
|
|
77 bcf menubit ; clear menu flag
|
|
78 bcf pressure_refresh
|
|
79 clrf last_pressure+0
|
|
80 clrf last_pressure+1
|
|
81 clrf last_temperature+0
|
|
82 clrf last_temperature+1
|
|
83
|
|
84 movlw d'5'
|
|
85 movwf timeout_counter ; reload counter
|
|
86
|
21
|
87 bcf LED_blue
|
|
88 bcf LED_red
|
0
|
89 bcf simulatormode_active ; Quit simulator mode (if active)
|
|
90 bcf standalone_simulator ; Quit simulator mode (if active)
|
|
91 WIN_TOP .0
|
|
92 WIN_LEFT .0
|
|
93 WIN_FONT FT_SMALL
|
|
94 WIN_INVERT .0 ; Init new Wordprocessor
|
3
|
95 call PLED_standard_color
|
|
96
|
0
|
97 bcf switch_left
|
|
98 bcf switch_right
|
4
|
99 call PLED_active_gas_surfmode ; Show start gas / SetPoint
|
0
|
100 call PLED_custom_text ; Displays custom text
|
|
101 movlw d'1' ; next cf to check
|
|
102 movwf cf_checker_counter ;
|
|
103 ostc_debug 'G' ; Sends debug-information to screen if debugmode active
|
|
104 GETCUSTOM8 d'12' ; Desaturation multiplier %
|
|
105 movwf wait_temp
|
|
106 movff wait_temp,char_I_desaturation_multiplier
|
|
107 GETCUSTOM8 d'11' ; Saturation multiplier %
|
|
108 movwf wait_temp
|
|
109 movff wait_temp,char_I_saturation_multiplier
|
|
110 call deco_main_calc_desaturation_time; calculate desaturation time
|
|
111 movlb b'00000001' ; select ram bank 1
|
|
112 ostc_debug 'H' ; Sends debug-information to screen if debugmode active
|
|
113
|
|
114 call wait_switches ; Waits until switches are released, resets flag if button stays pressed!
|
|
115
|
|
116 surfloop_loop:
|
|
117 btfss onesecupdate ; do every second tasks?
|
|
118 bra surfloop_loop2 ; no, loop
|
|
119
|
|
120 btfss FLAG_const_ppO2_mode ; are we in const. ppO2 mode?
|
|
121 bra surfloop_loop1 ; No
|
|
122 ; One Second tasks for ppO2 modes
|
|
123
|
|
124 bra surfloop_loop1 ; Do not search for sensor in CC mode
|
|
125
|
|
126
|
|
127 surfloop_loop1:
|
|
128 ; One Second tasks for all modes
|
|
129 call PLED_clock ; update clock
|
|
130 call test_charger ; check if charger IC is active
|
|
131 call timeout_surfmode ; check timeout
|
|
132 call get_battery_voltage ; get battery voltage
|
|
133 call update_batt_voltage ; display battery voltage
|
|
134 call timeout_premenu ; timeout premenu
|
|
135 call set_leds_surfmode ; Sets Warning and No-Fly LEDs
|
|
136 call custom_functions_check_surfmode ; Checks CF functions and displays warning symbol if something critical is wrong
|
4
|
137 ; call PLED_active_gas_surfmode ; Show start gas / SetPoint
|
0
|
138 call PLED_display_decotype_surface ; Show deco mode
|
|
139 btfsc enter_error_sleep ; Enter Fatal Error Routine?
|
16
|
140 call fatal_error_sleep ; Yes (In Sleepmode_vxx.asm!)
|
0
|
141 bcf onesecupdate ; every second tasks done
|
|
142
|
|
143 surfloop_loop2:
|
|
144 ; Tasks approx. every 50ms for all modes
|
|
145 call test_switches_surfmode ; check switches
|
|
146
|
|
147 ; Sensor tasks for all modes
|
|
148 btfsc pressure_refresh ; new pressure available?
|
|
149 call update_surf_press ; display surface pressure
|
|
150 btfsc pressure_refresh ; new temperature available?
|
|
151 call PLED_temp_surfmode ; Displays temperature
|
|
152 btfsc pressure_refresh ; new pressure available?
|
|
153 call set_dive_modes ; tests if depth>threshold
|
|
154 bcf pressure_refresh ; until new pressure is available
|
|
155
|
|
156 ; One minute tasks for all modes
|
|
157 btfsc oneminupdate ; do every minute tasks
|
|
158 call update_surfloop60 ; yes, e.g. update time and date
|
|
159
|
|
160 ; Mode tasks
|
|
161 btfsc menubit ; Menu?
|
|
162 goto menu ; Menu!
|
|
163 btfsc divemode ; Divemode active?
|
|
164 goto diveloop ; Yes, switch into Divemode!
|
|
165 btfsc sleepmode ; Sleepmode active?
|
|
166 goto sleeploop ; Yes, switch into sleepmode!
|
|
167 ; Check for the different UART flags
|
|
168 btfsc dump_external_eeprom ; Start interface (dumps EEPROM BANK 0 + additional data)?
|
|
169 goto menu_interface ; Yes!
|
|
170 btfsc uart_settime ; Sync clock with PC?
|
|
171 goto sync_clock ; Yes!
|
|
172 btfsc internal_eeprom_write ; Access internal EEPROM BANK 0 via UART module
|
|
173 goto internal_eeprom_access_b0 ; Yes!
|
|
174 btfsc internal_eeprom_write2 ; Access internal EEPROM BANK 1 via UART module
|
|
175 goto internal_eeprom_access_b1 ; Yes!
|
|
176 btfsc uart_send_hash ; Send MD2 hash values
|
|
177 goto send_md2_hash ; Yes!
|
|
178 btfsc uart_compensate_temp ; Enter temp. compensation routine?
|
|
179 goto compensate_temperature ; Yes!
|
|
180 btfsc uart_send_int_eeprom ; Send internal EEPROM BANK 0
|
|
181 goto send_int_eeprom_b0 ; Yes!
|
|
182 btfsc uart_reset_decodata ; Reset Deco Data?
|
|
183 goto reset_decodata ; Yes!
|
|
184 btfsc uart_send_int_eeprom2 ; Send internal EEPROM BANK 1
|
|
185 goto send_int_eeprom_b1 ; Yes!
|
|
186 btfsc uart_store_tissue_data ; Store tissue data?`
|
|
187 goto uart_store_tissues ; Yes!
|
|
188
|
|
189 bra surfloop_loop ; loop surfacemode
|
|
190
|
|
191
|
|
192 update_surfloop60:
|
|
193 ; One minute tasks for all modes
|
4
|
194 ; call PLED_active_gas_surfmode ; Show start gas / SetPoint
|
0
|
195 call update_date ; and date in divemode
|
|
196 call calc_deko_surfmode ; calculate desaturation every minute
|
|
197 call check_temp_extrema ; check for new temperature extremas
|
|
198 call PLED_custom_text ; Displays custom text
|
|
199 call calc_surface_interval ; Increases Surface-Interval time
|
|
200
|
|
201 btfsc gauge_mode ; Ignore in gauge mode
|
|
202 bra update_surfloop60_2
|
|
203 btfsc FLAG_apnoe_mode ; Ignore in Apnoe mode
|
|
204 bra update_surfloop60_2
|
|
205
|
|
206 ; One Minute tasks for deco modes
|
43
|
207 call PLED_display_cns_surface ; Update surface CNS display (If allowed by CF15)
|
0
|
208 call PLED_nofly_time ; display nofly time
|
|
209 call PLED_desaturation_time ; display desaturation time
|
13
|
210 btfsc premenu ; Not when "Menu?" is displayed!
|
|
211 bra update_surfloop60_2
|
|
212
|
|
213 btfss pre_dive_screen ; Show predive screen
|
|
214 call PLED_tissue_saturation_graph ; no, display saturation graph
|
|
215 btfsc pre_dive_screen ; Show predive screen
|
|
216 call PLED_pre_dive_screen ; yes, display Pre-Dive Screen
|
0
|
217
|
|
218 update_surfloop60_2:
|
|
219 call nofly_timeout60 ; checks if nofly time is > 0
|
|
220 bcf oneminupdate
|
|
221 return
|
|
222
|
|
223 nofly_timeout60:
|
|
224 bsf nofly_active ; Set flag
|
|
225 movlw d'1'
|
|
226 subwf nofly_time+0,F
|
|
227 movlw d'0'
|
|
228 subwfb nofly_time+1,F ; reduce by one
|
|
229 tstfsz nofly_time+0 ; =0?
|
|
230 return
|
|
231 tstfsz nofly_time+1 ; =0?
|
|
232 return
|
|
233 bcf nofly_active ; Clear flag
|
21
|
234 bcf LED_blue
|
0
|
235 incf nofly_time+0,F ; =1
|
|
236 return
|
|
237
|
|
238 calc_surface_interval:
|
|
239 movff int_O_desaturation_time+0,lo ; divide by 60...
|
|
240 movff int_O_desaturation_time+1,hi
|
|
241 tstfsz lo ;=0?
|
|
242 bra calc_surface_interval2 ; No
|
|
243 tstfsz hi ;=0?
|
|
244 bra calc_surface_interval2 ; No
|
|
245 clrf surface_interval+0
|
|
246 clrf surface_interval+1 ; Clear surface interval timer
|
|
247 return
|
|
248
|
|
249 calc_surface_interval2: ; Increase surface interval timer
|
|
250 movlw d'1'
|
|
251 addwf surface_interval+0,F
|
|
252 movlw d'0'
|
|
253 addwfc surface_interval+1,F
|
|
254 return
|
|
255
|
|
256 set_leds_surfmode:
|
|
257 btfsc nofly_active
|
21
|
258 btg LED_blue
|
0
|
259 return
|
|
260
|
|
261 calc_deko_surfmode:
|
21
|
262 bsf LED_red
|
0
|
263 ostc_debug 'I' ; Sends debug-information to screen if debugmode active
|
|
264
|
|
265 movff last_surfpressure+0,int_I_pres_surface+0 ; copy surface air pressure to deco routine
|
|
266 movff last_surfpressure+1,int_I_pres_surface+1
|
|
267 clrf wait_temp ; Use as buffer
|
|
268 movff wait_temp,char_I_He_ratio ; No He at the Surface
|
|
269 movlw d'79' ; 79% N2
|
|
270 movwf wait_temp ; Use as buffer
|
|
271 movff wait_temp,char_I_N2_ratio ; No He at the Surface
|
|
272
|
|
273 movff amb_pressure+0,int_I_pres_respiration+0 ; copy surface air pressure to deco routine
|
|
274 movff amb_pressure+1,int_I_pres_respiration+1
|
|
275 GETCUSTOM8 d'11' ; Saturation multiplier %
|
|
276 movwf wait_temp
|
|
277 movff wait_temp,char_I_saturation_multiplier
|
|
278 GETCUSTOM8 d'12' ; Desaturation multiplier %
|
|
279 movwf wait_temp
|
|
280 movff wait_temp,char_I_desaturation_multiplier
|
|
281
|
|
282 call deco_main_calc_wo_deco_step_1_m ; calculate deco in surface mode
|
|
283 movlb b'00000001' ; select ram bank 1
|
|
284 ostc_debug 'J' ; Sends debug-information to screen if debugmode active
|
21
|
285 bcf LED_red
|
0
|
286 return
|
|
287
|
|
288
|
|
289 test_charger:
|
|
290 bcf TRISC,1 ; CHRG_OUT output
|
|
291 bsf CHRG_OUT
|
|
292
|
|
293 bcf cc_active ; Constant Current mode active?
|
|
294 btfss CHRG_IN ; If CHRG_IN=0 -> CC active
|
|
295 bsf cc_active ; Constant Current mode Active!
|
|
296
|
|
297 bcf CHRG_OUT
|
|
298 bsf TRISC,1 ; CHRG_OUT high impedance
|
|
299
|
|
300 WAIT10US d'10'
|
|
301
|
|
302 bcf cv_active ; Constant Voltage mode Active?
|
|
303 btfss CHRG_IN ; If CHRG_IN=0 -> CV active
|
|
304 bsf cv_active ; Constant Voltage mode active!
|
|
305
|
|
306 bcf TRISC,1 ; CHRG_OUT output
|
|
307 bcf CHRG_OUT
|
|
308
|
|
309 btfsc cc_active
|
|
310 bra show_cc_active
|
|
311 btfsc cv_active
|
|
312 bra show_cv_active
|
|
313
|
|
314 bsf TRISC,1 ; CHRG_OUT high impedance
|
|
315
|
|
316 ; Charger inactive or ready
|
|
317 btfss charge_done ; charge done?
|
|
318 bra test_charger2 ; No, add incomplete cycle!
|
|
319
|
|
320 ; Yes, store all data for complete cycle
|
|
321 bcf charge_started ; Clear flag
|
|
322 bcf charge_done ; Clear flag
|
|
323 ; Store incomplete/total cycles
|
|
324 read_int_eeprom d'50' ; Read byte (stored in EEDATA)
|
|
325 movff EEDATA,temp1 ; Low byte
|
|
326 read_int_eeprom d'51' ; Read byte (stored in EEDATA)
|
|
327 movff EEDATA,temp2 ; high byte
|
|
328 bcf STATUS,C
|
|
329 movlw d'1'
|
|
330 addwf temp1
|
|
331 movlw d'0'
|
|
332 addwfc temp2
|
|
333 movff temp1,EEDATA
|
|
334 write_int_eeprom d'50' ; write byte stored in EEDATA
|
|
335 movff temp2,EEDATA
|
|
336 write_int_eeprom d'51' ; write byte stored in EEDATA
|
|
337
|
|
338 ; Store complete cycles
|
|
339 read_int_eeprom d'52' ; Read byte (stored in EEDATA)
|
|
340 movff EEDATA,temp1 ; Low byte
|
|
341 read_int_eeprom d'53' ; Read byte (stored in EEDATA)
|
|
342 movff EEDATA,temp2 ; high byte
|
|
343 bcf STATUS,C
|
|
344 movlw d'1'
|
|
345 addwf temp1
|
|
346 movlw d'0'
|
|
347 addwfc temp2
|
|
348 movff temp1,EEDATA
|
|
349 write_int_eeprom d'52' ; write byte stored in EEDATA
|
|
350 movff temp2,EEDATA
|
|
351 write_int_eeprom d'53' ; write byte stored in EEDATA
|
|
352 ; Store date of complete cycle
|
|
353 movff month,EEDATA
|
|
354 write_int_eeprom d'47'
|
|
355 movff day,EEDATA
|
|
356 write_int_eeprom d'48'
|
|
357 movff year,EEDATA
|
|
358 write_int_eeprom d'49'
|
|
359
|
|
360 return
|
|
361
|
|
362 test_charger2:
|
|
363 btfss charge_started ; Did the charger ever start?
|
|
364 return ; No, quit!
|
|
365
|
|
366 bcf charge_started ; Clear flag
|
|
367 ; Store incomplete/total cycles
|
|
368 read_int_eeprom d'50' ; Read byte (stored in EEDATA)
|
|
369 movff EEDATA,temp1 ; Low byte
|
|
370 read_int_eeprom d'51' ; Read byte (stored in EEDATA)
|
|
371 movff EEDATA,temp2 ; high byte
|
|
372 bcf STATUS,C
|
|
373 movlw d'1'
|
|
374 addwf temp1
|
|
375 movlw d'0'
|
|
376 addwfc temp2
|
|
377 movff temp1,EEDATA
|
|
378 write_int_eeprom d'50' ; write byte stored in EEDATA
|
|
379 movff temp2,EEDATA
|
|
380 write_int_eeprom d'51' ; write byte stored in EEDATA
|
|
381 return
|
|
382
|
|
383 show_cv_active: ; CV mode
|
21
|
384 bsf LED_red
|
0
|
385 WAITMS d'100'
|
21
|
386 bcf LED_red
|
0
|
387 WAITMS d'100'
|
21
|
388 bsf LED_red
|
0
|
389 bsf charge_done ; Charge cycle finished
|
|
390 return
|
|
391
|
|
392 show_cc_active: ; CC mode
|
21
|
393 bsf LED_red
|
0
|
394 bsf charge_started ; Charger started in CC mode
|
|
395 bcf charge_done ; Charge cycle not finished
|
|
396 return
|
|
397
|
|
398
|
|
399 timeout_premenu:
|
|
400 btfss premenu ; is "Menu?" displayed?
|
|
401 return ; No
|
|
402 incf timeout_counter3,F ; Yes...
|
|
403 GETCUSTOM8 d'4' ; loads premenu_timeout into WREG
|
|
404 cpfsgt timeout_counter3 ; ... longer then premenu_timeout
|
|
405 return ; No!
|
|
406 bcf premenu ; Yes, so clear "Menu?" and clear pre_menu bit
|
|
407
|
|
408 call PLED_topline_box_clear ; Clears Bar at the top
|
|
409
|
|
410 btfsc gauge_mode
|
|
411 bra timeout_premenu2 ; Skip in Gauge mode
|
|
412 btfsc FLAG_apnoe_mode
|
|
413 bra timeout_premenu2 ; Skip in Apnoe mode
|
13
|
414
|
|
415 btfss pre_dive_screen ; Show predive screen
|
|
416 call PLED_tissue_saturation_graph ; no, display saturation graph
|
|
417 btfsc pre_dive_screen ; Show predive screen
|
|
418 call PLED_pre_dive_screen ; yes, display Pre-Dive Screen
|
|
419
|
0
|
420 timeout_premenu2:
|
|
421 call update_surf_press ; rewrite serial number
|
|
422 call PLED_serial ; rewrite serial number
|
|
423 clrf timeout_counter3 ; Also clear timeout
|
|
424 bcf switch_left ; and debounce switches
|
|
425 bcf switch_right
|
|
426 return
|
|
427
|
|
428 test_switches_surfmode: ; checks switches in surfacemode
|
|
429 btfsc switch_left
|
|
430 bra test_switches_surfmode2
|
|
431 btfsc switch_right
|
|
432 bra test_switches_surfmode3
|
|
433
|
|
434 ; No button press, reset timer0
|
|
435 bcf T0CON,TMR0ON ; Stop Timer 0
|
|
436 bcf INTCON,TMR0IF ; Clear flag
|
|
437 clrf TMR0H
|
|
438 clrf TMR0L
|
|
439 bcf INTCON,INT0IF ; Clear flag
|
|
440 bcf INTCON3,INT1IF ; Clear flag
|
|
441 return
|
|
442
|
|
443 test_switches_surfmode3:
|
|
444 bcf switch_right
|
|
445 call PLED_topline_box ; Write a filled bar at the top
|
|
446 WIN_INVERT .1 ; Init new Wordprocessor
|
|
447 DISPLAYTEXT .4 ;Menu?
|
|
448 WIN_INVERT .0 ; Init new Wordprocessor
|
|
449 bsf premenu
|
|
450 clrf timeout_counter2
|
|
451 return
|
|
452
|
|
453 test_switches_surfmode2:
|
|
454 bcf switch_left
|
|
455 btfss premenu
|
13
|
456 bra test_switches_surfmode4
|
0
|
457 bsf menubit ; Enter Menu!
|
|
458 return
|
|
459
|
13
|
460 test_switches_surfmode4:
|
|
461 btg pre_dive_screen
|
0
|
462
|
13
|
463 btfss pre_dive_screen ; Show predive screen
|
|
464 call PLED_tissue_saturation_graph ; no, display saturation graph
|
|
465 btfsc pre_dive_screen ; Show predive screen
|
|
466 call PLED_pre_dive_screen ; yes, display Pre-Dive Screen
|
|
467
|
|
468 return
|
0
|
469
|
|
470 timeout_surfmode:
|
|
471 incf timeout_counter2,F ; increase timeout counter
|
|
472 GETCUSTOM8 d'3' ; loads surfloop_timeout into WREG
|
|
473 addlw d'5' ; adds five seconds in case timout=zero!
|
|
474 btfsc STATUS,C ; > 255?
|
|
475 movlw d'255' ; Set to 255...
|
|
476 decf WREG,F ; Limit to 254
|
|
477 cpfsgt timeout_counter2 ; Compare with timeout_counter2
|
|
478 return ; return, no timeout
|
|
479 bsf sleepmode ; Set Flag
|
|
480 return ; Return
|