📄 timer.asm
字号:
*********************************************************************************
* MEMORY.ASM v1.00 *
* 版权(c) 2003- 北京合众达电子技术有限责任公司 *
* 设计者: 段立锋 *
*********************************************************************************
.file "timer.asm"
.c_mode
.mmregs
.copy "vc54x.inc" ; VC5402 Memory-Mapped Register Declaration
.copy "dec5416.inc" ; SEED DEC5416 Memory-Mapped Register Declaration
.def _timer_start
.def _timer_stop
.def _timer_status
.def _timer_isr
.def _time_end
.def _dataend
****************************************************************************
*定时器设置参数 *
****************************************************************************
PRD_DATA .set 0A0H ;the period of timer is 0.001s
PRD_DATA1 .set 0ffffH ;the period of timer is 0.001s
TCR_START .set 0c6fH ;start the timer
TCR_STOP .set 010H ;stop the timer
.data
_timer_period .word 0
_timer_pdcount .word 0
_timer_statusd .word 0
_dataend .word 0
.sect ".timer"
*****************************************************************************
* *
* 函数定义:void _timer_start(uint period) *
* 功 能:启动定时器 *
* *
* 入口参数:A ---- 定时周期,单位为毫秒 *
* 出口参数:无 *
* 资源使用:A,AR0 *
* *
*****************************************************************************
_timer_start:
STM #0,AH
STM #_timer_period,AR0
STL A,*AR0 ;save the time period value
STM #_timer_pdcount,AR0
STL A,*AR0 ;set the time period count value
;启动定时器
STM #PRD_DATA,PRD ;set the period of the Timer0
STM #PRD_DATA,TIM
STM #TCR_START,TCR ;start the timer
.if __far_mode
FRET
.else
RET
.endif
*****************************************************************************
* *
* 函数定义:void _timer_stop() *
* 功 能:停止定时器 *
* *
* 入口参数:无 *
* 出口参数:无 *
* *
*****************************************************************************
_timer_stop:
STM #TCR_STOP,TCR ;stop the timer
.if __far_mode
FRET
.else
RET
.endif
*****************************************************************************
* *
* 函数定义:bool _timer_status() *
* 功 能:启动定时器 *
* *
* 入口参数:无 *
* 出口参数:A ----定时是否完成 *
* 未完成: 00H *
* 完成: 01H *
* 资源使用:A,AR0 *
* *
*****************************************************************************
_timer_status:
STM #_timer_statusd,AR0
LD *AR0,A
STM #0,AH
BC timer_exit,AEQ
NOP
NOP
ST #0,*AR0 ;清除标志
timer_exit: NOP
.if __far_mode
FRET
.else
RET
.endif
****************************************************************************
*定时器中断服务程序,频率为1MHz *
****************************************************************************
_timer_isr:
PSHM AL
PSHM AH
PSHM AR0
STM #_timer_pdcount,AR0 ;取当前的周期值
STM #0,AH
LD *AR0,A
SUB #1,A ;当前记数值减一
STL A,*AR0 ;保存当前的计数值
STM #0,AH
BC timer_next,ANEQ
STM #_timer_period,AR0 ;重置当前的周期记数值
LD *AR0,A
STM #_timer_pdcount,AR0
STL A,*AR0
STM #_timer_statusd,AR0
ST #1,*AR0 ;设置定时完成标志
timer_next: POPM AR0
POPM AH
POPM AL
POPM ST1
POPM ST0
RETE
_time_end: NOP
.end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -