新闻  |   论坛  |   博客  |   在线研讨会
一定要把下面的蔵起来(看CC2430的Timer设置程序)
0750long | 2009-07-15 13:49:27    阅读:2178   发布文章

一定要把下面的蔵起来(看CC2430的Timer设置程序)

 

这几天做的项目用到了CC2430的定时器,于是把hal.h中有声明的有关T3函数看了下,结果是乍一看,还看不懂。所以就慢慢看了看。结果还品出了些味道,那就是不惜一切代价把下层蔵起来。

先看来来函数说明:

/******************************************************************************
* @fn  halSetTimer34Period
*
* @brief
*      This function sets the period of timer 3 or 4 according to the value of
*      _timer_. The two timers are identical. Clock division is used to fit the
*      desired period within the timer range. If the period is too short or too
*      long the function returns 0. If the period is successfully set, the
*      function returns the BYTE value written to the timer register. This
*      value can be used to set the pulse length if the timer is used for PWM.
*      If _period_ is set to 0, maximum timeout value will be used.
*
* Parameters:
*
* @param  BYTE  timer
*         Indicates which timer to configure. Must be either 3 or 4
*         (0x03 or 0x04).
* @param  DWORD  period - Describe value.
*         The desired period in microseconds.
*
* @return BYTE
*         The value written to the TxCC0 register. The timer is incremented up
*         to this value before the timer is reset. This value may be used to
*         set the pulse length in PWM mode.
*
******************************************************************************/

这里说函数的作用的设置T3/4的周期,入参是定时器号,欲设置的周期长度(us);如果period指定的太长或太短,则返回0,如果设置成功则返回写入TxCC0的值 。这里说的是很明白,打开原型一看,原来事情不像想的那么简单(故意说难点吧,就当10.1长假没事写着玩)。只适合新近开始用CC2430的朋友闲来看,其他人等擅自浏览,被雷了别怪emot 。

点击看大图

图一 代码

上面的代码排版不方便。所以就用图了。

点击看大图

图二 时钟分频流程

在平时这么个设置我都是用笔算出DIV的值,再写个InitTimer3()这样的初始化程序,每次写程序,每次都要写InitTimer3(),在看到以上代码后,禁不住自我嘲笑了一回,然后把它整理了贴上来,算是标立一个前车之鉴吧,希望自己能不覆辙。

希望朋友们在以后也能够尽量把底层写得更加通用些,这样方便程序复用。

*博客内容为网友个人发布,仅代表博主个人观点,如有侵权请联系工作人员删除。

参与讨论
登录后参与讨论
推荐文章
最近访客