
252
CHAPTER 9 16-BIT TIMER/COUNTER
I
Program Example of the Counter Function
H
Processing specifications
Generate an interrupt whenever the rising edge of a pulse being input to the EC pin is
counted 10,000 times.
Use the interrupt processing routine to reset the TCR register and generate an interrupt
repeatedly.
The following shows the TCR register value at which the counter overflows when a rising
edge is detected 10,000 times.
TCR register value = 2
16
- 10000 = 65536 - 10000 = 55536 = D8F0H
H
Coding example
TMCR .EQU 0073H ; Address of the timer control reister
TCHR .EQU 0074H ; Upper address of the timer count
register
TCLR .EQU 0075H ; Lower address of the timer count
register
TCEF .EQU TMCR:2 ; Definition of the interrupt request
flag bit
TCS .EQU TMCR:0 ; Definition of the count start bit
ILR4 .EQU 007EH ; Address of the interrupt level setting
register
.SECTION INT_V, DATA, LOCATE=0 ; [DATA SEGMENT]
.ORG 0FFDCH
IRQF .DATA.H WARI ; Setting interrupt vector
;INT_V ENDS
;----Main program---------------------------------------------------
-----
.SECTION CSEG, CODE, ALIGN=1 ; [CODE SEGMENT]
; Stack pointer (SP) and other
are assumed to have been initialized
:
CLRI ; Interrupt disable
CLRB TCS ; Count operation stop
MOV ILR4,#01111111B ; Setting interrupt level (level 1)
MOV TCHR,#0D8H ; Initialize the counter value
MOV TCLR,#0F0H
MOV TMCR,#00110011B ; Retain the counter value,
set the counter function
(selecting the rising edge of
external input), clearing the
interrupt request flag, enabling
the interrupt request output, and
enabling the counter operation
SETI ; Interrupt enable
:
;----Interrupt program------------------------------------------------
WARI
CLRB TCEF ; Clearing interrupt request flag
PUSHW A
XCHW A,T
PUSHW A
CLRB TCS ; Stop counter operation