免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 895 | 回复: 0
打印 上一主题 下一主题

cc2430 timer()设置 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-01-24 11:29 |只看该作者 |倒序浏览

这几天做的项目用到了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(),在看到以上代码后,禁不住自我嘲笑了一回,然后把它整理了贴上来,算是标立一个前车之鉴吧,希望自己能不覆辙。
希望朋友们在以后也能够尽量把底层写得更加通用些,这样方便程序复用。
末了,祝大家国庆快乐。


本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u2/73801/showart_1807630.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP