SN8P2711A
8-Bit Micro-Controller
SONiX TECHNOLOGY CO., LTD
Page 89
Version 0.1
8.2.7 TC0 TIMER OPERATION SEQUENCE
TC0 timer operation includes timer interrupt, event counter, TC0OUT and PWM. The sequence of setup TC0 timer is
as following.
)
Stop TC0 timer counting, disable TC0 interrupt function and clear TC0 interrupt request flag.
B0BCLR
FTC0ENB
; TC0 timer, TC0OUT and PWM stop.
B0BCLR
FTC0IEN
; TC0 interrupt function is disabled.
B0BCLR
FTC0IRQ
; TC0 interrupt request flag is cleared.
)
Set TC0 timer rate. (Besides event counter mode.)
MOV
A, #0xxx0000b
;The TC0 rate control bits exist in bit4~bit6 of TC0M. The
; value is from x000xxxxb~x111xxxxb.
B0MOV
TC0M,A
; TC0 interrupt function is disabled.
)
Set TC0 timer clock source.
; Select TC0 internal / external clock source.
B0BCLR
FTC0CKS
; Select TC0 internal clock source.
or
B0BSET
FTC0CKS
; Select TC0 external clock source.
; Select TC0 Fcpu / Fosc internal clock source .
B0BCLR
FTC0X8
; Select TC0 Fcpu internal clock source.
or
B0BSET
FTC0X8
; Select TC0 Fosc internal clock source.
Note: TC0X8 is useless in TC0 external clock source mode.
)
Set TC0 timer auto-load mode.
B0BCLR
FALOAD0
; Enable TC0 auto reload function.
or
B0BSET
FALOAD0
; Disable TC0 auto reload function.
)
Set TC0 interrupt interval time, TC0OUT (Buzzer) frequency or PWM duty cycle.
; Set TC0 interrupt interval time, TC0OUT (Buzzer) frequency or PWM duty.
MOV
A,#7FH
; TC0C and TC0R value is decided by TC0 mode.
B0MOV
TC0C,A
; Set TC0C value.
B0MOV
TC0R,A
; Set TC0R value under auto reload mode or PWM mode.
; In PWM mode, set PWM cycle.
B0BCLR
FALOAD0
; ALOAD0, TC0OUT = 00, PWM cycle boundary is
B0BCLR FTC0OUT ;
0~255.
or
B0BCLR
FALOAD0
; ALOAD0, TC0OUT = 01, PWM cycle boundary is
B0BSET FTC0OUT ;
0~63.
or
B0BSET
FALOAD0
; ALOAD0, TC0OUT = 10, PWM cycle boundary is
B0BCLR FTC0OUT ;
0~31.
or
B0BSET
FALOAD0
; ALOAD0, TC0OUT = 11, PWM cycle boundary is
B0BSET FTC0OUT ;
0~15.