<p dir="ltr">There is a lot of useful information in avr-gcc code, once you can see past the peculiarities of C. See the implementation of avr-gcc's delay here: <a href="http://cvs.savannah.gnu.org/viewvc/avr-libc/include/util/delay.h">cvs.savannah.gnu.org/viewvc/avr-libc/include/util/delay.h</a> and delay_basic.h in the same folder. Basically they use op codes with fixed cpu cycles to construct the inside of the loop and use compile time constants to calculate the number of iterations required for a delay. The focus of the code is to get accurate delays down to a few cpu cycles. </p>