comparison code_part1/OSTC_code_asm_part1/divemode.asm @ 395:0e0cf4701c17

Merge with 64kByte Logbook
author JeanDo
date Thu, 23 Jun 2011 01:37:59 +0200
parents deced1cacff7
children ab962c4b19d6
comparison
equal deleted inserted replaced
369:93c0cb14b0d2 395:0e0cf4701c17
73 btfsc twosecupdate ; two seconds after the last call 73 btfsc twosecupdate ; two seconds after the last call
74 bra diveloop_loop1a2 ; Common Tasks 74 bra diveloop_loop1a2 ; Common Tasks
75 75
76 bsf twosecupdate ; Routines used in the "other second" 76 bsf twosecupdate ; Routines used in the "other second"
77 call calc_average_depth ; calculate average depth 77 call calc_average_depth ; calculate average depth
78 call calc_velocity ; calculate vertical velocity and display if > threshold (every two seconds)
78 79
79 bra diveloop_loop1x ; Common Tasks 80 bra diveloop_loop1x ; Common Tasks
80 81
81 diveloop_loop1a2: 82 diveloop_loop1a2:
82 bcf twosecupdate 83 bcf twosecupdate
587 movff eeprom_address+0, eeprom_header_address+0 ; store startposition 588 movff eeprom_address+0, eeprom_header_address+0 ; store startposition
588 movff eeprom_address+1, eeprom_header_address+1 ; store startposition 589 movff eeprom_address+1, eeprom_header_address+1 ; store startposition
589 590
590 ; shift address for header 591 ; shift address for header
591 ; the header will be stored after the dive 592 ; the header will be stored after the dive
592 incf_eeprom_address d'47' ; Macro, that adds 8Bit to eeprom_address:2 with banking at 0x8000 593 incf_eeprom_address d'57' ; Macro, that adds 8Bit to eeprom_address:2 with banking at 0x8000
593 594
594 store_dive_data2: 595 store_dive_data2:
595 SAFE_2BYTE_COPY rel_pressure, lo 596 SAFE_2BYTE_COPY rel_pressure, lo
596 movf lo,W ; store depth with every sample 597 movf lo,W ; store depth with every sample
597 call write_external_eeprom 598 call write_external_eeprom
610 decfsz divisor_deco,W ; Check divisor 611 decfsz divisor_deco,W ; Check divisor
611 bra check_extended2 612 bra check_extended2
612 movlw d'2' ; Information length 613 movlw d'2' ; Information length
613 addwf ProfileFlagByte,F ; add to ProfileFlagByte 614 addwf ProfileFlagByte,F ; add to ProfileFlagByte
614 check_extended2: 615 check_extended2:
615 decfsz divisor_tank,W ; Check divisor 616 decfsz divisor_gf,W ; Check divisor
616 bra check_extended3 617 bra check_extended3
617 movlw d'2' ; Information length 618 movlw d'1' ; Information length
618 addwf ProfileFlagByte,F ; add to ProfileFlagByte 619 addwf ProfileFlagByte,F ; add to ProfileFlagByte
619 check_extended3: 620 check_extended3:
620 decfsz divisor_ppo2,W ; Check divisor 621 decfsz divisor_ppo2,W ; Check divisor
621 bra check_extended4 622 bra check_extended4
622 movlw d'3' ; Information length 623 movlw d'3' ; Information length
625 decfsz divisor_deco_debug,W; Check divisor 626 decfsz divisor_deco_debug,W; Check divisor
626 bra check_extended5 627 bra check_extended5
627 movlw d'9' ; Information length 628 movlw d'9' ; Information length
628 addwf ProfileFlagByte,F ; add to ProfileFlagByte 629 addwf ProfileFlagByte,F ; add to ProfileFlagByte
629 check_extended5: 630 check_extended5:
630 decfsz divisor_nuy2,W ; Check divisor 631 decfsz divisor_cns,W ; Check divisor
631 bra check_extended6 632 bra check_extended6
632 movlw d'0' ; Information length 633 movlw d'1' ; Information length
633 addwf ProfileFlagByte,F ; add to ProfileFlagByte 634 addwf ProfileFlagByte,F ; add to ProfileFlagByte
634 check_extended6: 635 check_extended6:
635 636
636 ; Second, check global event flag 637 ; Second, check global event flag
637 btfss event_occured ; Check global event flag 638 btfss event_occured ; Check global event flag
704 store_extended1: 705 store_extended1:
705 decfsz divisor_deco,F ; Check divisor 706 decfsz divisor_deco,F ; Check divisor
706 bra store_extended2 707 bra store_extended2
707 rcall store_dive_decodata 708 rcall store_dive_decodata
708 store_extended2: 709 store_extended2:
709 decfsz divisor_tank,F ; Check divisor 710 decfsz divisor_gf,F ; Check divisor
710 bra store_extended3 711 bra store_extended3
711 rcall store_dive_tankdata 712 rcall store_dive_gf
712 store_extended3: 713 store_extended3:
713 decfsz divisor_ppo2,F ; Check divisor 714 decfsz divisor_ppo2,F ; Check divisor
714 bra store_extended4 715 bra store_extended4
715 rcall store_dive_ppo2 716 rcall store_dive_ppo2
716 store_extended4: 717 store_extended4:
717 decfsz divisor_deco_debug,F; Check divisor 718 decfsz divisor_deco_debug,F; Check divisor
718 bra store_extended5 719 bra store_extended5
719 rcall store_dive_decodebug 720 rcall store_dive_decodebug
720 store_extended5: 721 store_extended5:
721 decfsz divisor_nuy2,F ; Check divisor 722 decfsz divisor_cns,F ; Check divisor
722 bra store_extended6 723 bra store_extended6
723 rcall store_dive_nuy2 724 rcall store_dive_cns
724 store_extended6: 725 store_extended6:
725 726
726 ; The next block is required to take care of "store never" 727 ; The next block is required to take care of "store never"
727 btfsc divisor_temperature,7 ; Test highest Bit (Register must have been zero before the "decfsz" command!) 728 btfsc divisor_temperature,7 ; Test highest Bit (Register must have been zero before the "decfsz" command!)
728 clrf divisor_temperature ; And clear register again, so it will never reach zero... 729 clrf divisor_temperature ; And clear register again, so it will never reach zero...
729 btfsc divisor_deco,7 ; Test highest Bit (Register must have been zero before the "decfsz" command!) 730 btfsc divisor_deco,7 ; Test highest Bit (Register must have been zero before the "decfsz" command!)
730 clrf divisor_deco ; And clear register again, so it will never reach zero... 731 clrf divisor_deco ; And clear register again, so it will never reach zero...
731 btfsc divisor_tank,7 ; Test highest Bit (Register must have been zero before the "decfsz" command!) 732 btfsc divisor_gf,7 ; Test highest Bit (Register must have been zero before the "decfsz" command!)
732 clrf divisor_tank ; And clear register again, so it will never reach zero... 733 clrf divisor_gf ; And clear register again, so it will never reach zero...
733 btfsc divisor_ppo2,7 ; Test highest Bit (Register must have been zero before the "decfsz" command!) 734 btfsc divisor_ppo2,7 ; Test highest Bit (Register must have been zero before the "decfsz" command!)
734 clrf divisor_ppo2 ; And clear register again, so it will never reach zero... 735 clrf divisor_ppo2 ; And clear register again, so it will never reach zero...
735 btfsc divisor_deco_debug,7 ; Test highest Bit (Register must have been zero before the "decfsz" command!) 736 btfsc divisor_deco_debug,7 ; Test highest Bit (Register must have been zero before the "decfsz" command!)
736 clrf divisor_deco_debug ; And clear register again, so it will never reach zero... 737 clrf divisor_deco_debug ; And clear register again, so it will never reach zero...
737 btfsc divisor_nuy2,7 ; Test highest Bit (Register must have been zero before the "decfsz" command!) 738 btfsc divisor_cns,7 ; Test highest Bit (Register must have been zero before the "decfsz" command!)
738 clrf divisor_nuy2 ; And clear register again, so it will never reach zero... 739 clrf divisor_cns ; And clear register again, so it will never reach zero...
739 740
740 ostc_debug 'D' ; Sends debug-information to screen if debugmode active 741 ostc_debug 'D' ; Sends debug-information to screen if debugmode active
741 742
742 ; SetPoint change appended to information due to compatibility reasons 743 ; SetPoint change appended to information due to compatibility reasons
743 btfss setpoint_changed ; Check flag 744 btfss setpoint_changed ; Check flag
748 749
749 store_dive_data5: 750 store_dive_data5:
750 bcf event_occured ; Clear the global event flag 751 bcf event_occured ; Clear the global event flag
751 return ; Done. (Sample with all informations written to EEPROM) 752 return ; Done. (Sample with all informations written to EEPROM)
752 753
753 store_dive_nuy2: 754 store_dive_cns:
755 movff char_O_CNS_fraction,WREG
756 call write_external_eeprom ; Store in EEPROM
754 GETCUSTOM8 d'26' 757 GETCUSTOM8 d'26'
755 movwf divisor_nuy2 ; Reload divisor from CF 758 movwf divisor_cns ; Reload divisor from CF
756 return 759 return
757 760
758 store_dive_decodebug: 761 store_dive_decodebug:
759 ; Dump 9 bytes, int_O_DBS_bitfield .. char_O_NDL_at_20mtr 762 ; Dump 9 bytes, int_O_DBS_bitfield .. char_O_NDL_at_20mtr
760 lfsr FSR2, int_O_DBS_bitfield 763 lfsr FSR2, int_O_DBS_bitfield
789 call write_external_eeprom 792 call write_external_eeprom
790 GETCUSTOM8 d'24' 793 GETCUSTOM8 d'24'
791 movwf divisor_ppo2 ; Reload divisor from CF 794 movwf divisor_ppo2 ; Reload divisor from CF
792 return 795 return
793 796
794 store_dive_tankdata: 797 store_dive_gf:
795 movlw d'0' ; Dummy Tank1 798 movff char_O_gradient_factor,WREG ; gradient factor absolute
796 call write_external_eeprom
797 movlw d'0' ; Dummy Tank2
798 call write_external_eeprom 799 call write_external_eeprom
799 GETCUSTOM8 d'23' 800 GETCUSTOM8 d'23'
800 movwf divisor_tank ; Reload divisor from CF 801 movwf divisor_gf ; Reload divisor from CF
801 return 802 return
802 803
803 store_dive_decodata: 804 store_dive_decodata:
804 movf decodata+0,W ; =0:no stop dive, if in deco mode: ceiling in m 805 movf decodata+0,W ; =0:no stop dive, if in deco mode: ceiling in m
805 call write_external_eeprom 806 call write_external_eeprom
1296 swapf temp1,F ; swap nibbels 0-3 with 4-7 1297 swapf temp1,F ; swap nibbels 0-3 with 4-7
1297 GETCUSTOM8 d'22' ; Divisor deco 1298 GETCUSTOM8 d'22' ; Divisor deco
1298 addwf temp1,W ; copy to bits 0-3, result in WREG 1299 addwf temp1,W ; copy to bits 0-3, result in WREG
1299 call write_external_eeprom 1300 call write_external_eeprom
1300 1301
1301 movlw d'2' ; information size tank 1302 movlw d'1' ; information size GF
1302 movwf temp1 ; copy to bits 0-3 1303 movwf temp1 ; copy to bits 0-3
1303 swapf temp1,F ; swap nibbels 0-3 with 4-7 1304 swapf temp1,F ; swap nibbels 0-3 with 4-7
1304 GETCUSTOM8 d'23' ; Divisor Tank 1305 GETCUSTOM8 d'23' ; Divisor GF
1305 addwf temp1,W ; copy to bits 0-3, result in WREG 1306 addwf temp1,W ; copy to bits 0-3, result in WREG
1306 call write_external_eeprom 1307 call write_external_eeprom
1307 1308
1308 movlw d'3' ; information size pp02 1309 movlw d'3' ; information size pp02
1309 movwf temp1 ; copy to bits 0-3 1310 movwf temp1 ; copy to bits 0-3
1317 swapf temp1,F ; swap nibbels 0-3 with 4-7 1318 swapf temp1,F ; swap nibbels 0-3 with 4-7
1318 GETCUSTOM8 d'25' ; Divisor Decodebug 1319 GETCUSTOM8 d'25' ; Divisor Decodebug
1319 addwf temp1,W ; copy to bits 0-3, result in WREG 1320 addwf temp1,W ; copy to bits 0-3, result in WREG
1320 call write_external_eeprom 1321 call write_external_eeprom
1321 1322
1322 movlw d'0' ; information size nuy2 1323 movlw d'1' ; information size cns
1323 movwf temp1 ; copy to bits 0-3 1324 movwf temp1 ; copy to bits 0-3
1324 swapf temp1,F ; swap nibbels 0-3 with 4-7 1325 swapf temp1,F ; swap nibbels 0-3 with 4-7
1325 GETCUSTOM8 d'26' ; Divisor nuy2 1326 GETCUSTOM8 d'26' ; Divisor cns
1326 addwf temp1,W ; copy to bits 0-3, result in WREG 1327 addwf temp1,W ; copy to bits 0-3, result in WREG
1327 call write_external_eeprom 1328 call write_external_eeprom
1328 1329
1329 read_int_eeprom d'26' ; Read Salinity from EEPROM 1330 read_int_eeprom d'26' ; Read Salinity from EEPROM
1330 movf EEDATA,W 1331 movf EEDATA,W
1331 call write_external_eeprom ; Store Salinity to Dive 1332 call write_external_eeprom ; Store Salinity to Dive
1332 1333
1333 movff char_O_CNS_fraction,WREG ; copy into bank1 1334 movff char_O_CNS_fraction,WREG ; copy into bank1
1334 call write_external_eeprom ; Stores CNS% 1335 call write_external_eeprom ; Stores CNS%
1335 1336
1336 ; Add additional 10bytes here.... mH 1337 movff avr_rel_pressure_total+0,WREG ; Average Depth
1338 call write_external_eeprom
1339 movff avr_rel_pressure_total+1,WREG ; Average Depth
1340 call write_external_eeprom
1341
1342 movff total_divetime_seconds+0,WREG ; Total dive time (Regardless of CF01)
1343 call write_external_eeprom
1344 movff total_divetime_seconds+1,WREG ; Total dive time (Regardless of CF01)
1345 call write_external_eeprom
1346
1347 movlw d'32' ; GF_lo
1348 movff char_I_deco_model,lo
1349 decfsz lo,F ; jump over next line if char_I_deco_model == 1
1350 movlw d'11' ; Saturation Multiplier
1351 call getcustom8_1 ; Get Custom function #WREG
1352 call write_external_eeprom ; write WREG into external memory
1353
1354 movlw d'33' ; GF_hi
1355 movff char_I_deco_model,lo
1356 decfsz lo,F ; jump over next line if char_I_deco_model == 1
1357 movlw d'12' ; Desaturation Multiplier
1358 call getcustom8_1 ; Get Custom function #WREG
1359 call write_external_eeprom ; write WREG into external memory
1360
1361 read_int_eeprom d'34' ; Read deco modell
1362 movf EEDATA,W
1363 call write_external_eeprom ; write WREG into external memory
1364
1365 clrf WREG
1366 call write_external_eeprom ; Spare3
1367 clrf WREG
1368 call write_external_eeprom ; Spare2
1369 clrf WREG
1370 call write_external_eeprom ; Spare1
1337 1371
1338 movlw 0xFB ; Header stop 1372 movlw 0xFB ; Header stop
1339 call write_external_eeprom 1373 call write_external_eeprom
1340 movlw 0xFB 1374 movlw 0xFB
1341 call write_external_eeprom 1375 call write_external_eeprom
1402 bra timeout_divemode3 ; Yes, use fixed 5 seconds timeout 1436 bra timeout_divemode3 ; Yes, use fixed 5 seconds timeout
1403 endif 1437 endif
1404 1438
1405 bcf divemode 1439 bcf divemode
1406 incf timeout_counter,F 1440 incf timeout_counter,F
1407 GETCUSTOM8 d'2' ; diveloop_timeout 1441 movlw d'0'
1408 addlw d'2' ; adds two seconds in case timout=zero! 1442 addwfc timeout_counter2,F ; timeout is 15bits
1409 btfsc STATUS,C ; > 255? 1443 GETCUSTOM15 d'2' ; diveloop_timeout
1410 movlw d'255' ; Set to 255... 1444 movff lo,sub_a+0
1411 decf WREG,F ; Limit to 254 1445 movff hi,sub_a+1
1412 cpfsgt timeout_counter 1446 movff timeout_counter, sub_b+0
1413 bsf divemode 1447 movff timeout_counter2, sub_b+1
1448 call sub16 ; sub_c = sub_a - sub_b
1449 btfss neg_flag ; Result negative?
1450 bsf divemode ; No, set flag
1414 return 1451 return
1415 1452
1416 timeout_divemode2: 1453 timeout_divemode2:
1417 incf timeout_counter,F ; seconds... 1454 incf timeout_counter,F ; seconds...
1418 movlw d'60' 1455 movlw d'60'
1693 clrf apnoe_surface_secs 1730 clrf apnoe_surface_secs
1694 clrf apnoe_mins 1731 clrf apnoe_mins
1695 clrf apnoe_secs 1732 clrf apnoe_secs
1696 clrf divemins+0 1733 clrf divemins+0
1697 clrf divemins+1 1734 clrf divemins+1
1735 clrf total_divetime_seconds+0
1736 clrf total_divetime_seconds+1
1698 clrf menupos3 1737 clrf menupos3
1699 bcf menu3_active 1738 bcf menu3_active
1700 clrf divesecs 1739 clrf divesecs
1701 clrf samplesecs 1740 clrf samplesecs
1702 clrf apnoe_timeout_counter ; timeout in minutes 1741 clrf apnoe_timeout_counter ; timeout in minutes
1703 clrf timeout_counter ; takes care of the timeout 1742 clrf timeout_counter ; takes care of the timeout (Low byte)
1704 clrf timeout_counter2 ; Here: counts to six, then store deco data and temperature 1743 clrf timeout_counter2 ; takes care of the timeout (High byte)
1705 clrf AlarmType ; Clear all alarms 1744 clrf AlarmType ; Clear all alarms
1706 bcf event_occured ; clear flag 1745 bcf event_occured ; clear flag
1707 bcf setpoint_changed ; clear flag 1746 bcf setpoint_changed ; clear flag
1708 rcall reset_average1 ; Reset the resettable average depth 1747 rcall reset_average1 ; Reset the resettable average depth
1709 clrf average_depth_hold_total+0 1748 clrf average_depth_hold_total+0
1742 GETCUSTOM8 d'21' 1781 GETCUSTOM8 d'21'
1743 movwf divisor_temperature ; load divisors for profile storage 1782 movwf divisor_temperature ; load divisors for profile storage
1744 GETCUSTOM8 d'22' 1783 GETCUSTOM8 d'22'
1745 movwf divisor_deco 1784 movwf divisor_deco
1746 GETCUSTOM8 d'23' 1785 GETCUSTOM8 d'23'
1747 movwf divisor_tank 1786 movwf divisor_gf
1748 GETCUSTOM8 d'24' 1787 GETCUSTOM8 d'24'
1749 movwf divisor_ppo2 1788 movwf divisor_ppo2
1750 GETCUSTOM8 d'25' 1789 GETCUSTOM8 d'25'
1751 movwf divisor_deco_debug 1790 movwf divisor_deco_debug
1752 GETCUSTOM8 d'26' 1791 GETCUSTOM8 d'26'
1753 movwf divisor_nuy2 1792 movwf divisor_cns
1754 1793
1755 btfss FLAG_apnoe_mode ; In Apnoe mode? 1794 btfss FLAG_apnoe_mode ; In Apnoe mode?
1756 bra divemode1 1795 bra divemode1
1757 ; Overwrite some parameters in Apnoe mode.... 1796 ; Overwrite some parameters in Apnoe mode....
1758 movlw d'1' 1797 movlw d'1'