External pin definitions and Peter Fleury's LCD Library

Go To Last Post
4 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello,

 

Can someone who has successfully implemented external pin definitions (using lcd_definitions.h) for Peter Fleury's LCD library nudge me in the right direction?

 

I have a project where I am attempting to utilize the Peter Fleury LCD library. I have successfully programmed an ATmega328P using this library and want to attempt to use external modifications so I don't need to copy versions of the lcd.c and lcd.h files into each project. Per the header file, this can be done by including a file called lcd_definitions.h and by calling

-D_LCD_DEFINITIONS_FILE

from the Makefile at compile. I believe I properly set all of these up as before the project would simply build with the default pin setup, however when I attempt to build the project with the above setting applied it fails with the error message

 

lcd_definitions.h: No such file or directory

In the attached images, I created and set up my port and pin definitions per the library's instruction and have included both lcd_definitions.h and lcd.h in my main file. Is there a file location I need to be searching for from the library to find the external definitions file?

 

Attachment(s): 

This topic has a solution.
Last Edited: Mon. Jul 30, 2018 - 02:16 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

As supplied the Fleury lib doesn't include a file call lcd_definitions.h:

So you have to write one from scratch. The supplied lcd.h has the conditional include at the top but it's then followed by:
 

#ifndef LCD_PORT
#define LCD_PORT         PORTA        /**< port for the LCD lines   */
#endif
#ifndef LCD_DATA0_PORT
#define LCD_DATA0_PORT   LCD_PORT     /**< port for 4bit data bit 0 */
#endif
#ifndef LCD_DATA1_PORT
#define LCD_DATA1_PORT   LCD_PORT     /**< port for 4bit data bit 1 */
#endif
#ifndef LCD_DATA2_PORT
#define LCD_DATA2_PORT   LCD_PORT     /**< port for 4bit data bit 2 */
#endif
#ifndef LCD_DATA3_PORT
#define LCD_DATA3_PORT   LCD_PORT     /**< port for 4bit data bit 3 */
#endif
#ifndef LCD_DATA0_PIN
#define LCD_DATA0_PIN    0            /**< pin for 4bit data bit 0  */
#endif
#ifndef LCD_DATA1_PIN
#define LCD_DATA1_PIN    1            /**< pin for 4bit data bit 1  */
#endif
etc.

it's doing all those #ifndef tests because it doesn't know if you have an lcd_definitions.h or not. So in a newly created lcd_definitions.h you need to use something like:
 

#define LCD_PORT         PORTA        /**< port for the LCD lines   */
#define LCD_DATA0_PORT   LCD_PORT     /**< port for 4bit data bit 0 */
#define LCD_DATA1_PORT   LCD_PORT     /**< port for 4bit data bit 1 */
#define LCD_DATA2_PORT   LCD_PORT     /**< port for 4bit data bit 2 */
#define LCD_DATA3_PORT   LCD_PORT     /**< port for 4bit data bit 3 */
#define LCD_DATA0_PIN    0            /**< pin for 4bit data bit 0  */
#define LCD_DATA1_PIN    1            /**< pin for 4bit data bit 1  */
etc.

then those will be used in preference to the ones in lcd.h

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson,

 

Thank you for your response. I have created the file and it is currently located in my project folder (as this would make the most sense for use of external definitions). Does it need to be located in the library folder instead? If so is there a way to make it truly external by having the library reference a file located in the project folder instead of the library itself?

 

 

Thanks!

This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

#include follows a defined search order. The first place that is searched is the same directory as the file with the #include. So I'd suggest you want it close to the lcd.h that is trying to include it.

 

HOWEVER I understand this is for per-project configuration and you want different ones in different places. So I suggest you add a "-I ." to the compiler invocation so that the directory where the .c file that includes the first .h file is searched.