168
CHAPTER 9 8/16-Bit Timer/Counter
MB89960 series
9.9 Program Examples for the 8/16-Bit
Timer/Counter
This section gives program examples for the 8/16-bit timer/counter.
s Program Example for the Interval Timer Function
q Processing description
Generates 25 ms interval timer interrupts.
The interrupt processing routine resets the T1CR and T2CR registers for the next
interrupt.
The following shows the T1DR and T2DR registers value that results in an interval
time of 25 ms for a source oscillation of 10 MHz and the CS bits in SYCC are both 1.
TDR register value = (25ms/12.8us) - 1 = 1952 (07A0H)
q Coding example
T1CR
EQU
0019H
;Address of the timer 1 control register
T2DR
EQU
001AH
;Upper address of the timer count register
T1DR
EQU
001BH
;Lower address of the timer count register
T2DR
EQU
0018H
; Address of the timer 2 control register
T1IF
EQU
T1CR:7
;Defines the interrupt request flag bit.
T1STR
EQU
T1CR:0
;Defines the count start bit.
DDR3
EQU
000dH
;Data direction register 3
ILR1
EQU
007CH
;Address of interrupt level setting register 1
INT_V
DSEG
ABS
;[DATA SEGMENT]
ORG
0FFEEH
IRQ3
DW
WARI
;Set interrupt vector.
INT_V
ENDS
;-----Main program----------------------------------------------------------------------------------------------------------------------------------------
CSEG
;[CODE SEGMENT]
;Stack pointer (SP) etc. are already initialized.
:
CLRI
;Disable interrupts.
CLRB
T1STR
;Halt count operation.
MOV
DDR3,#00H
;Diable CLK output at P34
MOV
ILR1,#01111111B
;Set interrupt level (level 1).
MOV
T2DR,#07H
;Set data for 25 ms timer.
MOV
T1DR,#A0H
MOV
T1CR,#01000101B
;Do not clear counter value, set interval timer operation, clear
interrupt request flag, enable output of interrupt requests, and
start counter operation.
MOV
T2CR,#01001101B
SETI
;Enable interrupts.
:
;-----Interrupt processing routine----------------------------------------------------------------------------------------------------------------------
WARI
MOV
T1CR,#10000000B
;Clear interrupt request flag. Halt counter operation.
PUSHW
A
XCHW
A,T
PUSHW
A
MOV
T1CR,#01000101B
;Do not clear counter value, set interval timer operation, clear
interrupt request flag, enable output of interrupt requests, and
start counter operation.
MOV
T2CR,#01001101B
:
User processing
:
POPW
A
XCHW
A,T
POPW
A
RETI
ENDS
;---------------------------------------------------------------------------------------------------------------------------------------------------------------
END