comparison code_part1/OSTC_code_asm_part1/altimeter.asm @ 170:0f7ca37b1412

Altimeter: auto reset + when ref not in [900..1100] mbar (checked on 8bits). + display only mbar (not 1/4 mbar), and +/- 1mbar. + added menu default to 1013(.25) mbar.
author JeanDo
date Mon, 31 Jan 2011 21:21:53 +0100
parents 80de93d72a17
children 53b16a746166
comparison
equal deleted inserted replaced
169:e26f49674956 170:0f7ca37b1412
27 ; Known bug: Simulator reset altitude and reference... 27 ; Known bug: Simulator reset altitude and reference...
28 28
29 altimeter_calc: 29 altimeter_calc:
30 movlb HIGH(pressureAvg) 30 movlb HIGH(pressureAvg)
31 31
32 movlw HIGH(4*.1100) ; Is presure ref lower than 900mbar 32 movlw HIGH(4*.900) ; Is presure ref bigger than 900mbar
33 cpfslt pressureRef+1 33 cpfsgt pressureRef+1
34 bra altimeter_1 ; No: ok it is valid... 34 bra altimeter_reset ; No: Should do a reset now.
35 35
36 movlw HIGH(4*.1100) ; Is ref pressure bigger than 1100mbar ? 36 movlw HIGH(4*.1100) ; Is ref pressure bigger than 1100mbar ?
37 cpfsgt pressureRef+1 37 cpfsgt pressureRef+1
38 bra altimeter_1 ; No: ok it is valid... 38 bra altimeter_1 ; No: ok it is valid...
39 39
40 altimeter_0: 40 ; Reset computation. Eg. after a sleep, enables to faster restart with correct
41 ; values...
42 altimeter_reset:
43 movlb HIGH(pressureAvg)
41 movlw LOW(4*.1013+1) ; Init see level at 1013,25 mbar. 44 movlw LOW(4*.1013+1) ; Init see level at 1013,25 mbar.
42 movwf pressureRef+0 45 movwf pressureRef+0
43 movlw HIGH(4*.1013+1) 46 movlw HIGH(4*.1013+1)
44 movwf pressureRef+1 47 movwf pressureRef+1
45 48
46 ; Reset computation. Eg. after a sleep, enables to faster restart with correct
47 ; values...
48 altimeter_reset:
49 movlb HIGH(pressureAvg)
50 clrf pressureSum+0 ; Init averaging area 49 clrf pressureSum+0 ; Init averaging area
51 clrf pressureSum+1 50 clrf pressureSum+1
52 clrf pressureCount 51 clrf pressureCount
53 52
54 movff amb_pressure+0,pressureAvg+0 ; And init first average. 53 movff amb_pressure+0,pressureAvg+0 ; And init first average.
231 WIN_FONT .0 230 WIN_FONT .0
232 WIN_LEFT .80-7*7 231 WIN_LEFT .80-7*7
233 WIN_TOP .1 232 WIN_TOP .1
234 STRCPY_PRINT "Set Altimeter:" 233 STRCPY_PRINT "Set Altimeter:"
235 234
236 movlw 3 ; Start menu on line 3. 235 movlw 2 ; Start menu on line 2.
237 movwf menupos 236 movwf menupos
238 237
239 altimeter_menu_2: 238 altimeter_menu_2:
240 WIN_FONT .0 ; Reset, because compute erase that... 239 WIN_FONT .0 ; Reset, because compute erase that...
241 WIN_INVERT .0 240 WIN_INVERT .0
252 rrcf hi 251 rrcf hi
253 rrcf lo 252 rrcf lo
254 bsf leftbind 253 bsf leftbind
255 output_16 254 output_16
256 255
257 PUTC '.' 256 ; PUTC '.'
258 movff pressureRef+0, hi ; Decimal part is constructed 257 ; movff pressureRef+0, hi ; Decimal part is constructed
259 clrf WREG ; from the 2 lower bits. 258 ; clrf WREG ; from the 2 lower bits.
260 btfsc hi,0 259 ; btfsc hi,0
261 addlw .25 260 ; addlw .25
262 btfsc hi,1 261 ; btfsc hi,1
263 addlw .50 262 ; addlw .50
264 movwf lo 263 ; movwf lo
265 output_99x 264 ; output_99x
266 265
267 STRCAT_PRINT "mbar " 266 STRCAT_PRINT " mbar "
268 267
269 WIN_TOP .65 ; Second line: 268 WIN_TOP .65 ; Action enable
270 STRCPY "Alt: "
271 movff altitude+0, lo
272 movff altitude+1, hi
273 btfss hi,7 ; Is altitude negativ ?
274 bra altimeter_menu_3 ; No: just print it
275
276 PUTC '-' ; Yes: print the minus sign
277 comf hi ; And do a 16bit 2-complement.
278 comf lo
279 infsnz lo
280 incf hi
281
282 altimeter_menu_3:
283 bsf leftbind
284 output_16
285 bcf leftbind
286 STRCAT_PRINT "m "
287
288 WIN_TOP .95 ; Action enable
289 STRCPY "Enabled: " 269 STRCPY "Enabled: "
290 GETCUSTOM8 .49 270 GETCUSTOM8 .49
291 btfss WREG,0 271 btfss WREG,0
292 bra alt_menu_1 272 bra alt_menu_1
293 STRCAT_PRINT "ON " 273 STRCAT_PRINT "ON "
294 bra alt_menu_2 274 bra alt_menu_2
295 alt_menu_1: 275 alt_menu_1:
296 STRCAT_PRINT "OFF" 276 STRCAT_PRINT "OFF"
297 alt_menu_2: 277 alt_menu_2:
298 278
279 WIN_TOP .95 ; Action reset
280 STRCPY_PRINT "Default: 1013 mbar"
299 WIN_TOP .125 ; Action add 281 WIN_TOP .125 ; Action add
300 STRCPY_PRINT "+0.25 mbar" 282 STRCPY_PRINT "+1 mbar"
301 WIN_TOP .155 ; Action sub 283 WIN_TOP .155 ; Action sub
302 STRCPY_PRINT "-0.25 mbar" 284 STRCPY_PRINT "-1 mbar"
303 WIN_TOP .185 ; Action exit 285 WIN_TOP .185 ; Action exit
304 STRCPY_PRINT "Exit" 286 STRCPY_PRINT "Exit"
287
288 WIN_LEFT .85 ; Bottom right.
289 STRCPY "Alt: "
290 movff altitude+0, lo
291 movff altitude+1, hi
292 btfss hi,7 ; Is altitude negativ ?
293 bra altimeter_menu_3 ; No: just print it
294
295 PUTC '-' ; Yes: print the minus sign
296 comf hi ; And do a 16bit 2-complement.
297 comf lo
298 infsnz lo
299 incf hi
300
301 altimeter_menu_3:
302 bsf leftbind
303 output_16
304 bcf leftbind
305 STRCAT_PRINT "m "
305 306
306 alt_menu_loop: 307 alt_menu_loop:
307 call PLED_menu_cursor ; Display cursor 308 call PLED_menu_cursor ; Display cursor
308 bcf switch_left ; reset buttons state 309 bcf switch_left ; reset buttons state
309 bcf switch_right 310 bcf switch_right
336 alt_menu_next: 337 alt_menu_next:
337 incf menupos ; next line. 338 incf menupos ; next line.
338 movlw .7 339 movlw .7
339 cpfseq menupos ; Below last line ? 340 cpfseq menupos ; Below last line ?
340 bra alt_menu_loop 341 bra alt_menu_loop
341 movlw .3 ; Yes: back to line no 3. 342 movlw .2 ; Yes: back to line no 2.
342 movwf menupos 343 movwf menupos
343 bra alt_menu_loop 344 bra alt_menu_loop
344 345
345 ;----- Execute menu line ----------------------------------------------------- 346 ;----- Execute menu line -----------------------------------------------------
346 347
347 alt_menu_do_it: 348 alt_menu_do_it:
348 movf menupos,W ; test line value 349 movf menupos,W ; test line value
349 addlw -3 350 addlw -2
350 bz alt_menu_enable 351 bz alt_menu_enable ; 2 --> reset
352 dcfsnz WREG
353 bra alt_menu_reset ; 3 --> +1
351 dcfsnz WREG 354 dcfsnz WREG
352 bra alt_menu_plus1 ; 4 --> +1 355 bra alt_menu_plus1 ; 4 --> +1
353 dcfsnz WREG 356 dcfsnz WREG
354 bra alt_menu_minus1 ; 5 --> -1 357 bra alt_menu_minus1 ; 5 --> -1
355 bra alt_menu_exit ; else --> exit 358 bra alt_menu_exit ; else --> exit
364 movlw 4*(.49-.32) + 0x82 ; CF#49 low byte address in EEPROM 367 movlw 4*(.49-.32) + 0x82 ; CF#49 low byte address in EEPROM
365 movwf EEADR 368 movwf EEADR
366 call write_eeprom 369 call write_eeprom
367 bra altimeter_menu_2 370 bra altimeter_menu_2
368 371
372 ;---- Reset sea level pressure to reference ----------------------------------
373 alt_menu_reset:
374 rcall altimeter_reset
375 movlb 1 ; Go back to normal bank1
376 bra altimeter_menu_2
377
369 ;---- Increment sea level pressure ------------------------------------------- 378 ;---- Increment sea level pressure -------------------------------------------
370
371 alt_menu_plus1: 379 alt_menu_plus1:
372 movlb HIGH(pressureRef) ; Setup our own ram bank 380 movlb HIGH(pressureRef) ; Setup our own ram bank
373 infsnz pressureRef+0 ; 16bit inc. 381 movlw 4
374 incf pressureRef+1 382 addwf pressureRef+0,F ; 16bit inc.
383 movlw 0
384 addwfc pressureRef+1,F
375 bra alt_menu_recompute ; then recompute altitude. 385 bra alt_menu_recompute ; then recompute altitude.
376 386
377 ;---- Decrement sea level pressure ------------------------------------------- 387 ;---- Decrement sea level pressure -------------------------------------------
378
379 alt_menu_minus1: 388 alt_menu_minus1:
380 movlb HIGH(pressureRef) ; Setup our own ram bank 389 movlb HIGH(pressureRef) ; Setup our own ram bank
381 decf pressureRef+0 ; 16bit decrement 390 movlw -4
382 movlw 0 391 addwf pressureRef+0,F ; 16bit decrement
383 subwfb pressureRef+1 392 movlw -1
393 addwfc pressureRef+1,F
384 394
385 alt_menu_recompute: 395 alt_menu_recompute:
386 rcall compute_altitude ; Recompute altitude 396 rcall compute_altitude ; Recompute altitude
387 movlb 1 ; Go back to normal bank1 397 movlb 1 ; Go back to normal bank1
388 bra altimeter_menu_2 398 bra altimeter_menu_2