timer1.c
来自「cc1110,cc2510透传代码,IAR环境的」· C语言 代码 · 共 53 行
C
53 行
#include "includes.h"
//-----------------------------------------------------------------------------
// See hal.h for a description of this function.
//-----------------------------------------------------------------------------
word halSetTimer1Period(dword period){
byte div = 0;
// Checking that the period is not too short for the timer tick interval.
if(TICKSPD > 5) {
if( (period < 2*(TICKSPD-5)) && (period != 0) ){
return 0;
}
}
if(period == 0){ // Max timer period is used.
div = 3;
period = 0x0000FFFF;
}
else{
period = ((period*26) >> TICKSPD); // Calculating number of timer ticks the period
if(period&0xFFFF0000){ // Using prescaler to fit period
period = (period >> 3);
div = 1;
while (period&0xFFFF0000){
period = (period >> 2);
div++;
if(div > 3){ // If the period is too long, 0 is returned.
return 0;
}
}
}
}
T1CTL = ((T1CTL&~0x0c) | (div << 2)); // Setting prescaler division value
T1CC0L = (byte)(period); // Setting counter value
T1CC0H = (byte)(period >> 8);
return (word)period;
}
//----------------------------------------------------------------------------
// 定时器1初始化
//----------------------------------------------------------------------------
void timer1Init(void)
{
TIMER1_INIT();
if(halSetTimer1Period(10000)) // 10ms
{
TIMER1_ENABLE_OVERFLOW_INT(true);
INT_ENABLE(INUM_T1, INT_ON);
TIMER1_RUN(true);
}
}
//------------------------------------------------------
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?