Search code examples
cxc8attiny

XC8 compiler does not recognize __delay macros


I want to program a ATtiny85 microcontroller and have realized that my program needs a bit of delay to work properly. I am using MPLabX and the XC8 compiler. So I should be able to use the __delay_ms() macro and MPLab does recognize the macro and does NOT put the red line under the code. However when I try to compile the programm, there is an error thrown at each line where I use the macro. "Undefined reference to __delay_ms" And also an additional "implicit declaration of __delay_ms" for the first line that uses the macro. I do have _XTAL_FREQ defined correctly and xc.h included.

The code also compiles just fine without the delay macros, but than it doesn't work correctly, so I need the delay.

I don't know what the problem is. I have programmed other microcontrollers with the __delay_ms macro before. I am also using the latest version of the XC8 compiler. And according to the documentation of the compiler the version is fully compatible with the ATtiny85.

I also tried to find a solution on the internet, but didn't find anything that helped with my problem...

Any ideas where the problem could be?


Solution

  • So I did some more digging in the include directories for xc8 and I found something. If I include util/delay.h I can use the functions, but only using one underscore instead of two. So the command has to be _delay_ms(). Then I can compile the code, but it is missing a definition for F_CPU. This however only results in a warning and not an error. I will try to find out where F_CPU is defined. I am guessing it is defined relative to _XTAL_FREQ somewhere...

    I will keep you updated on what I can find out.