There is a built in function in xc8 called __delay_ms() that allows you to achieve an accurate delay.
My problem is that you can only put in a constant value like __delay_ms(1000) for 1 second. MPLAB gives the error
"inline delay argument must be constant"
I want to be able to put a variable in that depends on the users required delay from a PC GUI and EUSART RX.
I have tried using a const int but that doesn't work.
Has anyone any ideas on how to do this? maybe a way to manipulate the function somehow?
UPDATE - I have found the built-in delay routine in XC8's pic.h header file.
The code is:
/****************************************************************/
/* Built-in delay routine */
/****************************************************************/
#pragma intrinsic(_delay)
extern __nonreentrant void _delay(unsigned long);
#pragma intrinsic(_delaywdt)
extern __nonreentrant void _delaywdt(unsigned long);
#if defined(_PIC14E)
#pragma intrinsic(_delay3)
extern __nonreentrant void _delay3(unsigned char);
#endif
// NOTE: To use the macros below, YOU must have previously defined _XTAL_FREQ
#define __delay_us(x) _delay((unsigned long)((x)*(_XTAL_FREQ/4000000.0)))
#define __delay_ms(x) _delay((unsigned long)((x)*(_XTAL_FREQ/4000.0)))
#endif
I'm assuming that somewhere in another XC8 header file, x has been programmed to only accept a constant number i.e 1000 but can't accept a const int.
Does anyone have any ideas on this?