comparison src/i2c.asm @ 449:850c1f3c4824

minor
author heinrichsweikamp
date Wed, 31 Aug 2016 14:24:29 +0200
parents aadfe9f2edaf
children 7f4c3b2e6bb7
comparison
equal deleted inserted replaced
448:aadfe9f2edaf 449:850c1f3c4824
775 movff battery_offset+1,sub_b+1 775 movff battery_offset+1,sub_b+1
776 call subU16 ; sub_c = sub_a - sub_b (with signed values) 776 call subU16 ; sub_c = sub_a - sub_b (with signed values)
777 777
778 clrf batt_percent ; Set to zero 778 clrf batt_percent ; Set to zero
779 btfsc neg_flag ; result negative? 779 btfsc neg_flag ; result negative?
780 return ; Yes, done. 780 bra lt2942_set_to_zero_percent ; Yes, keep LT2942 at zero percent and return
781 781
782 ; > Zero, set batt_percent properly 782 ; > Zero, set batt_percent properly
783 movff sub_c+0,xA+0 783 movff sub_c+0,xA+0
784 movff sub_c+1,xA+1 784 movff sub_c+1,xA+1
785 movff battery_capacity+0,xB+0 785 movff battery_capacity+0,xB+0
786 movff battery_capacity+1,xB+1 786 movff battery_capacity+1,xB+1
787 call div16x16 ;xA/xB=xC with xA+0 as remainder, uses divB as temp variable 787 call div16x16 ;xA/xB=xC with xA+0 as remainder, uses divB as temp variable
788 movff xC+0,batt_percent 788 movff xC+0,batt_percent
789 return 789 return
790 790
791 lt2942_set_to_zero_percent:
792 clrf i2c_temp
793 movlw 0x02 ; Point to accumulated charge registers
794 rcall I2C_TX_GAUGE
795 movff battery_offset+1,SSP1BUF
796 rcall WaitMSSP
797 rcall I2C_WaitforACK
798 movff battery_offset+0,SSP1BUF
799 rcall WaitMSSP
800 rcall I2C_WaitforACK
801 bsf SSP1CON2,PEN ; Stop condition
802 bra WaitMSSP; (and return)
803
791 global lt2942_charge_done 804 global lt2942_charge_done
792 lt2942_charge_done: ; Reset accumulating registers to 0xFFFF 805 lt2942_charge_done: ; Reset accumulating registers to 0xFFFF
793 clrf i2c_temp 806 clrf i2c_temp
794 movlw 0x02 ; Point to accumulated charge registers 807 movlw 0x02 ; Point to accumulated charge registers
795 rcall I2C_TX_GAUGE 808 rcall I2C_TX_GAUGE