timer.c
来自「移植在鱼板上运行的ucos」· C语言 代码 · 共 47 行
C
47 行
#include "includes.h"
/*************************************************************************/
/* */
/* NAME : tm_init(timer device, time periode) */
/* */
/* FUNCTIONS : Initialize the TIMER0,1. */
/* */
/* EXAMPLES : */
/* tm_init(TIMER_DEV0,ONE_SECOND/TICKS_PER_SECOND); */
/* */
/* Where, the TIMER_DEV0 means timer0. */
/* ONE_SECOND = 1000, */
/* TICKS_PER_SECOND = 100, */
/* then timer0 timer periode become to 10ms. */
/* */
/* VARIABLES USED */
/* */
/* */
/* HISTORY */
/* */
/* NAME DATE REMARKS */
/* */
/* in4maker 06-07-1999 Created initial version 1.0 */
/* */
/*************************************************************************/
void tm_init(int TIMER_DEV, int t)
{
if(TIMER_DEV) /* for TIMER 1 */
{
Disable_Int(nTIMER1_INT);
SysSetInterrupt(nTIMER1_INT, OSTimeTick);
TDATA1 = t_data_ms(t); /* unit is [ms] */
TCNT1 = 0x0;
TMOD = TM1_TOGGLE; /* Toggle pulse will be out to port */
Enable_Int(nTIMER1_INT); /* Timer interrupt enable */
}
else /* for TIMER0 */
{
Disable_Int(nTIMER0_INT);
SysSetInterrupt(nTIMER0_INT, OSTimeTick);
TDATA0 = t_data_ms(t);
TCNT0 = 0x0;
TMOD = TM0_TOGGLE;
Enable_Int(nTIMER0_INT);
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?