ATMEGA168A - F_CPU warning
Solution 1
You need to define F_CPU
before that inclusion. You could do it on the command line when compiling, or put it in your source. You defining this symbol is you letting the build system know how fast your particular CPU is running. (I.e., you don't get to change the actual speed this way).
For a discussion, see http://www.avrfreaks.net/forum/understanding-fcpu
Solution 2
The scope of a macro definition is from its #define
directive to the end of the source file or a corresponding #undef
.
The value of F_CPU
is tested in the util/delay.h
header. But when that test happens, your #define F_CPU
has not yet been processed.
You can either move it before #include <util/delay>
or define that macro using a compiler option. The latter would be my choice. Then you have to change only one item in the build (Makefile, project settings, ...).
Comments
-
Kaguei Nakueka almost 2 years
I have written the code below in order to make an ATMEGA168A blink a small led:
#include <avr/io.h> #include <util/delay.h> #define F_CPU 1000000UL int main(void) { DDRB = 0b00000010; PORTB = 0b00000000; while(1) { PORTB ^= 1 << 1; _delay_ms(1000); } }
The compiler is giving me a warning as follows:
Warning #warning "F_CPU not defined for <util/delay.h>"
Here is where this warning comes from (delay.h)
#ifndef F_CPU /* prevent compiler error by supplying a default */ # warning "F_CPU not defined for <util/delay.h>" # define F_CPU 1000000UL #endif
What am I doing wrong here? Is my declaration incorrect?
-
R1S8K over 5 yearsI did it before the inclusion and still get the warning!