194
CHAPTER 9 16-BIT TIMER/COUNTER
MB89620 series
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.
TCR register value = 2
16
– 25 ms/(4/10 MHz) = 3036 (0BDC
H
)
l
Coding example
TMCR
EQU
0018H
; Address of the 16-bit timer control register
TCHR
EQU
0019H
; Upper address of the timer count register
TCLR
EQU
001AH
; Lower address of the timer count register
TCEF
EQU
TMCR:2
; Define the interrupt request flag bit.
TCS
EQU
TMCR:0
; Define the count start bit.
ILR2
EQU
007DH
; Address of the interrupt level setting register 2
INT_V
DSEG
ABS
; [DATA SEGMENT]
ORG
0FFEEH
IRQ6
DW
WARI
; Set interrupt vector.
INT_V
ENDS
;-----Main program----------------------------------------------------------------------------------------------------------------------------------------
CSEG
; [CODE SEGMENT]
; Stack pointer (SP) etc. are already initialized.
:
CLRI
; Disable interrupts.
CLRB
TCS
; Stop counter operation.
MOV
ILR2,#11011111B
; Set interrupt level (level 1).
MOV
TCHR,#0BH
; Set data for 25 ms timer.
MOV
TCLR,#0DCH
MOV
TMCR,#00100011B
; Store counter value, operate interval timer, clear interrupt
request flag, enable interrupt request output, and start counter
operation.
SETI
; Enable interrupts.
:
;-----Interrupt processing routine----------------------------------------------------------------------------------------------------------------------
WARI
MOV
TMCR,#00100000B
; Clear interrupt request flag. Stop counter operation.
PUSHW
A
XCHW
A,T
PUSHW
A
MOVW
A,TCHR
; Add time from overflow until interrupt accepted.
MOVW
A,#0BDCH
; 25 ms timer data (for 10 MHz).
CLRC
ADDCW
A
; This does not consider the case when an overflow occurs during
the addition.
MOVW
TCHR,A
; For absolute accuracy, the time while the counter is stopped
should be added.
MOV
TMCR,#00100011B
; Enable interrupts and start the count.
:
User processing
:
POPW
A
XCHW
A,T
POPW
A
RETI
ENDS
;---------------------------------------------------------------------------------------------------------------------------------------------------------------
END
Содержание F2MC-8L MB89620 Series
Страница 8: ......
Страница 10: ...MB89620 series ...
Страница 11: ...vi MB89620 series ...
Страница 17: ...xii MB89620 series ...
Страница 18: ...xvi MB89620 series ...
Страница 30: ...MB89620 series CHAPTER 1 OVERVIEW 9 Memo ...
Страница 34: ...MB89620 series CHAPTER 1 OVERVIEW 13 Memo ...
Страница 42: ...MB89620 series CHAPTER 1 OVERVIEW 21 Memo ...
Страница 49: ...28 CHAPTER 1 OVERVIEW MB89620 series ...
Страница 62: ...MB89620 series CHAPTER 3 CPU 41 Memo ...
Страница 78: ...MB89620 series CHAPTER 3 CPU 57 Memo ...
Страница 82: ...MB89620 series CHAPTER 3 CPU 61 Memo ...
Страница 86: ...MB89620 series CHAPTER 3 CPU 65 Memo ...
Страница 90: ...MB89620 series CHAPTER 3 CPU 69 Memo ...
Страница 96: ...MB89620 series CHAPTER 3 CPU 75 Memo ...
Страница 122: ...MB89620 series CHAPTER 4 I O PORTS 101 Memo ...
Страница 144: ...MB89620 series CHAPTER 5 TIMEBASE TIMER 123 Memo ...
Страница 149: ...128 CHAPTER 5 TIMEBASE TIMER MB89620 series ...
Страница 157: ...136 CHAPTER 6 WATCHDOG TIMER MB89620 series ...
Страница 174: ...MB89620 series CHAPTER 7 8 BIT PWM TIMER 153 Memo ...
Страница 177: ...156 CHAPTER 7 8 BIT PWM TIMER MB89620 series ...
Страница 202: ...MB89620 series CHAPTER 9 16 BIT TIMER COUNTER 181 Memo ...
Страница 217: ...196 CHAPTER 9 16 BIT TIMER COUNTER MB89620 series ...
Страница 220: ...MB89620 series CHAPTER 10 8 BIT SERIAL I O SERIAL I O 1 AND SERIAL I O 2 199 Memo ...
Страница 228: ...MB89620 series CHAPTER 10 8 BIT SERIAL I O SERIAL I O 1 AND SERIAL I O 2 207 Memo ...
Страница 245: ...224 CHAPTER 10 8 BIT SERIAL I O SERIAL I O 1 AND SERIAL I O 2 MB89620 series ...
Страница 266: ...MB89620 series CHAPTER 13 A D CONVERTER 245 13 Memo ...
Страница 283: ...262 CHAPTER 13 A D CONVERTER MB89620 series ...
Страница 289: ...268 CHAPTER 14 CLOCK MONITOR FUNCTION MB89620 series ...
Страница 306: ...MB89620 series APPENDIX 285 APPEND Memo ...
Страница 319: ...298 APPENDIX MB89620 series Memo ...
Страница 321: ...2 ...
Страница 354: ......