for AVR atmega8cpu clock :8M-----------------------------------------------------------------------*/#include "delay.h"void delay_1us(void) //1us delay { asm("nop"); }void delay_nus(unsigned int n) //N us delay { unsigned int i=0; for (i=0;i<n;i++) delay_1us(); } void delay_1ms(void) //1ms delay { unsigned int i; for (i=0;i<1140;i++); } void delay_nms(unsigned int n) //N ms delay { unsigned int i=0; for (i=0;i<n;i++) delay_1ms(); }
The interesting point about the routine is its ability to allow for different bus rates by simply setting the value in ACC - and this consumes a total of only 10 bytes. The maximum possible delay is a little over 3 ms.
Regards,
Mac