TextLCD library for controlling various LCD panels based on the HD44780 4-bit interface
Dependents: STM32_Button_Interrupt_dla_taty
TextLCD_Base Class Reference
A TextLCD interface for driving 4-bit HD44780-based LCDs. More...
#include <TextLCD.h>
Inherited by TextLCD, TextLCD_I2C, TextLCD_I2C_N, TextLCD_SPI, TextLCD_SPI_N, TextLCD_SPI_N_3_10, TextLCD_SPI_N_3_16, TextLCD_SPI_N_3_24, TextLCD_SPI_N_3_8, and TextLCD_SPI_N_3_9.
Public Types | |
enum | LCDType { LCD8x1 = (LCD_T_A | LCD_T_C8 | LCD_T_R1), LCD8x2 = (LCD_T_A | LCD_T_C8 | LCD_T_R2), LCD8x2B = (LCD_T_D | LCD_T_C8 | LCD_T_R2), LCD12x1 = (LCD_T_A | LCD_T_C12 | LCD_T_R1), LCD12x2 = (LCD_T_A | LCD_T_C12 | LCD_T_R2), LCD12x3D = (LCD_T_D | LCD_T_C12 | LCD_T_R3), LCD12x3D1 = (LCD_T_D1 | LCD_T_C12 | LCD_T_R3), LCD12x4 = (LCD_T_A | LCD_T_C12 | LCD_T_R4), LCD12x4D = (LCD_T_B | LCD_T_C12 | LCD_T_R4), LCD16x1 = (LCD_T_A | LCD_T_C16 | LCD_T_R1), LCD16x1C = (LCD_T_C | LCD_T_C16 | LCD_T_R1), LCD16x2 = (LCD_T_A | LCD_T_C16 | LCD_T_R2), LCD16x3D = (LCD_T_D | LCD_T_C16 | LCD_T_R3), LCD16x3F = (LCD_T_F | LCD_T_C16 | LCD_T_R3), LCD16x3G = (LCD_T_G | LCD_T_C16 | LCD_T_R3), LCD16x4 = (LCD_T_A | LCD_T_C16 | LCD_T_R4), LCD20x1 = (LCD_T_A | LCD_T_C20 | LCD_T_R1), LCD20x2 = (LCD_T_A | LCD_T_C20 | LCD_T_R2), LCD20x4 = (LCD_T_A | LCD_T_C20 | LCD_T_R4), LCD20x4D = (LCD_T_D | LCD_T_C20 | LCD_T_R4), LCD24x1 = (LCD_T_A | LCD_T_C24 | LCD_T_R1), LCD24x2 = (LCD_T_A | LCD_T_C24 | LCD_T_R2), LCD24x4D = (LCD_T_D | LCD_T_C24 | LCD_T_R4), LCD40x2 = (LCD_T_A | LCD_T_C40 | LCD_T_R2), LCD40x4 = (LCD_T_E | LCD_T_C40 | LCD_T_R4) } |
LCD panel format. More... | |
enum | LCDCtrl { HD44780 = 0 | LCD_C_PAR, AC780 = 1 | (LCD_C_PAR | LCD_C_SPI4 | LCD_C_I2C | LCD_C_PDN), AIP31068 = 2 | (LCD_C_SPI3_9 | LCD_C_I2C | LCD_C_BST), KS0073 = 3 | (LCD_C_PAR | LCD_C_SPI3_24 | LCD_C_PDN), KS0078 = 4 | (LCD_C_PAR | LCD_C_SPI3_24 | LCD_C_PDN), PCF2103_3V3 = 5 | (LCD_C_PAR | LCD_C_I2C), PCF2113_3V3 = 6 | (LCD_C_PAR | LCD_C_I2C | LCD_C_BST | LCD_C_CTR), PCF2116_3V3 = 7 | (LCD_C_PAR | LCD_C_I2C | LCD_C_BST), PCF2116_5V = 8 | (LCD_C_PAR | LCD_C_I2C), PCF2116C_5V = 9 | (LCD_C_PAR | LCD_C_I2C | LCD_C_BST) | LCD_C_FT1, PCF2119_3V3 = 10 | (LCD_C_PAR | LCD_C_I2C | LCD_C_BST | LCD_C_CTR), PT6314 = 13 | (LCD_C_PAR | LCD_C_SPI3_16 | LCD_C_CTR), SSD1803_3V3 = 14 | (LCD_C_PAR | LCD_C_SPI3_24 | LCD_C_I2C | LCD_C_BST | LCD_C_CTR | LCD_C_PDN), ST7032_3V3 = 16 | (LCD_C_PAR | LCD_C_SPI4 | LCD_C_I2C | LCD_C_BST | LCD_C_CTR), ST7032_5V = 17 | (LCD_C_PAR | LCD_C_SPI4 | LCD_C_I2C | LCD_C_CTR), ST7036_3V3 = 18 | (LCD_C_PAR | LCD_C_SPI4 | LCD_C_I2C | LCD_C_BST | LCD_C_CTR), ST7036_5V = 19 | (LCD_C_PAR | LCD_C_SPI4 | LCD_C_I2C | LCD_C_BST | LCD_C_CTR), ST7066_ACM = 20 | (LCD_C_PAR | LCD_C_I2C), ST7070 = 21 | (LCD_C_PAR | LCD_C_SPI3_8 | LCD_C_SPI4), US2066_3V3 = 22 | (LCD_C_PAR | LCD_C_SPI3_24 | LCD_C_I2C | LCD_C_CTR | LCD_C_PDN), WS0010 = 23 | (LCD_C_PAR | LCD_C_SPI3_10 | LCD_C_PDN) } |
LCD Controller Device. More... | |
enum | LCDCursor { CurOff_BlkOff = 0x00, CurOn_BlkOff = 0x02, CurOff_BlkOn = 0x01, CurOn_BlkOn = 0x03 } |
LCD Cursor control. More... | |
enum | LCDMode { DispOff = 0x00, DispOn = 0x04 } |
LCD Display control. More... | |
enum | LCDBacklight { LightOff, LightOn } |
LCD Backlight control. More... | |
enum | LCDBlink { BlinkOff, BlinkOn } |
LCD Blink control (UDC), supported for some Controllers. More... | |
enum | LCDOrient { Top, Bottom } |
LCD Orientation control, supported for some Controllers. More... | |
enum | LCDBigFont { None, TopLine, CenterLine, BottomLine, TopBottomLine } |
LCD BigFont control, supported for some Controllers. More... | |
Public Member Functions | |
int | ASCII_2_LCD (int c) |
Convert ASCII character code to the LCD fonttable code. | |
int | putc (int c) |
Write a character to the LCD. | |
int | printf (const char *text,...) |
Write a raw string to the LCD. | |
int | putc (int c) |
Write a character to the LCD. | |
int | printf (const char *format,...) |
Write a formatted string to the LCD. | |
void | locate (int column, int row) |
Locate cursor to a screen column and row. | |
int | getAddress (int column, int row) |
Return the memoryaddress of screen column and row location. | |
void | setAddress (int column, int row) |
Set the memoryaddress of screen column and row location. | |
void | cls () |
Clear the screen and locate to 0,0. | |
int | rows () |
Return the number of rows. | |
int | columns () |
Return the number of columns. | |
void | setCursor (LCDCursor cursorMode) |
Set the Cursormode. | |
void | setMode (LCDMode displayMode) |
Set the Displaymode. | |
void | setBacklight (LCDBacklight backlightMode) |
Set the Backlight mode. | |
void | setUDC (unsigned char c, char *udc_data) |
Set User Defined Characters (UDC) | |
void | setUDCBlink (LCDBlink blinkMode) |
Set UDC Blink and Icon blink setUDCBlink method is supported by some compatible devices (eg SSD1803) | |
void | setContrast (unsigned char c=LCD_DEF_CONTRAST) |
Set Contrast setContrast method is supported by some compatible devices (eg ST7032i) that have onboard LCD voltage generation Code imported from fork by JH1PJL. | |
void | setPower (bool powerOn=true) |
Set Power setPower method is supported by some compatible devices (eg SSD1803) that have power down modes. | |
void | setOrient (LCDOrient orient=Top) |
Set Orient setOrient method is supported by some compatible devices (eg SSD1803, US2066) that have top/bottom view modes. | |
void | setBigFont (LCDBigFont lines) |
Set Big Font setBigFont method is supported by some compatible devices (eg SSD1803, US2066) | |
void | setIcon (unsigned char idx, unsigned char data) |
Set Icons. | |
void | clrIcon () |
Clear Icons. | |
void | setInvert (bool invertOn) |
Set Invert setInvert method is supported by some compatible devices (eg KS0073) to swap between black and white. | |
Protected Types | |
enum | _LCDCtrl_Idx |
LCD controller select, mainly used for LCD40x4. More... | |
enum | _LCDDatalength { _LCD_DL_4 = 0x00, _LCD_DL_8 = 0x10 } |
LCD Datalength control to select between 4 or 8 bit data/commands, mainly used for native Serial interface. More... | |
Protected Member Functions | |
TextLCD_Base (LCDType type=LCD16x2, LCDCtrl ctrl=HD44780) | |
Create a TextLCD_Base interface. | |
virtual int | _putc (int value) |
Write a single character (Stream implementation) | |
void | _init (_LCDDatalength dl=_LCD_DL_4) |
Medium level initialisation method for LCD controller. | |
void | _initCtrl (_LCDDatalength dl=_LCD_DL_4) |
Low level initialisation method for LCD controller Set number of lines, fonttype, no cursor etc The controller is accessed in 4-bit parallel mode either directly via mbed pins or through I2C or SPI expander. | |
int | _address (int column, int row) |
Low level character address set method. | |
void | _setCursor (LCDCursor show) |
Low level cursor enable or disable method. | |
void | _setUDC (unsigned char c, char *udc_data) |
Low level method to store user defined characters for current controller. | |
void | _setCursorAndDisplayMode (LCDMode displayMode, LCDCursor cursorType) |
Low level method to restore the cursortype and display mode for current controller. | |
void | _writeNibble (int value) |
Low level nibble write operation to LCD controller (serial or parallel) | |
void | _writeCommand (int command) |
Low level command byte write operation to LCD controller. | |
void | _writeData (int data) |
Low level data byte write operation to LCD controller (serial or parallel). | |
virtual void | _setEnable (bool value)=0 |
Pure Virtual Low level writes to LCD Bus (serial or parallel) Set the Enable pin. | |
virtual void | _setRS (bool value)=0 |
Pure Virtual Low level writes to LCD Bus (serial or parallel) Set the RS pin ( 0 = Command, 1 = Data). | |
virtual void | _setBL (bool value)=0 |
Pure Virtual Low level writes to LCD Bus (serial or parallel) Set the BL pin (0 = Backlight Off, 1 = Backlight On). | |
virtual void | _setData (int value)=0 |
Pure Virtual Low level writes to LCD Bus (serial or parallel) Set the databus value (4 bit). | |
virtual void | _writeByte (int value) |
Low level byte write operation to LCD controller (serial or parallel) Depending on the RS pin this byte will be interpreted as data or command. |
Detailed Description
A TextLCD interface for driving 4-bit HD44780-based LCDs.
Currently supports 8x1, 8x2, 12x2, 12x3, 12x4, 16x1, 16x2, 16x3, 16x4, 20x2, 20x4, 24x2, 24x4, 40x2 and 40x4 panels Interface options include direct mbed pins, I2C portexpander (PCF8474/PCF8574A or MCP23008) or SPI bus shiftregister (74595) or native I2C or SPI interfaces for some supported devices.
Definition at line 146 of file TextLCD.h.
Member Enumeration Documentation
enum _LCDCtrl_Idx [protected] |
enum _LCDDatalength [protected] |
enum LCDBacklight |
enum LCDBigFont |
enum LCDBlink |
enum LCDCtrl |
LCD Controller Device.
- Enumerator:
enum LCDCursor |
enum LCDMode |
enum LCDOrient |
enum LCDType |
LCD panel format.
- Enumerator:
Constructor & Destructor Documentation
TextLCD_Base | ( | LCDType | type = LCD16x2 , |
LCDCtrl | ctrl = HD44780 |
||
) | [protected] |
Create a TextLCD_Base interface.
Base class, can not be instantiated
- Parameters:
-
type Sets the panel size/addressing mode (default = LCD16x2) ctrl LCD controller (default = HD44780) type Sets the panel size/addressing mode (default = LCD16x2) ctrl LCD controller (default = HD44780)
Definition at line 49 of file TextLCD.cpp.
Member Function Documentation
int _address | ( | int | column, |
int | row | ||
) | [protected] |
Low level character address set method.
Definition at line 1475 of file TextLCD.cpp.
void _init | ( | _LCDDatalength | dl = _LCD_DL_4 ) |
[protected] |
Medium level initialisation method for LCD controller.
Init the LCD Controller(s) Clear display.
- Parameters:
-
_LCDDatalength dl sets the datalength of data/commands
- Returns:
- none
Definition at line 71 of file TextLCD.cpp.
void _initCtrl | ( | _LCDDatalength | dl = _LCD_DL_4 ) |
[protected] |
Low level initialisation method for LCD controller Set number of lines, fonttype, no cursor etc The controller is accessed in 4-bit parallel mode either directly via mbed pins or through I2C or SPI expander.
Init the LCD controller Set number of lines, fonttype, no cursor etc The controller is accessed in 4-bit parallel mode either directly via mbed pins or through I2C or SPI expander.
Some controllers also support native I2C or SPI interfaces.
- Parameters:
-
_LCDDatalength dl sets the 4 or 8 bit datalength of data/commands. Required for some native serial modes.
- Returns:
- none
Some controllers also support native I2C or SPI interfaces.
- Parameters:
-
_LCDDatalength dl sets the 4 or 8 bit datalength of data/commands. Required for some native serial modes.
- Returns:
- none
Note: some configurations are commented out because they have not yet been tested due to lack of hardware
Definition at line 99 of file TextLCD.cpp.
int _putc | ( | int | value ) | [protected, virtual] |
Write a single character (Stream implementation)
Definition at line 1325 of file TextLCD.cpp.
virtual void _setBL | ( | bool | value ) | [protected, pure virtual] |
Pure Virtual Low level writes to LCD Bus (serial or parallel) Set the BL pin (0 = Backlight Off, 1 = Backlight On).
void _setCursor | ( | LCDCursor | show ) | [protected] |
Low level cursor enable or disable method.
Low level method to restore the cursortype and display mode for current controller.
Definition at line 1768 of file TextLCD.cpp.
virtual void _setData | ( | int | value ) | [protected, pure virtual] |
Pure Virtual Low level writes to LCD Bus (serial or parallel) Set the databus value (4 bit).
virtual void _setEnable | ( | bool | value ) | [protected, pure virtual] |
Pure Virtual Low level writes to LCD Bus (serial or parallel) Set the Enable pin.
virtual void _setRS | ( | bool | value ) | [protected, pure virtual] |
Pure Virtual Low level writes to LCD Bus (serial or parallel) Set the RS pin ( 0 = Command, 1 = Data).
void _setUDC | ( | unsigned char | c, |
char * | udc_data | ||
) | [protected] |
Low level method to store user defined characters for current controller.
- Parameters:
-
unsigned char c The Index of the UDC (0..7) for HD44780 clones and (0..15) for some more advanced controllers char *udc_data The bitpatterns for the UDC (8 bytes of 5 significant bits) unsigned char c The Index of the UDC (0..7) for HD44780 clones and (0..15) for some more advanced controllers char *udc_data The bitpatterns for the UDC (8 bytes of 5 significant bits for bitpattern and 3 bits for blinkmode (advanced types))
Definition at line 1844 of file TextLCD.cpp.
void _writeByte | ( | int | value ) | [protected, virtual] |
Low level byte write operation to LCD controller (serial or parallel) Depending on the RS pin this byte will be interpreted as data or command.
Definition at line 1433 of file TextLCD.cpp.
void _writeCommand | ( | int | command ) | [protected] |
Low level command byte write operation to LCD controller.
Methods resets the RS bit and provides the required timing for the command.
Definition at line 1452 of file TextLCD.cpp.
void _writeData | ( | int | data ) | [protected] |
Low level data byte write operation to LCD controller (serial or parallel).
Methods sets the RS bit and provides the required timing for the data.
Definition at line 1462 of file TextLCD.cpp.
void _writeNibble | ( | int | value ) | [protected] |
Low level nibble write operation to LCD controller (serial or parallel)
Definition at line 1421 of file TextLCD.cpp.
int ASCII_2_LCD | ( | int | c ) |
Convert ASCII character code to the LCD fonttable code.
- Parameters:
-
c The character to write to the display
- Returns:
- The character code for the specific fonttable of the controller
Definition at line 1374 of file TextLCD.cpp.
void clrIcon | ( | ) |
void cls | ( | ) |
Clear the screen and locate to 0,0.
Clear the screen, Cursor home.
Definition at line 1276 of file TextLCD.cpp.
int columns | ( | ) |
Return the number of columns.
- Returns:
- The number of columns
- The number of columns
Note: some configurations are commented out because they have not yet been tested due to lack of hardware
Definition at line 1689 of file TextLCD.cpp.
int getAddress | ( | int | column, |
int | row | ||
) |
Return the memoryaddress of screen column and row location.
- Parameters:
-
column The horizontal position from the left, indexed from 0 row The vertical position from the top, indexed from 0
- Returns:
- The memoryaddress of screen column and row location
Definition at line 1489 of file TextLCD.cpp.
void locate | ( | int | column, |
int | row | ||
) |
Locate cursor to a screen column and row.
- Parameters:
-
column The horizontal position from the left, indexed from 0 row The vertical position from the top, indexed from 0
Definition at line 1312 of file TextLCD.cpp.
int printf | ( | const char * | format, |
... | |||
) |
Write a formatted string to the LCD.
- Parameters:
-
format A printf-style format string, followed by the variables to use in formatting the string.
int printf | ( | const char * | text, |
... | |||
) |
Write a raw string to the LCD.
- Parameters:
-
string text, may be followed by variables to emulate formatting the string. However, printf formatting is NOT supported and variables will be ignored!
Definition at line 1409 of file TextLCD.cpp.
int putc | ( | int | c ) |
Write a character to the LCD.
- Parameters:
-
c The character to write to the display
Definition at line 1399 of file TextLCD.cpp.
int putc | ( | int | c ) |
Write a character to the LCD.
- Parameters:
-
c The character to write to the display
int rows | ( | ) |
Return the number of rows.
- Returns:
- The number of rows
- The number of rows
Note: some configurations are commented out because they have not yet been tested due to lack of hardware
Definition at line 1702 of file TextLCD.cpp.
void setAddress | ( | int | column, |
int | row | ||
) |
Set the memoryaddress of screen column and row location.
- Parameters:
-
column The horizontal position from the left, indexed from 0 row The vertical position from the top, indexed from 0
Definition at line 1655 of file TextLCD.cpp.
void setBacklight | ( | LCDBacklight | backlightMode ) |
Set the Backlight mode.
- Parameters:
-
backlightMode The Backlight mode (LightOff, LightOn)
Definition at line 1786 of file TextLCD.cpp.
void setBigFont | ( | LCDBigFont | lines ) |
Set Big Font setBigFont method is supported by some compatible devices (eg SSD1803, US2066)
- Parameters:
-
lines The selected Big Font lines (None, TopLine, CenterLine, BottomLine, TopBottomLine) Double height characters can be shown on lines 1+2, 2+3, 3+4 or 1+2 and 3+4 Valid double height lines depend on the LCDs number of rows.
Definition at line 2242 of file TextLCD.cpp.
void setContrast | ( | unsigned char | c = LCD_DEF_CONTRAST ) |
Set Contrast setContrast method is supported by some compatible devices (eg ST7032i) that have onboard LCD voltage generation Code imported from fork by JH1PJL.
Set Contrast setContrast method is supported by some compatible devices (eg ST7032i) that have onboard LCD voltage generation Initial code for ST70XX imported from fork by JH1PJL.
- Parameters:
-
unsigned char c contrast data (6 significant bits, valid range 0..63, Value 0 will disable the Vgen)
- Returns:
- none
Definition at line 1996 of file TextLCD.cpp.
void setCursor | ( | LCDCursor | cursorMode ) |
Set the Cursormode.
- Parameters:
-
cursorMode The Cursor mode (CurOff_BlkOff, CurOn_BlkOff, CurOff_BlkOn, CurOn_BlkOn)
Definition at line 1713 of file TextLCD.cpp.
void setIcon | ( | unsigned char | idx, |
unsigned char | data | ||
) |
Set Icons.
- Parameters:
-
unsigned char idx The Index of the icon pattern (0..15) for KS0073 and similar controllers and Index (0..31) for PCF2103 and similar controllers unsigned char data The bitpattern for the icons (6 lsb for KS0073 bitpattern (5 lsb for KS0078) and 2 msb for blinkmode) The bitpattern for the PCF2103 icons is 5 lsb (UDC 0..2) and 5 lsb for blinkmode (UDC 4..6)
Definition at line 2359 of file TextLCD.cpp.
void setInvert | ( | bool | invertOn ) |
Set Invert setInvert method is supported by some compatible devices (eg KS0073) to swap between black and white.
- Parameters:
-
bool invertOn Invert on/off
- Returns:
- none
Definition at line 2588 of file TextLCD.cpp.
void setMode | ( | LCDMode | displayMode ) |
Set the Displaymode.
- Parameters:
-
displayMode The Display mode (DispOff, DispOn)
Definition at line 1726 of file TextLCD.cpp.
void setOrient | ( | LCDOrient | orient = Top ) |
Set Orient setOrient method is supported by some compatible devices (eg SSD1803, US2066) that have top/bottom view modes.
- Parameters:
-
LCDOrient orient Orientation
- Returns:
- none
Definition at line 2139 of file TextLCD.cpp.
void setPower | ( | bool | powerOn = true ) |
Set Power setPower method is supported by some compatible devices (eg SSD1803) that have power down modes.
- Parameters:
-
bool powerOn Power on/off
- Returns:
- none
Definition at line 2065 of file TextLCD.cpp.
void setUDC | ( | unsigned char | c, |
char * | udc_data | ||
) |
Set User Defined Characters (UDC)
Set User Defined Characters.
- Parameters:
-
unsigned char c The Index of the UDC (0..7) for HD44780 clones and (0..15) for some more advanced controllers char *udc_data The bitpatterns for the UDC (8 bytes of 5 significant bits for bitpattern and 3 bits for blinkmode (advanced types)) unsigned char c The Index of the UDC (0..7) for HD44780 or clones and (0..15) for some more advanced controllers char *udc_data The bitpatterns for the UDC (8 bytes of 5 significant bits for bitpattern and 3 bits for blinkmode (advanced types))
Definition at line 1812 of file TextLCD.cpp.
void setUDCBlink | ( | LCDBlink | blinkMode ) |
Set UDC Blink and Icon blink setUDCBlink method is supported by some compatible devices (eg SSD1803)
- Parameters:
-
blinkMode The Blink mode (BlinkOff, BlinkOn)
Definition at line 1882 of file TextLCD.cpp.
Generated on Thu Jul 14 2022 17:12:56 by 1.7.2