SN8P2200 Series
USB 1.1 Low-Speed 8-Bit Micro-Controller
SONiX TECHNOLOGY CO., LTD
Page 94
Version 1.7
¾
Example: Using T1 to measure P0.1/T1IN input 10KHz frequency. T1RATE is Fcpu/8. Fhosc=6MHz,
Fcpu=Fhosc/1=6MHz. T1 edge trigger is falling edge.
; Set T1 mode.
CLR
T1C
; Clear T1 counter buffers.
B0BCLR
FT1IRQ
; Clear T1IRQ.
MOV
A, #01010000h
; Set T1RATE = Fcpu/8.
B0MOV
T1M, A
; Set T1 edge is falling edge.
B0BSET
FT1ENB
; Enable T1 timer.
; Start to measure P0.1/T1IN input frequency.
Chk_T1IRQ:
B0BTS1
FT1IRQ
; Check T1IRQ set status..
JMP
Chk_T1IRQ
B0MOV
A, T1C
; T1C=75
B0MOV
T1CBUF, A
; Save T1C.
…
;
Application
program.
CLR
T1C
; Clear T1C.
B0BCLR
FT1IRQ
; Clear T1IRQ.
JMP
Chk_T1IRQ
; Measure next signal.
The T1C = 75. Time base is 1.33us in T1RATE=101 (Fcpu/8) and Fcpu = 6MHz.
Input frequency = 1 / (1.33us * 75) = 10.025KHz
≈
10KHz
Above example is using polling to check TnIRQ. Tn supports interrupt function. When TnIEN=1 and TnIRQ=1, program
counter (PC) points to interrupt vector (ORG 8) and process interrupt service routine.
ORG
8
JMP
ISR
; Go to interrupt service routine.
ORG 10
; User’s program.
…
; T1 setting.
B0BSET
FT1IEN
; Enable T1 interrupt function.
…
; main program.
ISR:
PUSH
; Save ACC and PFLGA.
Chk_T1IRQ:
B0BTS1
FT1IRQ
; Check T1IRQ set status..
JMP
Chk_T1IRQ
B0MOV
A, T1C
; T1C=75
B0MOV
T1CBUF, A
; Save T1C.
…
;
Application
program.
CLR
T1C
; Clear T1C.
B0BCLR
FT1IRQ
; Clear T1IRQ for next frequency measurement.
…
POP
; Reload ACC and PFLAG.
RETI
; Exit interrupt service routine.