Thanks for the quick reply it has helped me understand how XC8 is handling the delays etc.
_XTAL_FREQ should be set to Fosc, so:
#define _XTAL_FREQ (48000000ULL)
On the PIC18F series, the __delay_ms macro is limited to a delay of 179,200 instruction cycles (just under 15ms @ 48MHz clock).
Well I just did some quick tests with _delay(...) and it seems when running at 48 MHz I can delay upto 197,120 cycles which works out to be approx 16.426 mS and a delay of 1 cycle is approx 83.333 nS, so no 1 nano second delay here :P
But will work fine for some of my projects that use IR Remotes which need to delay as fast as 560uS to detect the logic pulses etc which works out to be 6720 cycles @ 48 MHz so a _delay(6720); + a Nop(); gives me a 560uS delay (some reason it looses 1 cycle) and dont try and use _delay(1792); Should delay for 1792 cycles (149.333 uS) but insted it delays for 2560 cycles (213.333 uS) and a delay of 1793 results in a delay of 1792 cycles, but then again nothing is perfect.
You can just call it a few times in a loop:
for ( int i = 0; i < 10; i++ ) __delay_ms( 10 );
Great in theroy, but you won't get what you was hoping, the above worked ok ish a little bit out, but say I wanted say 560uS for decoding IR Remotes using the following you would think would work:
for (int i=0; i<56; i++) __delay_us(10);
Delays for 10uS 56 times so it should result in 6720 cycles (560 uS), however the for loop also takes cycles which results in 7281 cycles (606.75 uS) and for timing code that would be an issue.
Don't get me wrong using a loop to increase the delay is still a great idea as long as you cater for the amount of cycles each run of the loop takes, from there you can play about with values and adding one or two Nop() here and there works great :)
There shouldn't be any problem using #define _XTAL_FREQ multiple times. Or you could put it in a common header file and include it from your multiple source files.
Also, I think the old C18 delay routines (Delay10TCY, etc) still work with XC8 if you #include <delays.h>.
Yeah, I could have a header file where I store all my defines and include that where its needed, I don't really like having to re-define stuff all over the place due to it causes issues when you need to change them and you forget some.
As for the C18 Delay functions still working in XC8, I wasn't too sure due to MPLAB X highlighting the functions red and greying them out in the header file.
Once again thanks for your reply it has helped me resolve the issue that I was having, I was starting to think maybe it would be better to stay with C18, but now I see how it works I am fine with my choice in moving over to XC8 and also the smaller assembly that it creates :)