|
发表于 2010-9-29 17:52:01
|
显示全部楼层
the following hopefully will help you all understand the issue here.
this is a shot of single stepping through an AVR timer interrupt service routine. I stop'd the code right after it entered the isr, before executing the first statement.
on the right, I was showing the value of the timer / counter, TCNT0. The timer here works similar to the C51 timer: once TCNT0 hits a pre-set value (100 here and 0x100 in the case of a C51 8-bit timer), it rolls over and fires an interrupt.
so TCNT0 was just reset and that triggered the interrupt.
because of latency and context saving, by the time we are to execute the very 1st user code in the isr, the timer has advanced from 0x00 to 0x19.
if you ignore the value of the timer / counter at this point, by writing an explicit value to it, you would have created timing errors.
instead, you should simply increment or decrement the timer, as suggested earlier.
![](http://cache.amobbs.com/bbs_upload782111/files_33/ourdev_586637JYL351.PNG)
(原文件名:avr tmr isr.PNG) |
|