\$\begingroup\$
\$\endgroup\$
1
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!!");
}
-
\$\begingroup\$ Modifying distribution header files is bad practice. Why not move these lines into your own source code? \$\endgroup\$jippie– jippie2013年04月13日 08:12:28 +00:00Commented Apr 13, 2013 at 8:12
1 Answer 1
\$\begingroup\$
\$\endgroup\$
1
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
-
2\$\begingroup\$ Exactly. The included header is processed before the #define is reached. \$\endgroup\$Passerby– Passerby2013年04月13日 08:31:35 +00:00Commented Apr 13, 2013 at 8:31
lang-c