chip sn8p2711A
.data
acc_buf ds 1
pflag_buf ds 1
TC0_buf ds 1
.code
org 00h
jmp main
org 08h
jmp isr
org 10h
//============================================================================
// timer TC0 --> internal clock and auto re-load
//============================================================================
main:
mov a,#00h
b0mov TC0_buf,a
b0bclr ftc0enb
mov a,#20h //Fcpu/64
b0mov tc0m,a
mov a,#64h //10ms interrupt Once
b0mov tc0c,a
b0mov tc0r,a
//=============================================================================
b0bset faload0 //enable auto re-load
//=============================================================================
b0bset ftc0enb // Enable Tc0 timer
b0bset ftc0ien // Enable Tc0 interrupt
b0bclr ftc0irq // Clean Tc0 interrupt request flag
b0bset fgie // all interrupt operation
main10:
//==================================================================
//
// User code
//
//==================================================================
jmp main10
//===============================================================================================
// TC0 set 10ms interval time for TC0 interrupt. X'tal:4M Fcpu=Fosc/4 TC0RATE=010 (Fcpu/64)
//===============================================================================================
//
// TC0 initial value = 256-(TC0 interrupt interval time*clocl)
// = 256-(10ms*4MHz /4 /64)
// = 256-(0.01*4*1000000/4/64)
// = 100
// = 64H
//
isr:
mov acc_buf,a // Push ACC to buffer
mov a,pflag
b0mov pflag_buf,a // Push PFLAG to buffer
isr_adc:
b0bts1 ftc0ien // Check tc0ien
jmp isr90
b0bts1 ftc0irq // Check tc0irp
jmp isr90
b0bclr ft0irq
mov a,TC0_buf
add a,#01h // 0.5sec add one time
b0mov TC0_buf,a
isr90:
mov a,pflag_buf
b0mov pflag,a // Pop pflag_buf to pflag
mov a,acc_buf // Pop acc_buf to acc
reti
TC0 定时方式初始化设置 时间验算方法 SONIX
最新推荐文章于 2021-07-13 18:09:59 发布