Mercurial > public > hwos_code
comparison src/i2c.asm @ 654:75e90cd0c2c3
hwOS sport 10.77 release
| author | heinrichsweikamp |
|---|---|
| date | Thu, 14 Mar 2024 16:56:46 +0100 |
| parents | bc214815deb2 |
| children | c7b7b8a358cd |
comparison
equal
deleted
inserted
replaced
| 653:8bcd138ab744 | 654:75e90cd0c2c3 |
|---|---|
| 2 ; | 2 ; |
| 3 ; File i2c.asm * combined next generation V3.09.4b | 3 ; File i2c.asm * combined next generation V3.09.4b |
| 4 ; | 4 ; |
| 5 ; I2C Interface | 5 ; I2C Interface |
| 6 ; | 6 ; |
| 7 ; Copyright (c) 2012, JD Gascuel, HeinrichsWeikamp, all right reserved. | 7 ; Copyright (c) 2012, JD Gascuel, heinrichs weikamp gmbh, all right reserved. |
| 8 ;============================================================================= | 8 ;============================================================================= |
| 9 ; | 9 ; |
| 10 ; Compass0 | 10 ; Compass0 |
| 11 ; -------- | 11 ; -------- |
| 12 ; HMC5883L's read address (8-Bit): 0x3D | 12 ; HMC5883L's read address (8-Bit): 0x3D |
| 1134 ; divide by 65536 instead of 65535, introducing an error of 65536/65535 = 0.002 % | 1134 ; divide by 65536 instead of 65535, introducing an error of 65536/65535 = 0.002 % |
| 1135 movff xC+2,batt_voltage+0 ; divide by 65536 can easily be done by just taking the 3rd and 4th byte of the multiplication result | 1135 movff xC+2,batt_voltage+0 ; divide by 65536 can easily be done by just taking the 3rd and 4th byte of the multiplication result |
| 1136 movff xC+3,batt_voltage+1 ; ... | 1136 movff xC+3,batt_voltage+1 ; ... |
| 1137 | 1137 |
| 1138 tstfsz batt_voltage+1 ; < 256 mV ? | 1138 tstfsz batt_voltage+1 ; < 256 mV ? |
| 1139 return ; NO - done | 1139 return ; NO - done |
| 1140 bra lt2942_init ; YES - initialize gauge and return | 1140 bra lt2942_init_again ; YES - initialize gauge and return |
| 1141 | 1141 |
| 1142 | 1142 |
| 1143 ;----------------------------------------------------------------------------- | 1143 ;----------------------------------------------------------------------------- |
| 1144 ; Read Gauge IC - Temperature | 1144 ; Read Gauge IC - Temperature |
| 1145 ; | 1145 ; |
| 1237 call div16x16 ; xC = xA / xB with xA as remainder | 1237 call div16x16 ; xC = xA / xB with xA as remainder |
| 1238 movff xC+0,batt_percent ; result is battery percentage | 1238 movff xC+0,batt_percent ; result is battery percentage |
| 1239 movlw .100 ; max. value is 100 % | 1239 movlw .100 ; max. value is 100 % |
| 1240 cpfslt batt_percent ; batt_percent < 100 % ? | 1240 cpfslt batt_percent ; batt_percent < 100 % ? |
| 1241 movwf batt_percent ; NO - limit to 100 % | 1241 movwf batt_percent ; NO - limit to 100 % |
| 1242 movlw .95 ; < 95 % | |
| 1243 cpfsgt batt_percent | |
| 1244 bcf lock_cycle_counter ; Yes, unlock cycle counter | |
| 1242 return ; done | 1245 return ; done |
| 1243 | 1246 |
| 1244 lt2942_set_to_zero_percent: | 1247 lt2942_set_to_zero_percent: |
| 1245 movlw 0x02 ; point to accumulated charge registers | 1248 movlw 0x02 ; point to accumulated charge registers |
| 1246 rcall I2C_TX_GAUGE ; send byte to the LT2942 gauge IC | 1249 rcall I2C_TX_GAUGE ; send byte to the LT2942 gauge IC |
| 1329 clrf battery_gauge+1 ; ... | 1332 clrf battery_gauge+1 ; ... |
| 1330 clrf battery_gauge+2 ; ... | 1333 clrf battery_gauge+2 ; ... |
| 1331 clrf battery_gauge+3 ; ... | 1334 clrf battery_gauge+3 ; ... |
| 1332 clrf battery_gauge+4 ; ... | 1335 clrf battery_gauge+4 ; ... |
| 1333 clrf battery_gauge+5 ; ... | 1336 clrf battery_gauge+5 ; ... |
| 1337 banksel charge_cycles | |
| 1338 clrf charge_cycles+0 ; null the charge cycles | |
| 1339 clrf charge_cycles+1 ; ... | |
| 1334 banksel common ; back to bank common | 1340 banksel common ; back to bank common |
| 1335 goto eeprom_battery_gauge_write ; update battery registers in EEPROM, unblock ISR and return | 1341 goto eeprom_battery_gauge_write ; update battery registers in EEPROM, unblock ISR and return |
| 1336 | 1342 |
| 1337 | 1343 |
| 1338 | 1344 |
