![](http://datasheet.mmic.net.cn/120000/MB89P195P-101_datasheet_3559072/MB89P195P-101_147.png)
MB89190/190A series
Chapter 7 8-/16-bit Timer/Counter
7-27
7.
12 ProgramExamplesfor8-/16-bitTimer/Counter
Examples of programs for the 8-/16-bit timer/counter are shown.
T Example program for interval timer function
Processing specification
– Only timer 1 is used in the 8-bit mode to generate a 20-ms interval timer interrupt repeatedly.
– A square wave that is reversed after the elapse of the interval timer is output to the TO pin.
– The T1DR register value that gives an interval time of 20 ms when the original oscillation (FC) is 4.2
MHz (1 instruction cycle = 4/FC) is shown below. The internal count clock 512 tINST is assumed to
be the count clock.
T1DR register value = 20 ms/(512
× 4/4.2 MHz) 1 = 40.0 (28
H)
Coding example
T2CR
EQU
0018
H
; Address of timer 2 control register
T1CR
EQU
0019
H
; Address of timer 1 control register
T2DR
EQU
001A
H
; Address of timer 2 data register
T1DR
EQU
001B
H
; Address of timer 1 data register
T1IF
EQU
T1CR:7
; Definition of timer 1 interrupt request flag bit
ILR1
EQU
007C
H
; Address of interrupt level setting register
INT_V
DSEG
ABS
ORG
FFF4
H
IRQ3
DW
WARI
; Interrupt vector setting
ENDS
;---------- Main program ---------------------------------------------------------------------
CSEG
;[CODE SEGMENT]
; Stack pointer (SP) assumed initialized
:
CLRI
; Interrupt disabled
MOV
ILR1, #10111111B
; Interrupt level set to 2
MOV
T2CR, #00000010B
; Timer 2 interrupt request flag cleared, interrupt request
output disabled, other than 16-bit mode set, operation
stopped
MOV
T1CR, #00011000B
; Timer 1 interrupt request flag cleared, square wave
initial value “L”, 512 t
INST
selected, operation stopped
MOV
T1DR, #28H
; Value (interval time) to be compared to counter value set
MOV
T1CR, #00111000B
; Output L level to square wave
output pin (TO)
MOV
T1CR, #11111001B
; Timer 1 interrupt request output enabled, counter cleared,
and timer started
SETI
; CPU interrupt enabled
:
;---------- Interrupt program ----------------------------------------------------------------
WARI
CLRB
T1IF
; Interrupt request flag cleared
PUSHW
A
XCHW
A,T
PUSHW
A
:
Processing by user
:
POPW
A
XCHW
A,T
POPW
A
RETI
ENDS
; --------------------------------------------------------------------------------------------
END