comparison code_part1/OSTC_code_asm_part1/divemode.asm @ 344:797e2ac42d24 ScreenDump

MERGE with 1.91 main trunk.
author JeanDo
date Sat, 21 May 2011 14:48:07 +0200
parents d36fe3651d56 06299199dfb9
children ed137d66ac65
comparison
equal deleted inserted replaced
337:6bdf80d7276c 344:797e2ac42d24
414 return 414 return
415 415
416 ;----------------------------------------------------------------------------- 416 ;-----------------------------------------------------------------------------
417 ; calculate ppO2 in 0.01Bar (e.g. 150 = 1.50 Bar ppO2) 417 ; calculate ppO2 in 0.01Bar (e.g. 150 = 1.50 Bar ppO2)
418 set_actual_ppo2: 418 set_actual_ppo2:
419 movff amb_pressure+0,xA+0 ; P_amb in milibar (1000 = 1.000 bar). 419 SAFE_2BYTE_COPY amb_pressure, xA ; P_amb in milibar (1000 = 1.000 bar).
420 movff amb_pressure+1,xA+1
421 movlw d'10' 420 movlw d'10'
422 movwf xB+0 421 movwf xB+0
423 clrf xB+1 422 clrf xB+1
424 call div16x16 ; xC=p_amb/10 (100 = 1.00 bar). 423 call div16x16 ; xC=p_amb/10 (100 = 1.00 bar).
425 movff xC+0,xA+0 424 movff xC+0,xA+0
554 bra calc_deko_divemode5 553 bra calc_deko_divemode5
555 554
556 ;----------------------------------------------------------------------------- 555 ;-----------------------------------------------------------------------------
557 556
558 divemode_prepare_flags_for_deco: 557 divemode_prepare_flags_for_deco:
559 movff amb_pressure+0,int_I_pres_respiration+0 ; lo and copy result to deco routine 558 SAFE_2BYTE_COPY amb_pressure,int_I_pres_respiration ; copy result to deco routine
560 movff amb_pressure+1,int_I_pres_respiration+1 ; hi 559
561 GETCUSTOM8 d'11' ; Saturation multiplier % 560 GETCUSTOM8 d'11' ; Saturation multiplier %
562 movff WREG,char_I_saturation_multiplier 561 movff WREG,char_I_saturation_multiplier
563 GETCUSTOM8 d'12' ; Desaturation multiplier % 562 GETCUSTOM8 d'12' ; Desaturation multiplier %
564 movff WREG,char_I_desaturation_multiplier 563 movff WREG,char_I_desaturation_multiplier
565 GETCUSTOM8 d'16' ; Deco distance to decostop in 1/10 meter for simulation 564 GETCUSTOM8 d'16' ; Deco distance to decostop in 1/10 meter for simulation
591 ; shift address for header 590 ; shift address for header
592 ; the header will be stored after the dive 591 ; the header will be stored after the dive
593 incf_eeprom_address d'47' ; Macro, that adds 8Bit to eeprom_address:2 with banking at 0x8000 592 incf_eeprom_address d'47' ; Macro, that adds 8Bit to eeprom_address:2 with banking at 0x8000
594 593
595 store_dive_data2: 594 store_dive_data2:
596 movf rel_pressure+0,W ; store depth with every sample 595 SAFE_2BYTE_COPY rel_pressure, lo
597 call write_external_eeprom 596 movf lo,W ; store depth with every sample
598 movf rel_pressure+1,W 597 call write_external_eeprom
598 movf hi,W
599 call write_external_eeprom 599 call write_external_eeprom
600 600
601 ;First, find out how many bytes will append to this sample.... 601 ;First, find out how many bytes will append to this sample....
602 clrf ProfileFlagByte ; clear number of bytes to append 602 clrf ProfileFlagByte ; clear number of bytes to append
603 603
808 GETCUSTOM8 d'22' 808 GETCUSTOM8 d'22'
809 movwf divisor_deco ; Reload divisor from CF 809 movwf divisor_deco ; Reload divisor from CF
810 return 810 return
811 811
812 store_dive_temperature: 812 store_dive_temperature:
813 movf temperature+0,W ; append temperature to current sample! 813 SAFE_2BYTE_COPY temperature,lo
814 call write_external_eeprom 814 movf lo,W ; append temperature to current sample!
815 movf temperature+1,W 815 call write_external_eeprom
816 movf hi,W
816 call write_external_eeprom 817 call write_external_eeprom
817 GETCUSTOM8 d'21' 818 GETCUSTOM8 d'21'
818 movwf divisor_temperature ; Reload divisor from CF 819 movwf divisor_temperature ; Reload divisor from CF
819 return 820 return
820 821
821 calc_velocity: ; called every two seconds 822 calc_velocity: ; called every two seconds
822 btfss divemode 823 btfss divemode
823 bra do_not_display_velocity ; display velocity only in divemode 824 bra do_not_display_velocity ; display velocity only in divemode
824 825
825 calc_velocity2: 826 calc_velocity2:
826 movff amb_pressure+0,sub_a+0 827 SAFE_2BYTE_COPY amb_pressure, sub_a
827 movff amb_pressure+1,sub_a+1
828 movff last_pressure+0,sub_b+0 828 movff last_pressure+0,sub_b+0
829 movff last_pressure+1,sub_b+1 829 movff last_pressure+1,sub_b+1
830 movff amb_pressure+0,last_pressure+0 ; store old value for velocity 830 movff sub_a+0,last_pressure+0 ; store old value for velocity
831 movff amb_pressure+1,last_pressure+1 831 movff sub_a+1,last_pressure+1
832 832
833 call sub16 ; sub_c = amb_pressure - last_pressure 833 call sub16 ; sub_c = amb_pressure - last_pressure
834 834
835 movff sub_c+0,xA+0 835 movff sub_c+0,xA+0
836 movff sub_c+1,xA+1 836 movff sub_c+1,xA+1
873 check_ppO2: ; check current ppO2 and display warning if required 873 check_ppO2: ; check current ppO2 and display warning if required
874 btfsc FLAG_const_ppO2_mode ; ignore in ppO2 mode.... 874 btfsc FLAG_const_ppO2_mode ; ignore in ppO2 mode....
875 return 875 return
876 876
877 check_ppO2_bail: ; In CC mode but bailout active! 877 check_ppO2_bail: ; In CC mode but bailout active!
878 movff amb_pressure+0,xA+0 878 SAFE_2BYTE_COPY amb_pressure, xA
879 movff amb_pressure+1,xA+1
880 movlw d'10' 879 movlw d'10'
881 movwf xB+0 880 movwf xB+0
882 clrf xB+1 881 clrf xB+1
883 call div16x16 ; xC=p_amb/10 882 call div16x16 ; xC=p_amb/10
884 movff xC+0,xA+0 883 movff xC+0,xA+0
962 ; 961 ;
963 ; Output: better_gas_available 962 ; Output: better_gas_available
964 ; 963 ;
965 check_gas_change: ; Checks if a better gas should be selected (by user) 964 check_gas_change: ; Checks if a better gas should be selected (by user)
966 bcf better_gas_available ;=1: A better gas is available and a gas change is advised in divemode 965 bcf better_gas_available ;=1: A better gas is available and a gas change is advised in divemode
967 966
968 movff rel_pressure+0,xA+0 967 SAFE_2BYTE_COPY rel_pressure,xA
969 movff rel_pressure+1,xA+1
970 movlw d'100' 968 movlw d'100'
971 movwf xB+0 969 movwf xB+0
972 clrf xB+1 970 clrf xB+1
973 call div16x16 ; compute depth in full m -> result in xC+0 971 call div16x16 ; compute depth in full m -> result in xC+0
974 972
1442 call set_max_depth ; update max. depth if required 1440 call set_max_depth ; update max. depth if required
1443 1441
1444 btfsc divemode 1442 btfsc divemode
1445 call set_min_temp ; store min. temp if required 1443 call set_min_temp ; store min. temp if required
1446 1444
1447 bcf temp_changed ; Display temperature? 1445 bcf temp_changed ; Display temperature?
1448 movf temperature+0,W 1446 SAFE_2BYTE_COPY temperature,lo
1447 movf lo,W
1449 cpfseq last_temperature+0 1448 cpfseq last_temperature+0
1450 bsf temp_changed ; Yes 1449 bsf temp_changed ; Yes
1451 movf temperature+1,W 1450 movf hi,W
1452 cpfseq last_temperature+1 1451 cpfseq last_temperature+1
1453 bsf temp_changed ; Yes 1452 bsf temp_changed ; Yes
1454 btfsc temp_changed 1453 btfsc temp_changed
1455 call PLED_temp_divemode ; Displays temperature 1454 call PLED_temp_divemode ; Displays temperature
1456 1455
1457 bcf pres_changed ; Display new depth? 1456 bcf pres_changed ; Display new depth?
1458 movf amb_pressure+0,W 1457 SAFE_2BYTE_COPY amb_pressure, lo
1458 movf lo,W
1459 cpfseq last_pressure+0 1459 cpfseq last_pressure+0
1460 bsf pres_changed ; Yes 1460 bsf pres_changed ; Yes
1461 movf amb_pressure+1,W 1461 movf hi,W
1462 cpfseq last_pressure+1 1462 cpfseq last_pressure+1
1463 bsf pres_changed ; Yes 1463 bsf pres_changed ; Yes
1464 1464
1465 btfsc simulatormode_active ; always update depth when in simulator mode 1465 btfsc simulatormode_active ; always update depth when in simulator mode
1466 bsf pres_changed 1466 bsf pres_changed
1479 return 1479 return
1480 1480
1481 set_max_depth: 1481 set_max_depth:
1482 movff max_pressure+0,sub_a+0 1482 movff max_pressure+0,sub_a+0
1483 movff max_pressure+1,sub_a+1 1483 movff max_pressure+1,sub_a+1
1484 movff rel_pressure+0,sub_b+0 1484 SAFE_2BYTE_COPY rel_pressure, sub_b
1485 movff rel_pressure+1,sub_b+1 1485 call sub16 ; sub_c = sub_a - sub_b
1486 call sub16 ; sub_c = sub_a - sub_b
1487 ; max_pressure<rel_pressure -> neg_flag=1 1486 ; max_pressure<rel_pressure -> neg_flag=1
1488 ; rel_pressure<=max_pressure -> neg_flag=0 1487 ; rel_pressure<=max_pressure -> neg_flag=0
1489 btfss neg_flag 1488 btfss neg_flag
1490 return 1489 return
1491 ;max_pressure<rel_pressure 1490 ;max_pressure<rel_pressure
1492 movff rel_pressure+0,max_pressure+0 1491 movff sub_b+0,max_pressure+0
1493 movff rel_pressure+1,max_pressure+1 1492 movff sub_b+1,max_pressure+1
1494 call PLED_max_pressure ; No, use normal max. depth 1493 call PLED_max_pressure ; No, use normal max. depth
1495 return 1494 return
1496 1495
1497 set_min_temp: 1496 set_min_temp:
1498 movff mintemp+0,sub_a+0 1497 movff mintemp+0,sub_a+0
1499 movff mintemp+1,sub_a+1 1498 movff mintemp+1,sub_a+1
1500 movff temperature+0,sub_b+0 1499 SAFE_2BYTE_COPY temperature,sub_b
1501 movff temperature+1,sub_b+1 1500 call sub16 ; sub_c = sub_a - sub_b
1502 call sub16 ; sub_c = sub_a - sub_b
1503 ; mintemp<T -> neg_flag=1 1501 ; mintemp<T -> neg_flag=1
1504 ; T<=mintemp -> neg_flag=0 1502 ; T<=mintemp -> neg_flag=0
1505 btfsc neg_flag 1503 btfsc neg_flag
1506 return 1504 return
1507 ;mintemp>=T 1505 ;mintemp>=T
1508 movff temperature+0,mintemp+0 1506 movff sub_b+0,mintemp+0
1509 movff temperature+1,mintemp+1 1507 movff sub_b+1,mintemp+1
1510 return 1508 return
1511 1509
1512 set_dive_modes: 1510 set_dive_modes:
1513 btfsc high_altitude_mode ; In high altitude (Fly) mode? 1511 btfsc high_altitude_mode ; In high altitude (Fly) mode?
1514 bra set_dive_modes3 ; Yes 1512 bra set_dive_modes3 ; Yes
1516 bcf divemode2 ; Stop time 1514 bcf divemode2 ; Stop time
1517 1515
1518 GETCUSTOM8 .0 ; loads dive_threshold in WREG 1516 GETCUSTOM8 .0 ; loads dive_threshold in WREG
1519 movwf sub_a+0 ; dive_treshold is in cm 1517 movwf sub_a+0 ; dive_treshold is in cm
1520 clrf sub_a+1 1518 clrf sub_a+1
1521 movff rel_pressure+0,sub_b+0 1519 SAFE_2BYTE_COPY rel_pressure, sub_b
1522 movff rel_pressure+1,sub_b+1
1523 call sub16 ; sub_c = sub_a - sub_b 1520 call sub16 ; sub_c = sub_a - sub_b
1524 1521
1525 btfss neg_flag 1522 btfss neg_flag
1526 bra set_dive_modes2 ; too shallow (rel_pressure<dive_threshold) 1523 bra set_dive_modes2 ; too shallow (rel_pressure<dive_threshold)
1527 1524
1528 btfsc realdive ; Dive longer than one minute? 1525 btfsc realdive ; Dive longer than one minute?
1529 clrf timeout_counter ; Yes, reset timout counter 1526 clrf timeout_counter ; Yes, reset timout counter
1540 set_dive_modes3: 1537 set_dive_modes3:
1541 movlw HIGH d'1075' ; hard-wired 1075mBar threshold 1538 movlw HIGH d'1075' ; hard-wired 1075mBar threshold
1542 movwf sub_a+1 1539 movwf sub_a+1
1543 movlw LOW d'1075' ; hard-wired 1075mBar threshold 1540 movlw LOW d'1075' ; hard-wired 1075mBar threshold
1544 movwf sub_a+0 1541 movwf sub_a+0
1545 movff rel_pressure+0,sub_b+0 1542 SAFE_2BYTE_COPY rel_pressure, sub_b
1546 movff rel_pressure+1,sub_b+1
1547 call sub16 ; sub_c = sub_a - sub_b 1543 call sub16 ; sub_c = sub_a - sub_b
1548 1544
1549 btfss neg_flag 1545 btfss neg_flag
1550 bra set_dive_modes2 ; too shallow (rel_pressure<dive_threshold) 1546 bra set_dive_modes2 ; too shallow (rel_pressure<dive_threshold)
1551 1547
1579 calc_average_depth: 1575 calc_average_depth:
1580 btfsc reset_average_depth ; Reset the Avewrage depth? 1576 btfsc reset_average_depth ; Reset the Avewrage depth?
1581 rcall reset_average1 ; Reset the resettable average depth 1577 rcall reset_average1 ; Reset the resettable average depth
1582 1578
1583 ; 1. Add new 2xdepth to the Sum of depths registers 1579 ; 1. Add new 2xdepth to the Sum of depths registers
1584 movff rel_pressure+0,b0_lo 1580 SAFE_2BYTE_COPY rel_pressure, b0_lo ; Buffer...
1585 movff rel_pressure+1,b0_hi ; Buffer...
1586 1581
1587 movf b0_lo,w 1582 movf b0_lo,w
1588 addwf average_depth_hold+0,F 1583 addwf average_depth_hold+0,F
1589 movf b0_hi,w 1584 movf b0_hi,w
1590 addwfc average_depth_hold+1,F 1585 addwfc average_depth_hold+1,F
1735 movff WREG,int_I_pres_surface+0 ; LOW copy surfacepressure to deco routine 1730 movff WREG,int_I_pres_surface+0 ; LOW copy surfacepressure to deco routine
1736 movlw HIGH .1000 1731 movlw HIGH .1000
1737 movff WREG,int_I_pres_surface+1 ; HIGH copy surfacepressure to deco routine 1732 movff WREG,int_I_pres_surface+1 ; HIGH copy surfacepressure to deco routine
1738 1733
1739 diveloop_boot_2: 1734 diveloop_boot_2:
1740 movff temperature+0,mintemp+0 ; Reset Min-Temp registers 1735 SAFE_2BYTE_COPY temperature,mintemp ; Reset Min-Temp registers
1741 movff temperature+1,mintemp+1 ; Reset Min-Temp registers
1742 1736
1743 ; Init profile recording parameters 1737 ; Init profile recording parameters
1744 GETCUSTOM8 d'20' ; sample rate 1738 GETCUSTOM8 d'20' ; sample rate
1745 movwf samplesecs_value ; to avoid EEPROM access in the ISR 1739 movwf samplesecs_value ; to avoid EEPROM access in the ISR
1746 GETCUSTOM8 d'21' 1740 GETCUSTOM8 d'21'