I am trying to organise my UART library and prettify it a little bit by adding some #define s so I can customize it later without having to dig deeply into the code, but I can't seem to get the following bit of code working:
#define FOSC 8000000
#define BAUDRATE 9600
#define BRGVAL (FOSC/2)/(16*BAUDRATE)-1
void uart_init(){
U1BRG = BRGVAL;
}
After the calculation BRGVAL becomes 25.0416667, and because it is not an integer I get the following warning for it when I assign that into U1BRG:
UART.c: In function 'uart_init':
UART.c:24: warning: integer overflow in expression
...and the code simply does not work on target hardware. (If I manually put in U1BRG = 25 it works like a charm though)
Is there any way to typecast that constant into an integer to make the compiler happy?
Many Thanks, Hamza.