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!!");
}
asked Apr 13, 2013 at 7:45
\$\endgroup\$
1
  • \$\begingroup\$ Modifying distribution header files is bad practice. Why not move these lines into your own source code? \$\endgroup\$ Commented 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>
answered Apr 13, 2013 at 8:23
\$\endgroup\$
1
  • 2
    \$\begingroup\$ Exactly. The included header is processed before the #define is reached. \$\endgroup\$ Commented Apr 13, 2013 at 8:31

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.