1
\$\begingroup\$

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_gotoxy(0,4);
    lcd_puts("Hello world!!");
}
\$\endgroup\$
1
  • \$\begingroup\$ Modifying distribution header files is bad practice. Why not move these lines into your own source code? \$\endgroup\$
    – jippie
    Apr 13, 2013 at 8:12

1 Answer 1

3
\$\begingroup\$

The problem is likely to be that the preprocessor operates sequentially so you should perform the define before the include. Try the following:

#include <avr/io.h>
#define LCD_PORT PORTA
#include <lcd.h>
\$\endgroup\$
1
  • 2
    \$\begingroup\$ Exactly. The included header is processed before the #define is reached. \$\endgroup\$
    – Passerby
    Apr 13, 2013 at 8:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.