Hitachi HD44780 display controller
Controlled by PCF8574 I2C interface
Macros | Functions
hd44780.h File Reference

hd44780.h Header file for the Hitachi LCD display driver Copyright U. Raich Jan. 2017 This program is part of a course on embedded systems held at the University of Cape Coast, Ghana in 2017 It is released under the GNU Public License For details please see https://www.gnu.org/licenses/gpl.html More...

#include <stdio.h>
#include <pigpiod_if2.h>
#include <errno.h>
#include <unistd.h>
#include <stdbool.h>
#include <string.h>
Include dependency graph for hd44780.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define I2C_BUS   1
 
#define I2C_FLAGS   0
 
#define HD44780_ADDRESS   0x3f
 
#define HD44780_CLEAR   0x01
 
#define HD44780_HOME   0x02
 
#define HD44780_ENTRY_MODE   0x04
 
#define HD44780_CURSOR_DIR   0x02
 
#define HD44780_CURSOR_SHIFT   0x10
 
#define HD44780_DISPLAY_CURSOR   0x08
 
#define HD44780_DISPLAY_ON   0x04
 
#define HD44780_DISPLAY_OFF   0x00
 
#define HD44780_CURSOR_ON   0x02
 
#define HD44780_CURSOR_OFF   0x00
 
#define HD44780_CURSOR_BLINK   0x01
 
#define HD44780_CURSOR_NOBLINK   0x00
 
#define HD44780_ENTIRE_DISPLAY   0x04
 
#define HD44780_CURSOR_ONOFF   0x02
 
#define HD44780_BLINK   0x01
 
#define HD44780_CURSOR   0x10
 
#define HD44780_1_LINE   0x00
 
#define DH44780_CURSOR_MOVE   0x00
 
#define DH44780_DISPLAY_SHIFT   0x08
 
#define DH44780_SHIFT_LEFT   0x00
 
#define DH44780_SHIFT_RIGHT   0x04
 
#define HD44780_FUNCTION   0x20
 
#define HD44789_8_BIT_MODE   0x10
 
#define HD44780_4_BIT_MODE   0x00
 
#define HD44780_TWO_LINES   0x08
 
#define HD44780_5x10_FONT   0x04
 
#define HD44780_5x8_FONT   0x00
 
#define HD44780_1_LINE   0x00
 
#define HD44780_2_LINE   0x08
 
#define HD44780_CURSOR_DEC   0x00
 
#define HD44780_CURSOR_INC   0x02
 
#define HD44780_DISPLAY_SHIFT   0x01
 
#define HD44780_CGRAM_AHDR   0x10
 
#define HD44780_HDRAM_AHDR   0x20
 
#define HD44780_BUSY_FLAG   0x40
 
#define HD44780_BL   0x08
 
#define HD44780_EN   0x04
 
#define HD44780_READ   0x02
 
#define HD44780_WRITE   0x00
 
#define HD44780_CMD_REG   0x00
 
#define HD44780_DATA_REG   0x01
 
#define HD44780_SET_DDRAM   0x80
 
#define HD44780_SET_CGRAM   0x40
 
#define HD44780_2ND_LINE   0x40
 
#define HD44780_INCREMENT   true
 
#define HD44780_DECREMENT   false
 
#define HD44780_ON   true
 
#define HD44780_OFF   false
 
#define HD44780_SUCCESS   0
 
#define HD44780_MAX_STRLEN   16
 

Functions

void hd44780SetDebug (bool)
 switches debug mode on or off More...
 
int hd44780BackLight (bool)
 switches the display back light on or off More...
 
int hd44780PutC (char)
 Write a character to the display. More...
 
int hd44780GetC (char *)
 Read a character from the display. More...
 
int hd44780ReadBusy (bool *, unsigned char *)
 Reads the busy flag and the DDRAM address. More...
 
int hd44780PutS (char *)
 Writes a zero terminated character string to the display Not more than 16 characters are written it no zero is found. More...
 
int hd44780Home (void)
 Sets the DDRAM address to zero such that the next character is written to the top left position if the LED screen. If the display is shifted it is set back to the original position. More...
 
int hd44780Clear (void)
 Clears the display. More...
 
int hd44780Cursor (bool, bool)
 Sets the DDRAM address to zero such that the next character is written to the top left position if the LED screen. If the display is shifted it is set back to the original position. More...
 
int hd44780EntryMode (bool, bool)
 Defines if the address counter counts up or down
and sets shifting the whole display on or off. More...
 
int hd44780SetDDRamAddr (unsigned char)
 Sets the DDRAM address. More...
 
int hd44780SecondLine (void)
 Sets the DDRAM address to the beginning of the second line. More...
 
int hd44780CreateChar (unsigned char, unsigned char *)
 hd44780CreateChar: creates a character in the character generator RAM (CGRAM) More...
 
int hd44780Open (void)
 hd44770Open: initializes the pigpio library opens the I2C connection to the pcf8574 which is on the I2C address 0x3f More...
 
void hd44780Close (void)
 hd44770Close: closes the I2C connection to the pcf8574 and disconnects from the pigpio library More...
 

Detailed Description

hd44780.h Header file for the Hitachi LCD display driver Copyright U. Raich Jan. 2017 This program is part of a course on embedded systems held at the University of Cape Coast, Ghana in 2017 It is released under the GNU Public License For details please see https://www.gnu.org/licenses/gpl.html

Function Documentation

◆ hd44780BackLight()

int hd44780BackLight ( bool  onOff)

switches the display back light on or off

Parameters
onOfftrue: switches debug mode on
false: switches debug mode off
Returns
result from the call to the pigpio library
Return values
HD44780_SUCCESS-> success
negativeerror code from the pigpio library

◆ hd44780Clear()

int hd44780Clear ( void  )

Clears the display.

Returns
result from the call to the hd44780WriteCmd function
Return values
HD44780_SUCCESS-> success
negativeerror code from the hd44780WriteCmd function

◆ hd44780Close()

void hd44780Close ( void  )

hd44770Close: closes the I2C connection to the pcf8574 and disconnects from the pigpio library

◆ hd44780CreateChar()

int hd44780CreateChar ( unsigned char  cgramAddr,
unsigned char *  dotMatrix 
)

hd44780CreateChar: creates a character in the character generator RAM (CGRAM)

Parameters
addressthe address in the CGRAM where to write the character must be on a 8 byte boundary
characterthe dot matrix consisting of 7 bytes
Return values
HD44780_SUCCESS-> success
negativeerror code from the hd44780putC function

◆ hd44780Cursor()

int hd44780Cursor ( bool  onOff,
bool  blink 
)

Sets the DDRAM address to zero such that the next character is written to the top left position if the LED screen. If the display is shifted it is set back to the original position.

Returns
result from the call to the hd44780WriteCmd function
Return values
HD44780_SUCCESS-> success
negativeerror code from the hd44780WriteCmd function

◆ hd44780EntryMode()

int hd44780EntryMode ( bool  incDec,
bool  shift 
)

Defines if the address counter counts up or down
and sets shifting the whole display on or off.

Parameters
incDecfalse: the address counter is decremented when a character is written
true: it is incremented
shiftfalse: display shifts are switched off
true: they are switched on
Returns
result from the call to the hd44780WriteCmd function
Return values
HD44780_SUCCESS-> success
negativeerror code from the hd44780WriteCmd function

◆ hd44780GetC()

int hd44780GetC ( char *  c)

Read a character from the display.

Parameters
cpointer to the character read from the display controller
Returns
result from the call to the hd44780Read function
Return values
HD44780_SUCCESS-> success
negativeerror code from the hd44780Read function

◆ hd44780Home()

int hd44780Home ( void  )

Sets the DDRAM address to zero such that the next character is written to the top left position if the LED screen. If the display is shifted it is set back to the original position.

Returns
result from the call to the hd44780WriteCmd function
Return values
HD44780_SUCCESS-> success
negativeerror code from the hd44780WriteCmd function

◆ hd44780Open()

int hd44780Open ( void  )

hd44770Open: initializes the pigpio library opens the I2C connection to the pcf8574 which is on the I2C address 0x3f

Returns
result from the call to the pigpio library
Return values
HD44780_SUCCESS-> success
negativeerror code from the pigpio library

◆ hd44780PutC()

int hd44780PutC ( char  c)

Write a character to the display.

Parameters
cthe character to be written
Returns
result from the call to the hd44780WriteCmd function
Return values
HD44780_SUCCESS-> success
negativeerror code from the hd44780WriteCmd function

◆ hd44780PutS()

int hd44780PutS ( char *  text)

Writes a zero terminated character string to the display Not more than 16 characters are written it no zero is found.

Parameters
textthe zero terminated C character string
Returns
result from the call to the hd44780PutC function
Return values
HD44780_SUCCESS-> success
negativeerror code from the hd44780PutC function

◆ hd44780ReadBusy()

int hd44780ReadBusy ( bool *  busy,
unsigned char *  address 
)

Reads the busy flag and the DDRAM address.

Parameters
*busya pointer to a boolean into which the busy flag will be written
*addressa pointer to an unsigned char into which the DDRAM address will be written
Returns
result from the call to the hd44780Read function
Return values
HD44780_SUCCESS-> success
negativeerror code from the hd44780Read function

◆ hd44780SecondLine()

int hd44780SecondLine ( void  )

Sets the DDRAM address to the beginning of the second line.

Returns
result from the call to hd44780SetDDRamAddr()

◆ hd44780SetDDRamAddr()

int hd44780SetDDRamAddr ( unsigned char  addr)

Sets the DDRAM address.

Parameters
addrthe DDRAM address to which the next character will be written or read from
Returns
result from the call to the hd44780WriteCmd function
Return values
HD44780_SUCCESS-> success
negativeerror code from the hd44780WriteCmd function

◆ hd44780SetDebug()

void hd44780SetDebug ( bool  onOff)

switches debug mode on or off

pinout for 20x2 LCD via PCF8574AN:

0x80 P7 - - D7 0x40 P6 - - D6 0x20 P5 - - D5

0x10 P4 - - D4

0x08 P3 - - BL Backlight (LCD has 3 RGB LEDs - common anode) 0x04 P2 - - EN Starts Data read/write 0x02 P1 - - RW low: write, high: read 0x01 P0 - - RS Register Select: 0: Instruction Register (IR) (AC when read), 1: data register (DR)

Parameters
onOfftrue: switches debug mode on
false: switches debug mode off