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