Hardware Reference
In-Depth Information
8.8.1 Using the Modulus Down Counter to Generate Periodic Interrupts
Periodic interrupts can be generated by selecting the modulus mode and enabling its
interrupt. The interrupt period is equal to the value written into the load register multiplied
by the prescaler. When writing a value into MCCNT, the same value is also written into the
load register. In the modulus mode, when the MCCNT is decremented to zero, the value
in the load register will be reloaded into the MCCNT register and another cycle of down
counting is started.
Example 8.17
Write an instruction sequence to generate periodic interrupt every 10 ms.
Solution: One possible value to be written into the MCCTL register is $C0, which will
Enable MCCNT
Enable MCCNT interrupt
Enable modulus mode
Set prescaler to 16
The instruction sequence to achieve the desired setting is as follows:
movb
#$C7,MCCTL
movw
#15000,MCCNT
; place the value that will be decremented
; to 0 in 10 ms
cli
; enable interrupt
8.8.2 Using the Modulus Down Counter to Generate Time Delays
The method for generating a time delay by using the modulus down counter is similar to
that for generating periodic interrupts. However, one can choose to use either the modulus
mode or nonmodulus mode. The following example use the nonmodulus mode to generate a
time delay that is equal to 10 ms multiplied by the value in register Y.
Example 8.18
Write a subroutine to generate a time delay that is equal to 10 ms multiplied by the value
in register Y.
Solution: The assembly program that can generate a delay that is equal to 10 ms multiplied by
the value in register Y is as follows:
delay10ms
bset
TSCR1,TFFCA
; enable timer fast flag clear
movb
#$07,MCCTL
; enable modulus down counter with 1:16 as prescaler
movw
#15000,MCCNT
; load the value to be down-counted
brclr
MCFLG,MCZF,*
bclr
MCCTL,$04
; disable modulus down counter
dbne
y,delay10ms
rts
 
Search WWH ::




Custom Search