Mercurial > public > mk2
comparison code_part1/OSTC_code_asm_part1/divemode.asm @ 49:cd5b650920f6
1.70...
author | heinrichsweikamp |
---|---|
date | Wed, 28 Jul 2010 15:40:03 +0200 |
parents | 56aea9fcdd8f |
children | fee7c62b4de1 |
comparison
equal
deleted
inserted
replaced
48:ebc5abda180d | 49:cd5b650920f6 |
---|---|
268 | 268 |
269 calc_deko_divemode: | 269 calc_deko_divemode: |
270 btfsc twosecupdate ; two seconds after the last call | 270 btfsc twosecupdate ; two seconds after the last call |
271 bra calc_deko_divemode2 ; Yes, calculate and display deco data ("first second") | 271 bra calc_deko_divemode2 ; Yes, calculate and display deco data ("first second") |
272 | 272 |
273 bsf twosecupdate ; No, but next second! | |
273 ; Routines used in the "other second" | 274 ; Routines used in the "other second" |
274 | |
275 bsf twosecupdate ; No, but next second! | |
276 call calc_average_depth ; calculate average depth | 275 call calc_average_depth ; calculate average depth |
277 call calc_velocity ; calculate vertical velocity and display if > threshold (every two seconds) | 276 call calc_velocity ; calculate vertical velocity and display if > threshold (every two seconds) |
278 | 277 |
279 ; calculate ppO2 in 0.1Bar (e.g. 150 = 1.50Bar ppO2) | 278 ; calculate ppO2 in 0.1Bar (e.g. 150 = 1.50Bar ppO2) |
280 movff amb_pressure+0,xA+0 | 279 movff amb_pressure+0,xA+0 |
281 movff amb_pressure+1,xA+1 | 280 movff amb_pressure+1,xA+1 |
282 movlw LOW d'10' | 281 movlw d'10' |
283 movwf xB+0 | 282 movwf xB+0 |
284 movlw HIGH d'10' | |
285 clrf xB+1 | 283 clrf xB+1 |
286 call div16x16 ; xC=p_amb/10 | 284 call div16x16 ; xC=p_amb/10 |
287 movff xC+0,xA+0 | 285 movff xC+0,xA+0 |
288 movff xC+1,xA+1 | 286 movff xC+1,xA+1 |
289 movff char_I_O2_ratio,xB+0 | 287 movff char_I_O2_ratio,xB+0 |
290 clrf xB+1 | 288 clrf xB+1 |
291 call mult16x16 ; char_I_O2_ratio * p_amb/10 | 289 call mult16x16 ; char_I_O2_ratio * p_amb/10 |
292 movff xC+0,xA+0 | 290 movff xC+0,xA+0 |
293 movff xC+1,xA+1 | 291 movff xC+1,xA+1 |
294 movlw LOW d'100' | 292 movlw d'100' |
295 movwf xB+0 | 293 movwf xB+0 |
296 movlw HIGH d'100' | |
297 clrf xB+1 | 294 clrf xB+1 |
298 call div16x16 ; xC=(char_I_O2_ratio * p_amb/10)/100 | 295 call div16x16 ; xC=(char_I_O2_ratio * p_amb/10)/100 |
299 | 296 |
300 ; Copy ppO2 for CNS calculation | 297 ; Copy ppO2 for CNS calculation |
301 movff xC+0, char_I_actual_ppO2 ; copy last ppO2 to buffer register | 298 movff xC+0, char_I_actual_ppO2 ; copy last ppO2 to buffer register |
310 movff char_O_CNS_fraction,lo ; copy into bank1 | 307 movff char_O_CNS_fraction,lo ; copy into bank1 |
311 GETCUSTOM8 d'27' ; cns_display_high | 308 GETCUSTOM8 d'27' ; cns_display_high |
312 subwf lo,W | 309 subwf lo,W |
313 btfsc STATUS,C | 310 btfsc STATUS,C |
314 call PLED_display_cns ; Show CNS | 311 call PLED_display_cns ; Show CNS |
315 | |
316 call check_gas_change ; Checks if a better gas should be selected (by user) | 312 call check_gas_change ; Checks if a better gas should be selected (by user) |
317 | 313 |
318 ; Check for decompression gases if in decomode | 314 ; Check for decompression gases if in decomode |
319 btfss dekostop_active | 315 btfss dekostop_active |
320 bra reset_decompression_gases ; While in NDL, do not set deompression gas | 316 bra reset_decompression_gases ; While in NDL, do not set deompression gas |
321 | 317 |
322 divemode_check_decogases: ; CALLed from Simulator | 318 divemode_check_decogases: ; CALLed from Simulator |
323 ; Copy active gases to char_I_deco_N2_ratio and char_I_deco_He_ratio | 319 ; Copy active gases to char_I_deco_N2_ratio and char_I_deco_He_ratio |
324 | 320 read_int_eeprom d'97' ; Read He ratio |
325 clrf EEADRH | 321 movff EEDATA,char_I_deco_He_ratio5 ; And copy into hold register |
326 setf hi ; # of gas (0-4) | 322 read_int_eeprom d'96' ; Read O2 ratio |
327 lfsr FSR1, char_I_deco_He_ratio5 ; most shallow decogas | 323 movff char_I_deco_He_ratio5, wait_temp ; copy into bank1 register |
328 divemode_check_decogases2: | 324 bsf STATUS,C ; |
329 incf hi,F ; increase (First time: hi=0) | 325 movlw d'100' ; 100% |
330 rcall copy_decogas_info | 326 subfwb wait_temp,W ; minus He |
331 movlw d'3' | 327 subfwb EEDATA,F ; minus O2 |
332 cpfseq hi ; Gases 0-3 copied? | 328 movff EEDATA, char_I_deco_N2_ratio5; = N2! |
333 bra divemode_check_decogases2 ; No, Continue | 329 |
330 read_int_eeprom d'101' ; Read He ratio | |
331 movff EEDATA,char_I_deco_He_ratio4 ; And copy into hold register | |
332 read_int_eeprom d'100' ; Read O2 ratio | |
333 movff char_I_deco_He_ratio4, wait_temp ; copy into bank1 register | |
334 bsf STATUS,C ; | |
335 movlw d'100' ; 100% | |
336 subfwb wait_temp,W ; minus He | |
337 subfwb EEDATA,F ; minus O2 | |
338 movff EEDATA, char_I_deco_N2_ratio4; = N2! | |
339 | |
340 read_int_eeprom d'105' ; Read He ratio | |
341 movff EEDATA,char_I_deco_He_ratio3 ; And copy into hold register | |
342 read_int_eeprom d'104' ; Read O2 ratio | |
343 movff char_I_deco_He_ratio3, wait_temp ; copy into bank1 register | |
344 bsf STATUS,C ; | |
345 movlw d'100' ; 100% | |
346 subfwb wait_temp,W ; minus He | |
347 subfwb EEDATA,F ; minus O2 | |
348 movff EEDATA, char_I_deco_N2_ratio3; = N2! | |
349 | |
350 read_int_eeprom d'109' ; Read He ratio | |
351 movff EEDATA,char_I_deco_He_ratio2 ; And copy into hold register | |
352 read_int_eeprom d'108' ; Read O2 ratio | |
353 movff char_I_deco_He_ratio2, wait_temp ; copy into bank1 register | |
354 bsf STATUS,C ; | |
355 movlw d'100' ; 100% | |
356 subfwb wait_temp,W ; minus He | |
357 subfwb EEDATA,F ; minus O2 | |
358 movff EEDATA, char_I_deco_N2_ratio2; = N2! | |
334 | 359 |
335 read_int_eeprom d'113' ; Read He ratio | 360 read_int_eeprom d'113' ; Read He ratio |
336 movff EEDATA,char_I_deco_He_ratio ; And copy into hold register | 361 movff EEDATA,char_I_deco_He_ratio ; And copy into hold register |
337 | |
338 read_int_eeprom d'112' ; Read O2 ratio | 362 read_int_eeprom d'112' ; Read O2 ratio |
339 movff char_I_deco_He_ratio, wait_temp ; copy into bank1 register | 363 movff char_I_deco_He_ratio, wait_temp ; copy into bank1 register |
340 bsf STATUS,C ; | 364 bsf STATUS,C ; |
341 movlw d'100' ; 100% | 365 movlw d'100' ; 100% |
342 subfwb wait_temp,W ; minus He | 366 subfwb wait_temp,W ; minus He |
345 | 369 |
346 ; Now, set change depth. Inactive gases have depth=0! | 370 ; Now, set change depth. Inactive gases have depth=0! |
347 | 371 |
348 read_int_eeprom d'118' ; read gas_change_depth Gas1 | 372 read_int_eeprom d'118' ; read gas_change_depth Gas1 |
349 movff EEDATA,char_I_deco_gas_change5 | 373 movff EEDATA,char_I_deco_gas_change5 |
350 | 374 read_int_eeprom d'119' ; read gas_change_depth Gas2 |
351 read_int_eeprom d'119' ; read gas_change_depth Gas1 | |
352 movff EEDATA,char_I_deco_gas_change4 | 375 movff EEDATA,char_I_deco_gas_change4 |
353 | 376 read_int_eeprom d'120' ; read gas_change_depth Gas3 |
354 read_int_eeprom d'120' ; read gas_change_depth Gas1 | |
355 movff EEDATA,char_I_deco_gas_change3 | 377 movff EEDATA,char_I_deco_gas_change3 |
356 | 378 read_int_eeprom d'121' ; read gas_change_depth Gas4 |
357 read_int_eeprom d'121' ; read gas_change_depth Gas1 | |
358 movff EEDATA,char_I_deco_gas_change2 | 379 movff EEDATA,char_I_deco_gas_change2 |
359 | 380 read_int_eeprom d'122' ; read gas_change_depth Gas5 |
360 read_int_eeprom d'122' ; read gas_change_depth Gas1 | |
361 movff EEDATA,char_I_deco_gas_change | 381 movff EEDATA,char_I_deco_gas_change |
362 | 382 |
363 | 383 |
364 ; Debugger | 384 ; Debugger |
365 ; call enable_rs232 | 385 ; call enable_rs232 |
392 ; movff char_I_deco_gas_change2,TXREG | 412 ; movff char_I_deco_gas_change2,TXREG |
393 ; call rs232_wait_tx ; wait for UART | 413 ; call rs232_wait_tx ; wait for UART |
394 ; movff char_I_deco_gas_change,TXREG | 414 ; movff char_I_deco_gas_change,TXREG |
395 ; call rs232_wait_tx ; wait for UART | 415 ; call rs232_wait_tx ; wait for UART |
396 | 416 |
397 | |
398 | |
399 | |
400 | |
401 return | |
402 | |
403 copy_decogas_info: | |
404 movf hi,W ; Gas 1-4 | |
405 mullw d'4' ; times 4... | |
406 movlw d'90' ; +90 Offset to new... | |
407 addwf PRODL,F ; ..sorted list! | |
408 | |
409 movf PRODL,W ; | |
410 addlw d'7' ; +7 = address for He ratio | |
411 movwf EEADR | |
412 call read_eeprom ; Read He ratio | |
413 movff EEDATA,INDF1 ; And copy into hold register | |
414 | |
415 movf hi,W ; Gas 1-4 | |
416 mullw d'4' ; times 4... | |
417 movlw d'90' ; +90 Offset to new... | |
418 addwf PRODL,F ; ..sorted list! | |
419 | |
420 movf PRODL,W ; | |
421 addlw d'6' ; +6 = address for O2 ratio | |
422 movwf EEADR | |
423 call read_eeprom ; Read O2 ratio | |
424 ; movff EEDATA, char_I_O2_ratio ; O2 ratio | |
425 movff POSTDEC1, wait_temp ; copy into bank1 register | |
426 bsf STATUS,C ; | |
427 movlw d'100' ; 100% | |
428 subfwb wait_temp,W ; minus He | |
429 subfwb EEDATA,F ; minus O2 | |
430 movff EEDATA, POSTDEC1 ; = N2! | |
431 return | 417 return |
432 | 418 |
433 reset_decompression_gases: ; reset the deco gas while in NDL | 419 reset_decompression_gases: ; reset the deco gas while in NDL |
434 ostc_debug 'F' ; Sends debug-information to screen if debugmode active | 420 ostc_debug 'F' ; Sends debug-information to screen if debugmode active |
435 clrf lo | 421 clrf lo |
436 movff lo,char_I_deco_gas_change5 | 422 movff lo,char_I_deco_gas_change5 |
437 movff lo,char_I_deco_gas_change4 | 423 movff lo,char_I_deco_gas_change4 |
438 movff lo,char_I_deco_gas_change3 | 424 movff lo,char_I_deco_gas_change3 |
439 movff lo,char_I_deco_gas_change2 | 425 movff lo,char_I_deco_gas_change2 |
440 movff lo, char_I_deco_gas_change ; clear | 426 movff lo,char_I_deco_gas_change ; clear |
441 return | 427 return |
442 | 428 |
443 calc_deko_divemode2: | 429 calc_deko_divemode2: |
444 bcf twosecupdate | 430 bcf twosecupdate |
445 | 431 |
1252 movlw 0xFB ; Header stop | 1238 movlw 0xFB ; Header stop |
1253 call write_external_eeprom | 1239 call write_external_eeprom |
1254 movlw 0xFB | 1240 movlw 0xFB |
1255 call write_external_eeprom | 1241 call write_external_eeprom |
1256 | 1242 |
1257 btfsc simulatormode_active ; Are we in simulator mode? | |
1258 bra change_logbook_offset2 ; Yes, do not update history | |
1259 | |
1260 ; Increase total dive counter | 1243 ; Increase total dive counter |
1261 read_int_eeprom d'2' ; Read byte (stored in EEDATA) | 1244 read_int_eeprom d'2' ; Read byte (stored in EEDATA) |
1262 movff EEDATA,temp1 ; Low byte | 1245 movff EEDATA,temp1 ; Low byte |
1263 read_int_eeprom d'3' ; Read byte (stored in EEDATA) | 1246 read_int_eeprom d'3' ; Read byte (stored in EEDATA) |
1264 movff EEDATA,temp2 ; high byte | 1247 movff EEDATA,temp2 ; high byte |
1512 movff xC+1,avr_rel_pressure+1 | 1495 movff xC+1,avr_rel_pressure+1 |
1513 return | 1496 return |
1514 | 1497 |
1515 | 1498 |
1516 diveloop_boot: | 1499 diveloop_boot: |
1517 ostc_debug 'Q' ; Sends debug-information to screen if debugmode active | 1500 ostc_debug 'Q' ; Sends debug-information to screen if debugmode active |
1518 clrf max_pressure+0 ; clear some variables | 1501 clrf max_pressure+0 ; clear some variables |
1519 clrf max_pressure+1 | 1502 clrf max_pressure+1 |
1520 | 1503 |
1521 clrf avr_rel_pressure+0 | 1504 clrf avr_rel_pressure+0 |
1522 clrf avr_rel_pressure+1 | 1505 clrf avr_rel_pressure+1 |
1551 clrf timeout_counter2 ; Here: counts to six, then store deco data and temperature | 1534 clrf timeout_counter2 ; Here: counts to six, then store deco data and temperature |
1552 clrf AlarmType ; Clear all alarms | 1535 clrf AlarmType ; Clear all alarms |
1553 bcf event_occured ; clear flag | 1536 bcf event_occured ; clear flag |
1554 bcf depth_greater_100m ; clear flag | 1537 bcf depth_greater_100m ; clear flag |
1555 setf last_diluent ; to be displayed after first calculation (range: 0 to 100 [%]) | 1538 setf last_diluent ; to be displayed after first calculation (range: 0 to 100 [%]) |
1556 ; clrf char_last_pointer | |
1557 bcf dekostop_active | 1539 bcf dekostop_active |
1558 bcf is_bailout ;=1: CC mode, but bailout active! | 1540 bcf is_bailout ;=1: CC mode, but bailout active! |
1559 bcf better_gas_available ;=1: A better gas is available and a gas change is advised in divemode | 1541 bcf better_gas_available ;=1: A better gas is available and a gas change is advised in divemode |
1560 | 1542 |
1561 call get_free_EEPROM_location ; get last position in external EEPROM, may be up to 2 secs! | 1543 call get_free_EEPROM_location ; get last position in external EEPROM, may be up to 2 secs! |
1585 bra set_no_forced_stops | 1567 bra set_no_forced_stops |
1586 lfsr FSR0,0x290 ; clear int_O_calc_tissue_call_counter (DEBUG) | 1568 lfsr FSR0,0x290 ; clear int_O_calc_tissue_call_counter (DEBUG) |
1587 clrf POSTINC0 | 1569 clrf POSTINC0 |
1588 clrf POSTINC0 | 1570 clrf POSTINC0 |
1589 | 1571 |
1590 ;; Load GF values into RAM - now done in start.asm! | |
1591 ; GETCUSTOM8 d'32' ; GF low | |
1592 ; movff EEDATA,char_I_GF_Lo_percentage | |
1593 ; GETCUSTOM8 d'33' ; GF high | |
1594 ; movff EEDATA,char_I_GF_Hi_percentage | |
1595 ; | |
1596 ; Start with active Stopwatch? | 1572 ; Start with active Stopwatch? |
1597 bsf stopwatch_active | 1573 bsf stopwatch_active |
1598 GETCUSTOM8 d'41' ; =1: Start with active Stopwatch | 1574 GETCUSTOM8 d'41' ; =1: Start with active Stopwatch |
1599 movwf lo | 1575 movwf lo |
1600 movlw d'1' | 1576 movlw d'1' |
1634 bcf header_stored | 1610 bcf header_stored |
1635 bcf premenu | 1611 bcf premenu |
1636 bcf realdive | 1612 bcf realdive |
1637 bsf update_divetime ; set flag | 1613 bsf update_divetime ; set flag |
1638 btfss simulatormode_active ; do not disable in simulator mode! | 1614 btfss simulatormode_active ; do not disable in simulator mode! |
1639 call disable_rs232 ; Disable RS232 unless in external O2 Sensor mode | 1615 call disable_rs232 ; Disable RS232 |
1640 | 1616 |
1641 read_int_eeprom d'33' ; Read byte (stored in EEDATA) | 1617 read_int_eeprom d'33' ; Read byte (stored in EEDATA) |
1642 movff EEDATA,active_gas ; Read start gas (1-5) | 1618 movff EEDATA,active_gas ; Read start gas (1-5) |
1643 | 1619 |
1644 ; Read Start Gas and configure char_I_He_ratio, char_I_O2_ratio and char_I_N2_ratio | 1620 ; Read Start Gas and configure char_I_He_ratio, char_I_O2_ratio and char_I_N2_ratio |
1662 subfwb wait_temp,W ; minus He | 1638 subfwb wait_temp,W ; minus He |
1663 bsf STATUS,C ; Borrow bit | 1639 bsf STATUS,C ; Borrow bit |
1664 subfwb EEDATA,F ; minus O2 | 1640 subfwb EEDATA,F ; minus O2 |
1665 movff EEDATA, char_I_N2_ratio ; = N2! | 1641 movff EEDATA, char_I_N2_ratio ; = N2! |
1666 | 1642 |
1667 ; New in 1.09 - DecoGas can be configured to achieve exact decompression proposal | |
1668 ; required variables | |
1669 ; These values are set when the OSTC is in decompression mode - will be done in routine "check_decogas" | |
1670 ; char_I_deco_gas_change; ; next gas change in meter | |
1671 ; char_I_deco_N2_ratio; ; next gas N2 | |
1672 ; char_I_deco_He_ratio; ; next gas He | |
1673 clrf lo | |
1674 movff lo, char_I_deco_gas_change ; clear | |
1675 movff lo, char_I_deco_N2_ratio ; clear | |
1676 movff lo, char_I_deco_He_ratio ; clear | |
1677 bcf multi_gf_display ; Do not display the multi-gf table screen | 1643 bcf multi_gf_display ; Do not display the multi-gf table screen |
1678 return | 1644 return |