INITIALIZATION AND PROGRAMMING EXAMPLES
M68HC16 Z SERIES
E-20
USER’S MANUAL
CMPB #$20
BNE NO_DOG ;choose which string start address to load
LDX #DOG_STRING ;COP caused the reset
BRA PRINT
NO_DOG: LDX #NO_DOG_STR ;COP did not cause the reset
PRINT: JSR SEND_STRING ;print the string to the screen
ANDP #$FF1F ;set interrupt priority mask level to 0
***** The Main Program *****
MAIN: NOP
BRA MAIN ;keep on looping until watchdog causes a reset
;or we get some other interrupt
***** Subroutines *****
SEND_STRING: ;subroutine to send out the entire ASCII
string
LDAB 0,X ;get next byte in string as pointed to by IX
BEQ STRING_DONE ;if B=00, then we're done
JSR SEND_CH ;go send out the byte
AIX #$01 ;increment IX to point to the next byte
BRA SEND_STRING ;loop back and do next byte in string
STRING_DONE:
RTS ;go back to whence we came
SEND_CH: ;subroutine to send out one byte to SCI
LDAA SCSR ;read SCI status reg to check/clear TDRE bit
ANDA #$01 ;check only the TDRE flag bit
BEQ SEND_CH ;if TDR is not empty, go back to check it
again
LDAA #$00 ;clear A to send a full word to SCDR ($FFC0E)
STD SCDR ;transmit one ASCII character to the screen
TC_LOOP:
LDAB SCSR+1
ANDB #$80 ;test the TC bit (transfer complete)
BEQ TC_LOOP ;continue to wait until TC is set
RTS ;finish sending out byte
***** The STRINGs *****
DOG_STRING DC 'The Software Watchdog just caused a reset!',0a,0d,00
NO_DOG_STR DC 'The last reset was not caused by the COP.',0a,0d,00
AUTOV_STRING DC 'Feeding the dog...',0a,0d,00
***** Periodic Interrupt Vector Routine *****
VECRT: ;When the processor is interrupted by the
;periodic timer, it will run this routine.
;This routine simply increments a clock
;every time it is interrupted, and prints
;the clock out on the dummy terminal.
SECONDS: ;advance the counter for seconds
F
re
e
sc
a
le
S
e
m
ic
o
n
d
u
c
to
r,
I
Freescale Semiconductor, Inc.
For More Information On This Product,
Go to: www.freescale.com
n
c
.
..