I am using the following code for Time Delays when programming the Pic 16F690. However, I am not totally understanding how it works to provide the time delay. Can anyone of you be so kind and explain it to me in detail how it works?
// Using Internal Clock of 8 Mhz
#define FOSC 8000000L
// Delay Function
#define _delay_us(x) { unsigned char us; \
us = (x)/(12000000/FOSC)|1; \
while(--us != 0) continue; }
void _delay_ms(unsigned int ms)
{
unsigned char i;
do {
i = 4;
do {
_delay_us(164);
} while(--i);
} while(--ms);
}
void main(void)
{
//Other code written here
_delay_ms(10);
//Other code written here
}
If possible is there a way to modify such code to provide time delays in micro seconds. Thank you
// Using Internal Clock of 8 Mhz
#define FOSC 8000000L
// Delay Function
#define _delay_us(x) { unsigned char us; \
us = (x)/(12000000/FOSC)|1; \
while(--us != 0) continue; }
void _delay_ms(unsigned int ms)
{
unsigned char i;
do {
i = 4;
do {
_delay_us(164);
} while(--i);
} while(--ms);
}
void main(void)
{
//Other code written here
_delay_ms(10);
//Other code written here
}
If possible is there a way to modify such code to provide time delays in micro seconds. Thank you