diff src/i2c.asm @ 449:850c1f3c4824

minor
author heinrichsweikamp
date Wed, 31 Aug 2016 14:24:29 +0200
parents aadfe9f2edaf
children 7f4c3b2e6bb7
line wrap: on
line diff
--- a/src/i2c.asm	Tue Aug 30 17:26:21 2016 +0200
+++ b/src/i2c.asm	Wed Aug 31 14:24:29 2016 +0200
@@ -777,7 +777,7 @@
 
     clrf    batt_percent   ; Set to zero
     btfsc   neg_flag                ; result negative?
-    return                          ; Yes, done.
+    bra	    lt2942_set_to_zero_percent	; Yes, keep LT2942 at zero percent and return
 
     ; > Zero, set batt_percent properly
     movff   sub_c+0,xA+0
@@ -788,6 +788,19 @@
     movff   xC+0,batt_percent
     return
 
+lt2942_set_to_zero_percent:
+	clrf	i2c_temp
+	movlw	0x02                ; Point to accumulated charge registers
+	rcall	I2C_TX_GAUGE
+	movff	battery_offset+1,SSP1BUF
+	rcall	WaitMSSP
+	rcall	I2C_WaitforACK
+	movff	battery_offset+0,SSP1BUF
+	rcall	WaitMSSP
+	rcall	I2C_WaitforACK
+	bsf	SSP1CON2,PEN		; Stop condition
+	bra	WaitMSSP; (and return)
+
 	global	lt2942_charge_done
 lt2942_charge_done:                 ; Reset accumulating registers to 0xFFFF
 	clrf	i2c_temp