Hardware Reference
In-Depth Information
Step 5
The main program continues to perform other operations.
The interrupt service routine of OC0 performs the following operations:
If ( HiorLo 55 1)
Start an OC0 operation using DelayHi as the delay count
HiorLo 0
Return from interrupt
Else
Start an OC0 operation using DelayLo as the delay count
HiorLo 1
Return from interrupt.
The assembly program that implements this algorithm is as follows:
#include
“c:\miniide\hcs12.inc”
DelayHi equ
18000
; pulse high interval duration
DelayLo equ
12000
; pulse low interval duration
NN
equ
10
; number of pulses to be created
org
$1000
pcount
ds.b
1
; number of OC0 operations remaining to be performed
HiorLo
ds.b
1
; flag to choose DelayHi(1) or DelayLo(0)
org
$1500
lds
#$1500
movw
#oc0ISR,UserTimerCh0
; set up OC0 interrupt vector
movb
#$90,TSCR1
movb
#$04,TSCR2
bset
TIOS,OC0
; enable OC0
movb
#C0F,TFLG1
; clear C0F flag
movb
#$03,TCTL2
; set OC0 pin action to pull high
ldd
TCNT
; use OC0 operation to pull TC0 pin high
addd
#12
; quickly
std
TC0
;
brclr
TFLG1,C0F,*
; wait until C0F flag is set
movb
#$01,TCTL2
; set OC0 pin action to toggle
ldd
TC0
; start next OC0 operation with
addd
#DelayHi
; delay set to DelayHi
std
TC0
;
movb
2*NN-1,pcount
; prepare to perform pcount OC0 operations
clr
HiorLo
; next OC0 operation use DelayLo as delay
bra
$
oc0ISR
ldaa
HiorLo
; check the flag to choose delay count
beq
pulseLo
; if flag is 0, then go and use DelayLo
ldd
TC0
; start an OC0 operation and use
addd
#DelayHi
; DelayHi as delay count
std
TC0
;
movb
#0,HiorLo
; toggle the flag
bra
decCnt
pulseLo ldd
TC0
; start an OC0 operation and use
addd
#DelayLo
; DelayLo as delay count
std
TC0
;
movb
#1,HiorLo
; toggle the flag
 
Search WWH ::




Custom Search