Search code examples
cembeddedavr

Empty loop meaning in a timer code using C


void Tmr_Wait1us (uint16_t delay) {
    uint16_t i;
    TCNT0 = 0;      // will start to count from 0 up to 255 (if 8-bit timer)
    for (i = 0; i < delay / 256; i++)
        while (TCNT0 < 255)         
            ;   
    while (TCNT0 <= delay % 256)
        ;
}

This code is used to set a timer to wait precise amount of time, to be applied to AVR-Atmega32a , I can't understand what the empty loops does here? also what the second loop does?


Solution

  • They look like busy waits. They block until the condition is met.