
M68HC16 Z SERIES
INITIALIZATION AND PROGRAMMING EXAMPLES
USER’S MANUAL
E-27
STAB
TMSK2
;& set the TCNT's prescale to sysclock/128
*
Set up Input Capture and Output Compare
LDAB
#$27
;Input Captures
STAB
TCTL2
;TIC1=either, TIC2=rise, TIC3=fall, TIC4=off
LDAB
#$01
;Output Compares
STAB
TCTL1
;TOC2=toggle, TOC3=off, TOC4=off, TOC5=off
LDD
#$1000
;set OC2 to toggle every time that
STD
TOC2
;TCNT is #$1000
*
Set up the Pulse Width Modulators A and B
LDD
#$0064
;set PWM prescaler to div by 128
STD
PWMC
;set PWMA fast (512 Hz)
;and PWMB slow (4 Hz)
LDAB
#$80
;set 50% duty cycle
STAB
PWMA
;in PWMA
STAB
PWMB
;in PWMB
*
Set up the Pulse Accumulator
LDD
#$5000
;set PAC to sense rising edges in
STD
PACTL
;event counting mode
*
Other Initializations
LDAB
#$00
TBXK
;set XK to bank 0 for STRING access
PAOV_CNT EQU
0
;counter variable for PAOV_ROUTINE
LDAB
#$01
TBZK
LDZ
#$0000
;PAOV_CNT will be indexed off ZK:IZ
LDAB
#$0A
STAB
PAOV_CNT,Z
;load a 10 into the variable
ANDP
#$FF1F
;set interrupt priority mask level to 0
*****
Start of main program
*****
GO:
NOP
BRA
GO
;Let's loop until we're interrupted
*****
Subroutines
*****
SEND_STRING:
EVEN
;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 the string is 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
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
..
.