MOTOROLA
INITIALIZATION AND PROGRAMMING EXAMPLES
M68HC16 Z SERIES
E-22
USER’S MANUAL
LDAB
SCCNT,Z
JSR
HEXTOASC
;convert hex number to ASCII and print
LINE_FD:
;output a linefeed
LDAB
#$0A
;load ASCII number for line feed
JSR
SEND_CH
;send character to terminal
CARRIAGE:
;output a carriage return
LDAB
#$0D
;ASCII number for carriage return
JSR
SEND_CH
;send character to terminal
RTS
;done with display routine
*****
Hexadecimal to ASCII conversion
*****
HEXTOASC:
;the following code takes a number or
;character stored in register D, assumes
;it's in its hexadecimal form and converts
;it to an ASCII equivalent. It also sends
;that character to the screen.
STD
TEMP,Z
;store the hex number temporarily into “TEMP”
JSR
PRTMSB
LDD
TEMP,Z
;reload value of hex number into D register
ANDB
#$0F
;get rid of upper 4 bits in hex number
BRA
PRTLSB
PRTMSB: LSRB
;shift high 4 bits down to low 4 bits position
LSRB
PRTLSB:
;the actual conversion process:
ADDB
#$30
;add $30 to the hex number
CMPB
#$39
;check for digithood
BLS
NOTAF
;go print now if it's a digit 0-9
ADDB
#$07
;it's a letter A-F, so add $07 before printing
NOTAF:
JSR
SEND_CH
;send the character to the SCI
RTS
;done with hex to ascii conversion
*****
Autovector Routine
*****
AUTOV:
;when IRQ6 is low, this autovector routine starts
LDAB #$55
;These four lines reset the watchdog and keep it
STAB SWSR
;from causing a system reset by writing to the SWSR
LDAB #$AA
;By writing a #$55 and a #$AA to the SWSR before
;the end
STAB SWSR
;of every time-out period, the watchdog will be
reset.
LDX
#AUTOV_STRING
JSR
SEND_STRING
RTI
;return to the main loop
*****
Other exception/interrupts
*****
BDM:
BGND
;all other exception vectors point here
;and put the user into background mode