comparison code_part1/OSTC_code_asm_part1/surfmode.asm @ 0:96a35aeda5f2

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