Reputation: 169
Im using microchip studio How can I define F_CPU in main.c file and make all files "see" this definition?
I declared in main.c:
#include <avr/io.h>
#include "UART.h"
#define F_CPU 12000000
and in UART.c I tried using this definition :
ubrr_value = (F_CPU/(2*BAUD_RATE))-1;
i recieved this error:
Severity Code Description Project File Line
Error 'F_CPU' undeclared (first use in this function) UART_TEST XX\UART_TEST\UART_TEST\UART.c 55
Upvotes: 2
Views: 312
Reputation: 141768
How can I define F_CPU in main.c file and make all files "see" this definition?
You can't.
You can define F_CPU
in your compiler command line arguments. For example gcc compiler takes -DF_CPU=12000000
. And compile all your sources with that definition.
You can refactor your code, and put F_CPU
into separate file and include it from all files that need it.
// config.h
#deifne F_CPU 12000000
// main.c
#include "config.h"
// uart.c
#include "config.h"
...
ubrr_value = (F_CPU/(2*BAUD_RATE))-1;
...
Upvotes: 1