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