;
;
delmain: main delay routine; generates delay equal to H:X x 20us
-------
delmain: mov #$36,tsc
sthx tmodh
;stop TIM & / 64
;count H:X x 20us
bclr 5,tsc
;start clock
delwait: brclr 7,tsc,delwait ;wait for end of countdown
pulx
pulh
rts
;this RTS serves for all delay routines!
;-------- A/D Routines ----------------------------------------------
;
;
adcbyti: gets single A/D reading from PTA0 and returns it in A
-------
adcbyti: mov #$00,adscr ;ADC set to PTA0
brclr 7,adscr,*
lda adr
rts
;wait for ADC reading
;result in adr
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
;
;
adcbyta: gets averaged A/D reading from PTA0 and returns it in A
-------
adcbyta: clr CNT
clr RB
;average 256 readings
;will be addint them up
;in RB:RA
clr RA
do256a: bsr adcbyti
add RA
sta RA
lda RB
adc #$00
sta RB
;16-bit add into RB:RA
dbnz CNT,do256a ;do all 256
lsl RA
bcc nochga
inc RB
;if RA<$80
;then RB result is correctly rounded
;otherwise round off to next value
nochga: lda RB
rts
;-------- LCD Routines ----------------------------------------------
;
;
lcdinit: initializes LCD
-------
lcdinit: lda #$3C
bsr lcdcmdo
lda #$0C
;set 8-bit interface, 1/16 duty, 5x10 dots
;display on, cursor off, blink off
;increment cursor position, no display shift
;clear display
bsr lcdcmdo
lda #$06
bsr lcdcmdo
lda #$01
bsr lcdcmdo
rts
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
;
;
lcdcmdo: sends a command to LCD
-------
lcdcmdo: bsr shiftA
bclr 4,porta
bset 3,porta
bclr 3,porta
bsr del5ms
rts
;RS=0 for command
;toggle E
;some commands require 2ms for LCD to execute
;so let's play it safe
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
;
;
lcdchro: sends a character (data) to LCD
-------
lcdchro: bsr shiftA
bset 4,porta
;RS=1 for data
AN1950
20
Sensors
Freescale Semiconductor