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