Hardware Reference
In-Depth Information
Step 9
Compute the fractional digit by multiplying rem by 10 and then dividing the resulting
product by 62.
Step 10
Compute the integral digits by performing repeated division by 10 to quo .
Step 11
Wait for 200 ms and then go to step 2.
The assembly program that implements this algorithm is as follows:
#include “c:\miniIDE\hcs12.inc”
period
equ
$2E
; ASCII code of period character
degree
equ
223
; ASCII code of degree character
org
$1000
quo
ds.b
1
rem
ds.b
1
sign
ds.b
1
fract
ds.b
1
buf
ds.b
8
; to hold string to be output to LCD
org
$1500
lds
#$1500
; set up stack pointer
ldy
#2
; wait for LCD to complete
jsr
delayby100ms
; internal configuration
jsr
openlcd
; configure LCD
ldaa
#$80
; set LCD cursor to upper
jsr
cmd2lcd
; left corner
ldx
#msg1
; output “Temperature 5
jsr
puts2lcd
;
jsr
openAD0
; configure ATD0 module
forever
movb
#$20,buf
; initialize the buffer contents to 0.0°C
movb
#$20,buf 1 1
;
movb
#$30,buf 1 2
;
movb
#period,buf 1 3
;
movb
#$30,buf 1 4
;
movb
#degree,buf 1 5
; degree character
movb
#$43,buf 1 6
; letter 'C'
movb
#0,buf 1 7
; null character
movb
#$87,ATD0CTL5
; start an ATD conversion sequence
movb
#0,sign
; initialize sign to positive
movb
#$30,fract
; initialize fractional digit to 0
brclr
ATD0STAT0,SCF,*
; wait for the conversion to complete
ldd
ATD0DR0
; read a conversion result
ldy
#10
; compute result x 10/62
emul
;
ldx
#62
;
ediv
;
stab
rem
; save the remainder
tfr
y,d
; transfer quotient to B
subb
#40
; subtract temperature offset
bhs
save_quo
; if nonnegative, don't touch remainder
Search WWH ::




Custom Search