C delay routine

I need to write a delay routine in C for a 80C251 . The delay has got to be about 30 seconds . Any ideas welcomed.

Parents
  • Hi Iain,

    you really shouldn't wait 30 seconds and let your processor do nothing else than waiting. That is a no-no for embedded applications.

    You should write an interrupt service routine for a timer (i.e. timer 0) that is invoked like every 10ms. The ISR should count down a volatile variable as long as it is not zero. And when you wait in your main loop, you can set that countdown variable at the beginning of your waiting periode and checking it in every loop for being zero. This way, you can determin the end of a waiting periode and do lotsa useful things while waiting.

    Take care
    Sven

Reply
  • Hi Iain,

    you really shouldn't wait 30 seconds and let your processor do nothing else than waiting. That is a no-no for embedded applications.

    You should write an interrupt service routine for a timer (i.e. timer 0) that is invoked like every 10ms. The ISR should count down a volatile variable as long as it is not zero. And when you wait in your main loop, you can set that countdown variable at the beginning of your waiting periode and checking it in every loop for being zero. This way, you can determin the end of a waiting periode and do lotsa useful things while waiting.

    Take care
    Sven

Children
More questions in this forum