0

我正在学习在我的 Silicon Laboratories C8051F020 toolstick 子卡包上使用中断。我想在指定的时间内运行中断。谁能给我一个例子或指出我正确的方向?或者,如果有办法在 x 秒内运行一个函数?

4

1 回答 1

0

You can run a "for" loop for a specified number of time. You know the speed of you CPU, thus you can compute the time required to run a single instruction. And then you can know the number of loop you have to do in your for loop. Just make sure that you compiler doesn't optimize your loop.... by removing it ! But, I don't understand why you want to do that. Usually interrupts should run for the smallest amount of time. I never saw any need for loosing cycles in a ISR. (except small "waits" of some cycles for some external sychro). If you need to wait for a long time, use a timer that will call its own ISR upon overflows when the time is elapsed.

Or if you want to run an interrupt that runs every xxx secondes, you should not actively wait, But use a timer instead. Configure a timer that overflows every xxx seconds and put your code in its ISR. Once the timer and IRQ are enabled, your ISR will run every xxx seconds

于 2012-10-16T05:33:12.827 回答