7.12 Program Examples for 8/16-bit Timer/Counter
This section gives program examples for the 8/16-bit timer/counter.
Program Example for Interval Timer Function
Processing description
•
Repeatedly generates 20 ms interval timer interrupts, when using only the timer 1 in 8-bit
mode.
•
Outputs the square wave inverted at fixed time intervals to the TO pin.
•
The T1DR register value shown below assumes an oscillation frequency (F
the fastest main clock speed (gear function) (1 instruction cycle = 4/F
time of approx. 20 ms. The count clock is an internal count clock of 512 t
Coding example
T2CR
EQU
T1CR
EQU
T2DR
EQU
T1DR
EQU
T1IF
EQU
ILR1
EQU
INT_V
DSEG
ORG
IRQ3
DW
ENDS
;-----Main program----------------------------------------------------------------------------------------------------------------------------------
CSEG
:
CLRI
MOV
T1DR register value = 20 ms/(512 × 4/4.2 MHz) - 1 = 40.0 (28
0018H
0019H
001AH
001BH
T1CR:7
007CH
ABS
FFF4H
WARI
ILR1, #10111111
7.12 Program Examples for 8/16-bit Timer/Counter
; Address of the timer 2 control register
; Address of the timer 1 control register
; Address of the timer 2 data register
; Address of the timer 1 data register
; Define the timer 1 interrupt request flag bit.
; Address of the interrupt level setting register
; Set interrupt vector.
; [CODE SEGMENT]
; Stack pointer (SP) etc. are already initialized.
; Disable interrupts.
; Set interrupt level (level2).
of 4.2 MHz,
CH
), and an interval
CH
.
inst
)
H
189