Display_Lib_RPI 2.3.0
A C++ Library to connect electronic displays to Linux single board computers.
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
HD44780PCF8574LCD Class Reference

class to drive the HD44780 LCD with PCF8574 I2C interface More...

#include <HD44780_LCD_RDL.hpp>

Inheritance diagram for HD44780PCF8574LCD:
Inheritance graph
[legend]

Public Types

enum  LCDBackLight_e : uint8_t { LCDBackLightOnMask = 0x0F , LCDBackLightOffMask = 0x07 }
 
enum  LCDEntryMode_e : uint8_t { LCDEntryModeOne = 0x04 , LCDEntryModeTwo = 0x05 , LCDEntryModeThree = 0x06 , LCDEntryModeFour = 0x07 }
 
enum  LCDCursorType_e : uint8_t { LCDCursorTypeOff = 0x0C , LCDCursorTypeBlink = 0x0D , LCDCursorTypeOn = 0x0E , LCDCursorTypeOnBlink = 0x0F }
 
enum  LCDDirectionType_e : uint8_t { LCDMoveRight = 1 , LCDMoveLeft = 2 }
 
enum  LCDLineNumber_e : uint8_t { LCDLineNumberOne = 1 , LCDLineNumberTwo = 2 , LCDLineNumberThree = 3 , LCDLineNumberFour = 4 }
 
- Public Types inherited from Print
enum  BaseNum : uint8_t { RDL_DEC = 10 , RDL_HEX = 16 , RDL_OCT = 8 , RDL_BIN = 2 }
 

Public Member Functions

 HD44780PCF8574LCD (uint8_t NumRow, uint8_t NumCol, int I2Cdevice, int I2Caddress, int I2Cflags)
 Constructor for class HD44780PCF8574LCD.
 
void LCDInit (LCDCursorType_e)
 Initialise LCD.
 
void LCDDisplayON (bool)
 Turn Screen on and off.
 
void LCDResetScreen (LCDCursorType_e)
 Reset screen.
 
void LCDBackLightSet (bool)
 Turn LED backlight on and off.
 
bool LCDBackLightGet (void)
 get the backlight flag status
 
rdlib::Return_Codes_e LCD_I2C_ON (void)
 Switch on the I2C.
 
rdlib::Return_Codes_e LCD_I2C_OFF (void)
 End I2C operations.
 
int LCDCheckConnection (void)
 checks if LCD on I2C bus
 
int LCDI2CErrorGet (void)
 get I2C error Flag
 
uint16_t LCDI2CErrorTimeoutGet (void)
 Gets the I2C timeout, used in the event of an I2C write error.
 
void LCDI2CErrorTimeoutSet (uint16_t)
 Sets the I2C timeout, in the event of an I2C write error.
 
uint8_t LCDI2CErrorRetryNumGet (void)
 Gets the I2C error retry attempts, used in the event of an I2C write error.
 
void LCDI2CErrorRetryNumSet (uint8_t)
 Sets the I2C error retry attempts used in the event of an I2C write error.
 
rdlib::Return_Codes_e LCDSendString (char *str)
 Send a string to LCD.
 
void LCDSendChar (char data)
 Sends a character to screen , simply wraps SendData command.
 
virtual size_t write (uint8_t)
 Called by print class, used to print out numerical data types etc.
 
rdlib::Return_Codes_e LCDCreateCustomChar (uint8_t location, uint8_t *charmap)
 Saves a custom character to a location in character generator RAM 64 bytes.
 
void LCDPrintCustomChar (uint8_t location)
 Print out a customer character from character generator CGRAM 64 bytes 8 characters.
 
void LCDMoveCursor (LCDDirectionType_e, uint8_t moveSize)
 Moves cursor.
 
void LCDScroll (LCDDirectionType_e, uint8_t ScrollSize)
 Scrolls screen.
 
void LCDGOTO (LCDLineNumber_e lineNo, uint8_t col)
 moves cursor to an x , y position on display.
 
void LCDClearLine (LCDLineNumber_e lineNo)
 Clear a line by writing spaces to every position.
 
rdlib::Return_Codes_e LCDClearScreen (void)
 Clear screen by writing spaces to every position.
 
void LCDClearScreenCmd (void)
 Clear display using software command , set cursor position to zero.
 
void LCDHome (void)
 Set cursor position to home position .
 
void LCDChangeEntryMode (LCDEntryMode_e mode)
 Change entry mode.
 
- Public Member Functions inherited from Print
int getWriteError ()
 gets the error flag status, zero no error
 
void clearWriteError ()
 clears the error flag by setting it to zero
 
virtual size_t write (const uint8_t *buffer, size_t size)
 define in the sub class
 
size_t write (const char *str)
 Writes a string to the output.
 
size_t write (const char *buffer, size_t size)
 Writes a buffer of a specified size to the output.
 
virtual int availableForWrite ()
 define in the sub class
 
size_t print (const char[])
 print an array
 
size_t print (char)
 print an character
 
size_t print (int, int=RDL_DEC)
 print an integer of base number system
 
size_t print (unsigned int, int=RDL_DEC)
 print an unsigned integer of base number system
 
size_t print (long, int=RDL_DEC)
 print an long integer of base number system
 
size_t print (unsigned long, int=RDL_DEC)
 print an unsigned long integer of base number system
 
size_t print (double, int=2)
 print an double
 
size_t print (const std::string &)
 print an C++ string object
 
size_t println (const char[])
 Prints a character array followed by a newline.
 
size_t println (char)
 print an character followed by new line
 
size_t println (int, int=RDL_DEC)
 print an integer of base number system followed by new line
 
size_t println (unsigned int, int=RDL_DEC)
 print an unsigned integer of base number system followed by new line
 
size_t println (long, int=RDL_DEC)
 print an long integer of base number system followed by new line
 
size_t println (unsigned long, int=RDL_DEC)
 print an unsigned long integer of base number system followed by new line
 
size_t println (double, int=2)
 print an double
 
size_t println (void)
 Goto to new line.
 
size_t println (const std::string &s)
 print an C++ string object followed by new line
 
template<typename T >
size_t print (const std::vector< T > &v, int format=defaultFormat< T >())
 Print a vector of any type.
 
template<typename T >
size_t println (const std::vector< T > &vec, int format=defaultFormat< T >())
 Print a vector of elements followed by a newline.
 
template<typename T , size_t N>
size_t print (const std::array< T, N > &arr, int format=defaultFormat< T >())
 Print a std::array of any type.
 
template<typename T , size_t N>
size_t println (const std::array< T, N > &arr, int format=defaultFormat< T >())
 Print a std::array of elements followed by a newline.
 

Private Types

enum  LCDAddress_e : uint8_t {
  LCDLineAddressOne = 0x80 , LCDLineAddressTwo = 0xC0 , LCDLineAddress3Col20 = 0x94 , LCDLineAddress4Col20 = 0xD4 ,
  LCDLineAddress3Col16 = 0x90 , LCDLineAddress4Col16 = 0xD0
}
 
enum  LCDCmdBytesGeneral_e : uint8_t {
  LCDCmdModeFourBit = 0x28 , LCDCmdHomePosition = 0x02 , LCDCmdDisplayOn = 0x0C , LCDCmdDisplayOff = 0x08 ,
  LCDCmdClearScreen = 0x01
}
 

Private Member Functions

void LCDSendCmd (unsigned char cmd)
 Send command byte to lcd.
 
void LCDSendData (unsigned char data)
 Send data byte to LCD via I2C.
 

Private Attributes

enum LCDBackLight_e _LCDBackLight = LCDBackLightOnMask
 
int _LCDI2CAddress = 0x27
 
int _LCDI2CDevice = 1
 
int _LCDI2CFlags = 0
 
int _LCDI2CHandle = 0
 
uint16_t _I2C_ErrorDelay = 100
 
uint8_t _I2C_ErrorRetryNum = 3
 
int _I2C_ErrorFlag = 0
 
uint8_t _NumRowsLCD = 2
 
uint8_t _NumColsLCD = 16
 

Additional Inherited Members

- Protected Member Functions inherited from Print
void setWriteError (int err=0)
 

Detailed Description

class to drive the HD44780 LCD with PCF8574 I2C interface

Member Enumeration Documentation

◆ LCDAddress_e

DDRAM address's used to set cursor position Note Private

Enumerator
LCDLineAddressOne 

Line 1

LCDLineAddressTwo 

Line 2

LCDLineAddress3Col20 

Line 3 20x04 line 3

LCDLineAddress4Col20 

Line 4 20x04 line 4

LCDLineAddress3Col16 

Line 3 16x04 untested, no part

LCDLineAddress4Col16 

Line 4 16x04 untested, no part

◆ LCDBackLight_e

Backlight Control , Command Byte Code

Enumerator
LCDBackLightOnMask 

XXXX-1111 , Turn on Back light

LCDBackLightOffMask 

XXXX-0111, Turn off Back light

◆ LCDCmdBytesGeneral_e

Command Bytes General Note Private

Enumerator
LCDCmdModeFourBit 

Function set (4-bit interface, 2 lines, 5*7 Pixels)

LCDCmdHomePosition 

Home (move cursor to top/left character position)

LCDCmdDisplayOn 

Restore the display (with cursor hidden)

LCDCmdDisplayOff 

Blank the display (without clearing)

LCDCmdClearScreen 

clear screen command byte

◆ LCDCursorType_e

Cursor mode, Command Byte Code

Enumerator
LCDCursorTypeOff 

Make cursor invisible

LCDCursorTypeBlink 

Turn on blinking-block cursor

LCDCursorTypeOn 

Turn on visible underline cursor

LCDCursorTypeOnBlink 

Turn on blinking-block cursor + visible underline cursor

◆ LCDDirectionType_e

Direction mode for scroll and move

Enumerator
LCDMoveRight 

move or scroll right

LCDMoveLeft 

move or scroll left

◆ LCDEntryMode_e

Entry mode control set command, Command Byte Code

Enumerator
LCDEntryModeOne 

Display Shift :OFF Decrement Address Counter

LCDEntryModeTwo 

Display Shift :ON Decrement Address Counter

LCDEntryModeThree 

Display Shift :OFF Increment Address Counter, default

LCDEntryModeFour 

Display Shift :ON Increment Address Counter

◆ LCDLineNumber_e

Line Row Number

Enumerator
LCDLineNumberOne 

row 1

LCDLineNumberTwo 

row 2

LCDLineNumberThree 

row 3

LCDLineNumberFour 

row 4

Constructor & Destructor Documentation

◆ HD44780PCF8574LCD()

HD44780PCF8574LCD::HD44780PCF8574LCD ( uint8_t  NumRow,
uint8_t  NumCol,
int  I2CDevice,
int  I2Caddress,
int  I2CFlags 
)

Constructor for class HD44780PCF8574LCD.

Parameters
NumRownumber of rows in LCD
NumColnumber of columns in LCD
I2CDeviceAn I2C device number.
I2CaddressThe address of a device on the I2C bus. PCF8574 default is 0x27.
I2CFlagsFlags which modify an I2C open command. None are currently defined.

Member Function Documentation

◆ LCD_I2C_OFF()

rdlib::Return_Codes_e HD44780PCF8574LCD::LCD_I2C_OFF ( void  )

End I2C operations.

Returns
error for failure to close a I2C bus device
  1. rdlib::Success
  2. rdlib::I2CcloseFail

◆ LCD_I2C_ON()

rdlib::Return_Codes_e HD44780PCF8574LCD::LCD_I2C_ON ( void  )

Switch on the I2C.

Note
Start I2C operations.
Returns
error for failure to init a I2C bus
  1. rdlib::Success
  2. rdlib::I2CbeginFail

◆ LCDBackLightGet()

bool HD44780PCF8574LCD::LCDBackLightGet ( void  )

get the backlight flag status

Returns
the status of backlight on or off , true or false.

◆ LCDBackLightSet()

void HD44780PCF8574LCD::LCDBackLightSet ( bool  OnOff)

Turn LED backlight on and off.

Parameters
OnOffpassed bool True = LED on , false = display LED off
Note
another data or command must be issued before it takes effect.

◆ LCDChangeEntryMode()

void HD44780PCF8574LCD::LCDChangeEntryMode ( LCDEntryMode_e  newEntryMode)

Change entry mode.

Parameters
newEntryMode1-4 , 4 choices.

◆ LCDCheckConnection()

int HD44780PCF8574LCD::LCDCheckConnection ( void  )

checks if LCD on I2C bus

Returns
lg Error codes, LG_OKAY 0x00 = Success
Note
Error codes are here https://abyz.me.uk/lg/lgpio.html prints error code text to console

◆ LCDClearLine()

void HD44780PCF8574LCD::LCDClearLine ( LCDLineNumber_e  lineNo)

Clear a line by writing spaces to every position.

Parameters
lineNoLCDLineNumber_e enum lineNo 1-4

◆ LCDClearScreen()

rdlib::Return_Codes_e HD44780PCF8574LCD::LCDClearScreen ( void  )

Clear screen by writing spaces to every position.

Note
: See also LCDClearScreenCmd for software command clear alternative.
Returns
  1. Success
  2. GenericError of number of rows invalid

◆ LCDClearScreenCmd()

void HD44780PCF8574LCD::LCDClearScreenCmd ( void  )

Clear display using software command , set cursor position to zero.

Note
See also LCDClearScreen for manual clear

◆ LCDCreateCustomChar()

rdlib::Return_Codes_e HD44780PCF8574LCD::LCDCreateCustomChar ( uint8_t  location,
uint8_t charmap 
)

Saves a custom character to a location in character generator RAM 64 bytes.

Parameters
locationCG_RAM location 0-7, we only have 8 locations 64 bytes
charmapAn array of 8 bytes representing a custom character data
Returns
codes
  1. Success
  2. CharArrayNullptr
  3. InvalidRAMLocation

◆ LCDDisplayON()

void HD44780PCF8574LCD::LCDDisplayON ( bool  OnOff)

Turn Screen on and off.

Parameters
OnOffTrue = display on , false = display off

◆ LCDGOTO()

void HD44780PCF8574LCD::LCDGOTO ( LCDLineNumber_e  line,
uint8_t  col 
)

moves cursor to an x , y position on display.

Parameters
linex row 1-4
coly column 0-15 or 0-19

◆ LCDI2CErrorGet()

int HD44780PCF8574LCD::LCDI2CErrorGet ( void  )

get I2C error Flag

See Error Codes at bottom of https://abyz.me.uk/lg/lgpio.html

Returns
I2C error flag

◆ LCDI2CErrorRetryNumGet()

uint8_t HD44780PCF8574LCD::LCDI2CErrorRetryNumGet ( void  )

Gets the I2C error retry attempts, used in the event of an I2C write error.

Number of times to retry in event of an error

Returns
_I2C_ErrorRetryNum

◆ LCDI2CErrorRetryNumSet()

void HD44780PCF8574LCD::LCDI2CErrorRetryNumSet ( uint8_t  AttemptCount)

Sets the I2C error retry attempts used in the event of an I2C write error.

Number of times to retry in event of an error

Parameters
AttemptCountI2C retry attempts

◆ LCDI2CErrorTimeoutGet()

uint16_t HD44780PCF8574LCD::LCDI2CErrorTimeoutGet ( void  )

Gets the I2C timeout, used in the event of an I2C write error.

Delay between retry attempts in event of an error , mS

Returns
I2C timeout delay in mS, _I2C_ErrorDelay

◆ LCDI2CErrorTimeoutSet()

void HD44780PCF8574LCD::LCDI2CErrorTimeoutSet ( uint16_t  newTimeout)

Sets the I2C timeout, in the event of an I2C write error.

Delay between retry attempts in event of an error , mS

Parameters
newTimeoutI2C timeout delay in mS

◆ LCDInit()

void HD44780PCF8574LCD::LCDInit ( LCDCursorType_e  CursorType)

Initialise LCD.

Parameters
CursorTypeThe cursor type 4 choices.

◆ LCDMoveCursor()

void HD44780PCF8574LCD::LCDMoveCursor ( LCDDirectionType_e  direction,
uint8_t  moveSize 
)

Moves cursor.

Parameters
directionenum LCDDirectionType_e left or right
moveSizenumber of spaces to move

◆ LCDPrintCustomChar()

void HD44780PCF8574LCD::LCDPrintCustomChar ( uint8_t  location)

Print out a customer character from character generator CGRAM 64 bytes 8 characters.

Parameters
locationCGRAM 0-7

◆ LCDResetScreen()

void HD44780PCF8574LCD::LCDResetScreen ( LCDCursorType_e  CursorType)

Reset screen.

Parameters
CursorTypeLCDCursorType_e enum cursor type, 4 choices

◆ LCDScroll()

void HD44780PCF8574LCD::LCDScroll ( LCDDirectionType_e  direction,
uint8_t  ScrollSize 
)

Scrolls screen.

Parameters
directionleft or right
ScrollSizenumber of spaces to scroll

◆ LCDSendChar()

void HD44780PCF8574LCD::LCDSendChar ( char  data)

Sends a character to screen , simply wraps SendData command.

Parameters
dataCharacter to display

◆ LCDSendCmd()

void HD44780PCF8574LCD::LCDSendCmd ( unsigned char  cmd)
private

Send command byte to lcd.

Parameters
cmdcommand byte
Note
if debug flag == true ,will output data on I2C failures.

◆ LCDSendData()

void HD44780PCF8574LCD::LCDSendData ( unsigned char  data)
private

Send data byte to LCD via I2C.

Parameters
dataThe data byte to send
Note
if debug flag is true, will output data on I2C failures.

◆ LCDSendString()

rdlib::Return_Codes_e HD44780PCF8574LCD::LCDSendString ( char str)

Send a string to LCD.

Parameters
strPointer to the char array
Returns
codes
  1. Success
  2. CharArrayNullptr
  3. CustomCharLen

◆ write()

size_t HD44780PCF8574LCD::write ( uint8_t  character)
virtual

Called by print class, used to print out numerical data types etc.

Parameters
characterwrite a character
Note
used internally. Called by the print method using virtual
Returns
returns 1 to the print class

Implements Print.

Member Data Documentation

◆ _I2C_ErrorDelay

uint16_t HD44780PCF8574LCD::_I2C_ErrorDelay = 100
private

I2C delay(in between retry attempts) in event of error in mS

◆ _I2C_ErrorFlag

int HD44780PCF8574LCD::_I2C_ErrorFlag = 0
private

In event of I2C error holds code

◆ _I2C_ErrorRetryNum

uint8_t HD44780PCF8574LCD::_I2C_ErrorRetryNum = 3
private

In event of I2C error number of retry attempts

◆ _LCDBackLight

enum LCDBackLight_e HD44780PCF8574LCD::_LCDBackLight = LCDBackLightOnMask
private

Enum to store backlight status

◆ _LCDI2CAddress

int HD44780PCF8574LCD::_LCDI2CAddress = 0x27
private

I2C address for I2C module PCF8574 backpack on LCD

◆ _LCDI2CDevice

int HD44780PCF8574LCD::_LCDI2CDevice = 1
private

An I2C device number.

◆ _LCDI2CFlags

int HD44780PCF8574LCD::_LCDI2CFlags = 0
private

Flags which modify an I2C open command. None are currently defined.

◆ _LCDI2CHandle

int HD44780PCF8574LCD::_LCDI2CHandle = 0
private

A number referencing an object opened by one of lgI2cOpen

◆ _NumColsLCD

uint8_t HD44780PCF8574LCD::_NumColsLCD = 16
private

number of columns on LCD

◆ _NumRowsLCD

uint8_t HD44780PCF8574LCD::_NumRowsLCD = 2
private

number of rows on LCD


The documentation for this class was generated from the following files: