n Program Example for Counter Function
l
Processing description
•
Generates an interrupt after 10000 rising edges are counted on the pulses input to the EC
pin.
•
The interrupt processing routine resets the TCR register for the next interrupt.
•
The following shows the TCR register value that results in an overflow after 10000 counts.
l
Coding example
DDR3
TMCR
TCHR
TCLR
TCEF
TCS
ILR2
INT_V
IRQ6
INT_V
;-----Main program----------------------------------------------------------------------------------------------------------------------------------------
;-----Interrupt processing routine----------------------------------------------------------------------------------------------------------------------
WARI
;---------------------------------------------------------------------------------------------------------------------------------------------------------------
MB89620 series
16
TCR register value = 2
EQU
000DH
EQU
0018H
EQU
0019H
EQU
001AH
EQU
TMCR:2
EQU
TMCR:0
EQU
007DH
DSEG
ABS
ORG
0FFEEH
DW
WARI
ENDS
CSEG
:
MOV
DDR3,#00000000B
CLRI
CLRB
TCS
MOV
ILR2,#11011111B
MOV
TCHR,#0D8H
MOV
TCLR,#0F0H
MOV
TMCR,#00110011B
SETI
CLRB
TCEF
PUSHW
A
XCHW
A,T
PUSHW
A
CLRB
TCS
MOV
A,#0D8H
MOV
TCHR,A
MOV
A,#0F0H
MOV
TCLR,A
SETB
TCS
:
User processing
:
POPW
A
XCHW
A,T
POPW
A
RETI
ENDS
END
– 10000 = 65536 – 10000 = 55536 = D8F0
; Address of the16-bit timer control register
; Upper address of the timer count register
; Lower address of the timer count register
; Define the interrupt request flag bit.
; Define the count start bit.
; Address of the interrupt level setting register 2
; [DATA SEGMENT]
; Set interrupt vector.
; [CODE SEGMENT]
; Stack pointer (SP) etc. are already initialized.
; Set P34/EC pin as an input.
; Disable interrupts.
; Stop counter operation.
; Set interrupt level (level 1).
; Initialize the counter value.
; Store counter value, the counter function (select rising edges on
the external input), clear interrupt request flag, enable interrupt
request output, and enable counter operation.
; Enable interrupts.
; Clear interrupt request flag.
; Stop counter operation.
; Initialize the counter value.
; This ignores the pulses after an overflow.
; Restart counter operation. Count 10000 pulses from this time.
CHAPTER 9 16-BIT TIMER/COUNTER
H
195