lsr DC
ror DB
ror DA
lda NA
add DA
sta NA
lda NB
adc DB
sta NB
lda NC
adc DC
sta NC
lsla
;divide DC:DB:DA by 2
;and add into NC:NB:NA
bcs nornd
lda RA
add #$01
sta RA
lda RB
adc #$00
sta RB
;if carry=1 then remainder<1/2 of dividend
;otherwise add 1 to result
nornd: rts
;__________________________________________________________
;__________________________________________________________
UNITS: brclr 2,porta,UNITS ;let go of ENT first
lda #$01
jsr lcdcmdo
;===UNITS=== Allows user to select units: inches or cm
;clear screen
ldhx #msg03
jsr lcdstro
jsr del100ms
clr RA
lda #$0D
jsr lcdcmdo
;Unit Choice menu
;menu choice=0 to begin with
;blink cursor on menu choice
;get current menu choice
uluke: ldx RA
clrh
lda menupos,x
jsr lcdcmdo
;and look up corresponding LCD address
;reposition cursor
uwarm: brclr 1,porta,uPB1 ;check for SEL
brclr 2,porta,uPB2 ;or for ENT
bclr 4,porta
bset 5,porta
jsr del100ms
bset 4,porta
bclr 5,porta
jsr del100ms
bra uwarm
;otherwise
;turn on "SEL" LED
;delay
;toggle LEDs
;"ENT" now on: means choice is SEL ***or*** ENT
;delay and repeat until SEL or ENT
uPB1: inc RA
lda RA
;***SEL*** toggles menu choices
;menu choices are $00 and $01
cmp #$02
bne uPB1ok
clr RA
;back to $00 when all others have been offered
uPB1ok: bclr 4,porta
bclr 5,porta
;LEDs off
jsr del100ms
;wait a little bit
brclr 1,porta,uPB1ok ;make sure they let go of SEL
bra uluke
AN1950
Sensors
16
Freescale Semiconductor