Home › Forums › Microcontrollers › PIC Microcontroller › Microsecond variable Delay in MikroC › Reply To: Microsecond variable Delay in MikroC
June 5, 2015 at 1:57 pm
#11456
Keymaster
Hi, the following variable microsecond delay functions will work with enough accuracy if you use clock 20MHz or more.
For PIC 16F
void Vdelay_us(unsigned time_us)
{
unsigned ncyc;
ncyc = Clock_MHz()>>2;
ncyc *= time_us>>4;
while (ncyc--)
{
asm nop;
asm nop;
}
}
For PIC 18F
void Vdelay_us(unsigned time_us)
{
unsigned ncyc;
ncyc = Clock_MHz()>>2;
ncyc *= time_us>>4;
while (ncyc--)
{
asm nop;
asm nop;
asm nop;
}
}
