These are the delay subroutines i use in my PIC projects. It was written for the PIC16 family but should be compatible with the 18F instruction set as well.

The simplest way to produce delay is to write a subroutine that waste instructions cycles for the desired amount of time. This method should not be used for application that require a high level of precision since the delay subroutine may be halted by interrupts. The delay is offset by the time it takes to execute the interrupt service routine. For short delays however, this should not be a problem.

Continue reading..