comparison code_part1/OSTC_code_asm_part1/outputs.asm @ 826:2151c4135fad

CHANGE: Battery percent based on ON-Time instead of battery voltage
author heinrichsweikamp
date Wed, 30 Sep 2015 20:25:28 +0200
parents 1a64088b49d3
children 0cf00ecf3532
comparison
equal deleted inserted replaced
825:588867b0d5c2 826:2151c4135fad
2250 movff lo,sub_a+0 2250 movff lo,sub_a+0
2251 movff hi,sub_a+1 2251 movff hi,sub_a+1
2252 call sub16 ; sub_c = sub_a - sub_b 2252 call sub16 ; sub_c = sub_a - sub_b
2253 btfss neg_flag 2253 btfss neg_flag
2254 bra update_batt_voltage0 ; Normal display 2254 bra update_batt_voltage0 ; Normal display
2255 WIN_BOX_BLACK .174, .194, .1, .34 ;top, bottom, left, right 2255 WIN_BOX_BLACK .174, .194, .1, .35 ;top, bottom, left, right
2256 return
2257
2258 update_batt_get_percent_in_lo:
2259 ; percent = ontime [m] * 100 / CF74
2260 movff on_time_seconds+0,xC+0
2261 movff on_time_seconds+1,xC+1
2262 movff on_time_seconds+2,xC+2
2263 clrf xC+4
2264 movlw .60
2265 movwf xB+0
2266 clrf xB+1
2267 call div32x16 ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder
2268 movff xC+0,xA+0
2269 movff xC+1,xA+1 ; On-Time in full minutes
2270 movlw .100
2271 movwf xB+0
2272 clrf xB+1
2273 call mult16x16 ;xA*xB=xC
2274 GETCUSTOM15 d'74'
2275 movff lo,xB+0
2276 movff hi,xB+1
2277 call div32x16 ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder
2278 movff xC+0,lo ; Copy result
2279
2280 ; Limit to 100
2281 movlw .100
2282 cpfslt lo
2283 movwf lo
2284 ; lo will be between 0 (Full) and 100 (empty)
2285 movf lo,W
2286 sublw .100
2287 movwf lo
2288
2289 movlw .100
2290 cpfslt lo
2291 movwf lo
2292 ; lo will be between 100 (Full) and 0 (empty)
2256 return 2293 return
2257 2294
2258 update_batt_voltage: 2295 update_batt_voltage:
2259 ostc_debug 'f' 2296 ostc_debug 'f'
2260 btfss secs,0 2297 btfss secs,0
2270 WIN_TOP .175 2307 WIN_TOP .175
2271 WIN_LEFT .1 2308 WIN_LEFT .1
2272 WIN_FONT FT_SMALL 2309 WIN_FONT FT_SMALL
2273 WIN_INVERT .0 ; Init new Wordprocessor 2310 WIN_INVERT .0 ; Init new Wordprocessor
2274 call DISP_standard_color 2311 call DISP_standard_color
2275 2312 call update_batt_get_percent_in_lo ; 100 - 0
2276 lfsr FSR2,letter 2313 lfsr FSR2,letter
2277 movff batt_voltage+0,lo 2314 STRCPY TXT_BATT ; Batt:
2278 movff batt_voltage+1,hi 2315 bsf leftbind
2279 movlw d'1' 2316 output_8
2280 movwf ignore_digits
2281 bsf ignore_digit5 ; do not display mV
2282 bsf leftbind
2283 output_16dp d'2' ; e.g. 3.45V
2284 bcf leftbind 2317 bcf leftbind
2285 STRCAT_PRINT TXT_VOLT2 2318 STRCAT_PRINT "%"
2286 return 2319 return
2287 2320
2288 update_batt_voltage2: 2321 update_batt_voltage2:
2289 WIN_FRAME_STD .174, .194, .1, .32 2322 WIN_FRAME_STD .174, .194, .1, .33
2290 2323
2291 ; 4100-Vbatt 2324 call update_batt_get_percent_in_lo ; 100 - 0
2292 movlw LOW d'4100' 2325 movf lo,W
2293 movwf sub_a+0 2326 mullw .10 ; PRODH:PRODL = 1000 - 0
2294 movlw HIGH d'4100' 2327 movff PRODH,divA+1
2295 movwf sub_a+1 2328 movff PRODL,divA+0
2296 movff batt_voltage+0,sub_b+0 2329 movlw .5
2297 movff batt_voltage+1,sub_b+1 2330 movwf divB
2298 call sub16 ; sub_c = sub_a - sub_b 2331 call div16 ; divA=divA/2^divB (divB: 8Bit only!)
2299 ; Battery full (>4100mV? 2332 ; xC is between 0 and 32
2300 btfsc neg_flag 2333 movff divA+0,wait_temp ;save value
2301 bra update_batt_voltage2_full
2302
2303 ; Vbatt-3500
2304 movlw LOW d'3500'
2305 movwf sub_b+0
2306 movlw HIGH d'3500'
2307 movwf sub_b+1
2308 movff batt_voltage+0,sub_a+0
2309 movff batt_voltage+1,sub_a+1
2310 call sub16 ; sub_c = sub_a - sub_b
2311 ; Battery lower then 3500mV?
2312 btfsc neg_flag
2313 bra update_batt_voltage2_empty
2314
2315 ; Battery is between 3500 and 4100mV
2316 ; sub_c:2 is between 0 and 600
2317 movff sub_c+0,xA+0
2318 movff sub_c+1,xA+1
2319 movlw d'20'
2320 movwf xB+0
2321 clrf xB+1
2322 call div16x16 ;xA/xB=xC with xA as remainder
2323 ; xC is between 0 and 30
2324 movff xC+0,wait_temp ;save value
2325 incf wait_temp,F ; +1
2326 2334
2327 movlw d'3' 2335 movlw d'3'
2328 cpfsgt wait_temp 2336 cpfsgt wait_temp
2329 movwf wait_temp ; Minimum = 3 2337 movwf wait_temp ; Minimum = 3
2330 2338
2331 update_batt_voltage2a: 2339 update_batt_voltage2a:
2332 WIN_BOX_STD .181, .187, .32, .34 ; Battery nose 2340 WIN_BOX_STD .181, .187, .33, .35 ; Battery nose
2333 2341
2334 update_batt_voltage3: 2342 update_batt_voltage3:
2335 GETCUSTOM8 d'34' ; Color battery 2343 GETCUSTOM8 d'34' ; Color battery
2336 btfsc cc_active 2344 btfsc cc_active
2337 ; movlw color_yellow ; CC active 2345 ; movlw color_yellow ; CC active
2349 movff wait_temp,win_width ; column right (0-159) 2357 movff wait_temp,win_width ; column right (0-159)
2350 call DISP_box 2358 call DISP_box
2351 call DISP_standard_color 2359 call DISP_standard_color
2352 return 2360 return
2353 2361
2354 update_batt_voltage2_empty: 2362 ;update_batt_voltage2_empty:
2355 movlw d'1' 2363 ; movlw d'1'
2356 movwf wait_temp 2364 ; movwf wait_temp
2357 bra update_batt_voltage2a 2365 ; bra update_batt_voltage2a
2358 2366 ;
2359 update_batt_voltage2_full: 2367 ;update_batt_voltage2_full:
2360 movlw d'30' 2368 ; movlw d'30'
2361 movwf wait_temp 2369 ; movwf wait_temp
2362 bra update_batt_voltage2a 2370 ; bra update_batt_voltage2a
2363 2371
2364 DISP_convert_signed_temperature: 2372 DISP_convert_signed_temperature:
2365 btfss hi,7 ; Negative temperature ? 2373 btfss hi,7 ; Negative temperature ?
2366 return ; No, return 2374 return ; No, return
2367 ; Yes, negative temperature! 2375 ; Yes, negative temperature!