cavravr-gccwinavravr-studio4

How to flash error if a macro not defined?


I want my program to flash compile time error like "LCD_PORT not defined" if it is not defined in program itself. For that I modified the header file like this

.
.
.
#if LCD_IO_MODE
#ifndef LCD_PORT
#error LCD_PORT not defined //(e.g. #define LCD_PORT PORTA/B/C/D)
#endif

#define LCD_DATA0_PORT   LCD_PORT     /**< port for 4bit data bit 0 */
#define LCD_DATA1_PORT   LCD_PORT     /**< port for 4bit data bit 1 */
.
.
.
...

But even after defining the LCD_PORT (like in the following program), it flashes the error.

#include <avr/io.h>
#include <lcd.h>

#define LCD_PORT PORTA

int main(void)
{
    lcd_init(LCD_DISP_ON_CURSOR); 
    lcd_home();
    lcd_puts("Hello world!!");
}

Solution

  • Because you define the macro only after including the header file. What you need is this:

    #define LCD_PORT PORTA
    
    #include <lcd.h>