Program Examples For 16-Bit Timer/Counter - Fujitsu F2MC-8L MB89620 Series Hardware Manual

8-bit microcontroller
Table of Contents

Advertisement

9
9.

Program Examples for 16-bit Timer/Counter

This section gives program examples for the 16-bit timer/counter.
n Program Example for Interval Timer Function
l
Processing description
Generates 25 ms interval timer interrupts.
The interrupt processing routine resets the TCR register for the next interrupt.
The following shows the TCR register value that results in an interval time of 25 ms for a
10 MHz source oscillation.
Coding example
l
TMCR
TCHR
TCLR
TCEF
TCS
ILR2
INT_V
IRQ6
INT_V
;-----Main program----------------------------------------------------------------------------------------------------------------------------------------
;-----Interrupt processing routine----------------------------------------------------------------------------------------------------------------------
WARI
;---------------------------------------------------------------------------------------------------------------------------------------------------------------
194
CHAPTER 9 16-BIT TIMER/COUNTER
16
TCR register value = 2
EQU
0018H
EQU
0019H
EQU
001AH
EQU
TMCR:2
EQU
TMCR:0
EQU
007DH
DSEG
ABS
ORG
0FFEEH
DW
WARI
ENDS
CSEG
:
CLRI
CLRB
TCS
MOV
ILR2,#11011111B
MOV
TCHR,#0BH
MOV
TCLR,#0DCH
MOV
TMCR,#00100011B
SETI
:
MOV
TMCR,#00100000B
PUSHW
A
XCHW
A,T
PUSHW
A
MOVW
A,TCHR
MOVW
A,#0BDCH
CLRC
ADDCW
A
MOVW
TCHR,A
MOV
TMCR,#00100011B
:
User processing
:
POPW
A
XCHW
A,T
POPW
A
RETI
ENDS
END
– 25 ms/(4/10 MHz) = 3036 (0BDC
; Address of the 16-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.
; Disable interrupts.
; Stop counter operation.
; Set interrupt level (level 1).
; Set data for 25 ms timer.
; Store counter value, operate interval timer, clear interrupt
request flag, enable interrupt request output, and start counter
operation.
; Enable interrupts.
; Clear interrupt request flag. Stop counter operation.
; Add time from overflow until interrupt accepted.
; 25 ms timer data (for 10 MHz).
; This does not consider the case when an overflow occurs during
the addition.
; For absolute accuracy, the time while the counter is stopped
should be added.
; Enable interrupts and start the count.
)
H
MB89620 series

Advertisement

Table of Contents
loading

Table of Contents