do256: lda #$C9
jsr lcdcmdo
lda CNT
deca
;position LCD cursor at the right spot
;display current iteration $FF downto $00
;get reading
jsr lcdbyto
lda #':'
jsr lcdchro
jsr adcbyti
add RA
sta RA
lda RB
adc #$00
sta RB
jsr lcdbyto
lda RA
;add into RB:RA (16 bit add)
;show RB
jsr lcdbyto
;then RA
dbnz CNT,do256
;and do 256x
lsl RA
bcc nochg
inc RB
;get bit7 into carry
;if C=0 then no need to round up
;otherwise round up
nochg: lda RB
ldhx #N1
;we can discard RA: average value is in RB
;point to flash location
;burn it in!
jsr wrflash
ldhx #msg05c
jsr lcdstro
;ask for 160mm
waitPB2: brset 2,porta,waitPB2 ;wait for ENT
ldhx #msg05d
jsr lcdstro
clr CNT
;2nd point cal: show values
;ditto as 1st point cal
clr RB
clr RA
do256b: lda #$C9
jsr lcdcmdo
lda CNT
deca
jsr lcdbyto
lda #':'
jsr lcdchro
jsr adcbyti
add RA
sta RA
lda RB
adc #$00
sta RB
jsr lcdbyto
lda RA
jsr lcdbyto
dbnz CNT,do256b
lsl RA
bcc nochg2
inc RB
nochg2: lda RB
cmp N1
;compare N2 to N1
bne validcal
ldhx #msg05e
jsr lcdstro
jsr del1s
;if different, we are OK
;otherwise warn of INVALID CAL!
jsr del1s
jsr del1s
;wait 2s
jmp CALIB
;try cal again
AN1950
Sensors
10
Freescale Semiconductor