ECE 2325 UMD S.Norr
HW6:
11-7: An alternate method
toggling PA5 using the
CFORC register:
;
; Dly10:
a subroutine which turns on PA5,
; waits for 10 mS, then turns off PA5
; and returns.
;
; DOES NOT CORRUPT REGISTERS
;
; Assumptions:
; PR1, PR0 = 1,0 and E-clck = 2 MHz such that
; TCNT is counting at 4 microsec per count
; Also assume that PA5 is currently off
Dly10: pshx
psha
pshb
ldx #1000
bset 26,x,80 ; Make PortA = output (DDRA = 1)
ldaa 20,x
psha
; Put old contents of TCTL1 on stack
bset 20,x,10 ;
bclr 20,x,20 ; Make OM3, OL3 = 01 (Toggle PA5)
bset 0b,x,20 ; Force an OC3 using CFORC register
ldd 0e,x
addd #9c0 ; Set up TOC3 for 10 ms compare :
std 1a,x ; (9c4 - 4) cycles which executed
; between PA5 on and the load of TCNT
bclr 23,x,20 ; clear any "stale" OC3F flag to
; prepare for new one
Wait: brset 23,x,20,End ; Wait for OC3F flag to be set
bra Wait
End: pula
staa 20,x ; Restore old contents of TCTL1
pulb
pula ; restore accumulators and return
pulx
rts