HD44780 LCD Display in C++


Control of a HD44780 LCD display is made complex by the fact that it is done in 4 bit mode.  The I2C interface is an 8 bit one but the LCD display has control bits in addition to the 8 bit data.  The solution is to put the device in 4 bit mode.  The control bits occupy the 4 least significant bits and the character/command data is in the 4 most significant bits.

Although documentation on the I2C interface and the LCD control chips were relatively easy to find, the wiring between the parts was no where to be found.  Enter the document "Control a HD44780 LCD display via I2C with the Raspberry Pi" at https://tutorials-raspberrypi.com/control-a-raspberry-pi-hd44780-lcd-display-via-i2c/.  This did not document the interface directly but provided working Python code.

My first step was to test the code itself.  It worked flawlessly so I proceeded to use it as a template for my C++ code.

I created the I2C.h file to wrap the wiringPiI2C* calls in a C++ class to clean up the calling code.  All the code is in the header with no corresponding cpp file.  This should allow little overhead in using the class since the optimizer has all the code at once and can inline it.  LCD.h and LCD.cpp provides the code to initialize and operate the display.  As I stated, it relies heavily on the Python code.  Finally, the LCD_Example.cpp is a simple example to test the operation of the code.

Feel free to use this code as needed, although a reference would be nice.  A reference to the author of the tutorials-raspberrypi.com article would be nice too, but I was unable to discern it.

Here is the code:

LCD_Example.zip

-Jack Bonn