请教一下:设置了定时器中断,但想中断程序之外,即另一个子程序中改写定时器的计数值(非初始值,是当前值),从而使定时器从新的计数值往下递减,该怎样实现?
xyz549040622:
1.另一个子程序最好还是放在中断中判断
2.如果非要写的话,在修改定时器计数值的时候停止定时器中断,修改后恢复中断。
jun wang15:
回复 xyz549040622:
谢谢您的回答,很有参考价值。请问改写计数器的值是用这个语句:HWREG(TIMER0_BASE + TIMER_O_TAV) = ****吗?
xyz549040622:
回复 jun wang15:
这样也可以。这是直接操作底层的地址了,建议你用库函数试试,这么搞,容易搞乱。
kqian0327:
回复 jun wang15:
你好,
关于如何改写定时器的计算timer你可以参考API驱动库,不要直接操作底层计算器。
API文档见SDK目录下C:\ti\TivaWare_C_Series-2.1.0.12573\docs
SW-TM4C-DRL-UG-2.1.0.12573.pdf
第550页:
TimerLoadSetSets the timer load value.Prototype:voidTimerLoadSet(uint32_t ui32Base,uint32_t ui32Timer,uint32_t ui32Value)February 07, 2014 549TimerParameters:ui32Base is the base address of the timer module.ui32Timer specifies the timer(s) to adjust; must be one of TIMER_A, TIMER_B, orTIMER_BOTH. Only TIMER_A should be used when the timer is configured for full-widthoperation.ui32Value is the load value.Description:This function configures the timer load value; if the timer is running then the value is immediatelyloaded into the timer.Note:This function can be used for both full- and half-width modes of 16/32-bit timers and for halfwidthmodes of 32/64-bit timers. Use TimerLoadSet64() for full-width modes of 32/64-bit timers.Returns:None.