📄 timer.c
字号:
return (0);
}
/*********************************************************************************************************
** Function name: timerConfig
** Descriptions: 设置定时器控制选项
** input parameters: ucTimer 定时器号
** ucOption 选项(timer.h)
** output parameters: NONE
** Returned value: 正确返回 0, 错误返回 -1
** Created by: Hanhui
** Created Date: 2007/09/18
**--------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
**--------------------------------------------------------------------------------------------------------
*********************************************************************************************************/
int timerConfig (unsigned char ucTimer, unsigned char ucOption)
{
switch (ucTimer) {
case 0: /* 定时器 0 */
rTCON &= 0xFFFFFF00;
rTCON |= ucOption;
break;
case 1: /* 定时器 1 */
rTCON &= 0xFFFFF0FF;
rTCON |= (unsigned int)(ucOption << 8);
break;
case 2: /* 定时器 2 */
rTCON &= 0xFFFF0FFF;
rTCON |= (unsigned int)(ucOption << 12);
break;
case 3: /* 定时器 3 */
rTCON &= 0xFFF0FFFF;
rTCON |= (unsigned int)(ucOption << 16);
break;
case 4: /* 定时器 4 */
rTCON &= 0xFF0FFFFF;
if (ucOption & TIMER_RELOAD) { /* timer4 没有 INVERTER 位 */
ucOption &= 0x07;
ucOption |= TIMER_INVERTER; /* INVERTER 位 决定 Reload */
}
rTCON |= (unsigned int)(ucOption << 20);
break;
default:
return (-1);
}
return (0);
}
/*********************************************************************************************************
** Function name: timerSetCnt
** Descriptions: 设置定时器初始计数值
** input parameters: ucTimer 定时器号
** usCnt 计数值
** output parameters: NONE
** Returned value: 正确返回 0, 错误返回 -1
** Created by: Hanhui
** Created Date: 2007/09/18
**--------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
**--------------------------------------------------------------------------------------------------------
*********************************************************************************************************/
int timerSetCnt (unsigned char ucTimer, unsigned short usCnt)
{
switch (ucTimer) {
case 0: /* 定时器 0 */
rTCNTB0 = usCnt;
break;
case 1: /* 定时器 1 */
rTCNTB1 = usCnt;
break;
case 2: /* 定时器 2 */
rTCNTB2 = usCnt;
break;
case 3: /* 定时器 3 */
rTCNTB3 = usCnt;
break;
case 4: /* 定时器 4 */
rTCNTB4 = usCnt;
break;
default:
return (-1);
}
return (0);
}
/*********************************************************************************************************
** Function name: timerSetCmp
** Descriptions: 设置定时器比较值
** input parameters: ucTimer 定时器号
** usCnt 比较值
** output parameters: NONE
** Returned value: 正确返回 0, 错误返回 -1
** Created by: Hanhui
** Created Date: 2007/09/18
**--------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
**--------------------------------------------------------------------------------------------------------
*********************************************************************************************************/
int timerSetCmp (unsigned char ucTimer, unsigned short usCnt)
{
switch (ucTimer) {
case 0: /* 定时器 0 */
rTCMPB0 = usCnt;
break;
case 1: /* 定时器 1 */
rTCMPB1 = usCnt;
break;
case 2: /* 定时器 2 */
rTCMPB2 = usCnt;
break;
case 3: /* 定时器 3 */
rTCMPB3 = usCnt;
break;
default: /* 没有定时器 4 */
return (-1);
}
return (0);
}
/*********************************************************************************************************
** Function name: timerGetCnt
** Descriptions: 获得定时器计数值
** input parameters: ucTimer 定时器号
** output parameters: NONE
** Returned value: 计数值 错误返回 -1
** Created by: Hanhui
** Created Date: 2007/09/18
**--------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
**--------------------------------------------------------------------------------------------------------
*********************************************************************************************************/
int timerGetCnt (unsigned char ucTimer)
{
switch (ucTimer) {
case 0: /* 定时器 0 */
return (rTCNTO0);
case 1: /* 定时器 1 */
return (rTCNTO1);
case 2: /* 定时器 2 */
return (rTCNTO2);
case 3: /* 定时器 3 */
return (rTCNTO3);
case 4: /* 定时器 4 */
return (rTCNTO4);
default:
return (0);
}
}
/*********************************************************************************************************
END FILE
*********************************************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -