I found this on an old sparkfun website. It definately helped.
Code: Select all/*
7/23/02
Nathan Seidle
nathan.seidle@colorado.edu
Delays for... Well, everything.
11-11 Updated the delays - now they actually delay what they say they should.
10-11-03 Updated delays. New CC5X compiler is muy optimized.
*/
//Really short delay
void delay_us(uns16 x)
{
#ifdef Clock_4MHz
//Calling with 10us returns 69us
for ( ; x > 0 ; x--);
#endif
#ifdef Clock_8MHz
//Calling with 1us returns 11us
//Calling with 10us returns 56us
//for ( ; x > 0 ; x--);
//Calling with 1us returns 7.5us
//Calling with 10us returns 48
//Calling with 1000us returns 4.5ms
while(--x);
//while(x--);
#endif
#ifdef HS_Osc
//Calling with 10us returns 13 us
//Calling with 1us returns 1.8us
while(--x) nop();
#endif
}
//General short delay
void delay_ms(uns16 x)
{
#ifdef Clock_4MHz
//Clocks out at 1002us per 1ms
int y;
for ( ; x > 0 ; x--)
for ( y = 0 ; y < 108 ; y++);
#endif
#ifdef Clock_8MHz
//Clocks out at 1006us per 1ms
uns8 y, z;
for ( ; x > 0 ; x--)
for ( y = 0 ; y < 4 ; y++)
for ( z = 0 ; z < 69 ; z++);
#endif
#ifdef HS_Osc
uns8 y, z;
//Clocks out to 1.00ms per 1ms
//9.99 ms per 10ms
for ( ; x > 0 ; x--)
for ( y = 0 ; y < 4 ; y++)
for ( z = 0 ; z < 176 ; z++);
#endif
}
43
//Delays in 31.25kHz Low Power mode using the internal 31.25kHz oscillator
void delay_s_lp(uns16 x)
{
uns16 y;
//Clocks out to 1.001s per 1s
for ( ; x > 0 ; x--)
for ( y = 0 ; y < 775 ; y++);