trying to solve this problem, I reduced my code to a minimum to find errors and check the results of expressions F_CPU
is defined in the main file.
#ifndef USART_H_
#define USART_H_
#include <avr/io.h>
#define USART_BAUDRATE 4800
#define USART_BSCALE -3
#if USART_BSCALE < 0
#define USART_BSEL ((F_CPU / 16) * (1<<(-1*USART_BSCALE)) / USART_BAUDRATE - (1<<(-1*USART_BSCALE)))
#if (USART_BSEL < 0)
#pragma message "BSEL < 0"
#elif (USART_BSEL == 0)
#pragma message "BSEL = 0"
#elif (USART_BSEL > 0)
#pragma message "BSEL > 0"
#endif
#endif
#endif
The result of USART_BSEL
- calculating with integers only - is 3325. The output is this:
#pragma message: BSEL > 0
#pragma message: BSEL < 0
How can I get more than one message from this code? And how can they be different?
The output is always two lines, but depending on my use of integer suffixes for BAUDRATE
and F_CPU
(I used L, UL and ULL), I get different pragma messages. Why is the preprocessor behaving that way?