Take the 2-minute tour ×

I am learning to use interrupts on my Silicon Laboratories C8051F020 toolstick daughter card package. I would like to run an interrupt for a specified amount of time. Can anyone give me an example or point me in the right direction? Or if there is a way to run a function for x amount of seconds?

share|improve this question

1 Answer 1

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

share|improve this answer
After a little studying I realize I asked the wrong question. However, you mentioned a timer. The proper is question here: stackoverflow.com/questions/12929226/…. I would appreciate your input. –  arynhard Oct 17 '12 at 7:38

Your Answer


