Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ATMEGA168A - F_CPU warning

Tags:

c

avr

atmega

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?

like image 716
Kaguei Nakueka Avatar asked Feb 08 '23 06:02

Kaguei Nakueka


1 Answers

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

like image 161
donjuedo Avatar answered Feb 13 '23 02:02

donjuedo