Rpi-hw  0.7.2
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
rpihw::display::hd44780 Class Reference

Hitachi HD44780 LCD controller. More...

#include <hd44780.hpp>

Public Types

enum  RomCodes { ROM_A00 = 0, ROM_A02 = 1 }
 The ROM codes. More...
 
enum  Commands {
  CLEAR = 0x01, HOME = 0x02, ENTRY = 0x04, POWER = 0x08,
  SHIFT = 0x10, FUNC = 0x20, CGRAM = 0x40, DDRAM = 0x80
}
 The controller command set. More...
 
enum  Settings {
  ENTRY_S = 0x01, ENTRY_ID = 0x02, POWER_B = 0x01, POWER_C = 0x02,
  POWER_D = 0x04, SHIFT_RL = 0x04, SHIFT_SC = 0x08, FUNC_F = 0x04,
  FUNC_N = 0x08, FUNC_DL = 0x10
}
 The controller command set (bit flags). More...
 
enum  CustomCharacters {
  CCHAR0 = 0, CCHAR1 = 1, CCHAR2 = 2, CCHAR3 = 3,
  CCHAR4 = 4, CCHAR5 = 5, CCHAR6 = 6, CCHAR7 = 7
}
 The custom characters. More...
 
enum  CursorMode { NO_CURSOR = 0x00, CURSOR_SOLID = 0x01, CURSOR_BLINKING = 0x02 }
 The cursor modes (bitwise flags). More...
 
enum  AutoscrollMode { NO_SCROLL = 0x00, VSCROLL = 0x01, HSCROLL = 0x02, HSCROLL_LINE = 0x04 }
 The autoscroll modes (bitwise flags). More...
 

Public Member Functions

 hd44780 (uint8_t rs, uint8_t e, uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7)
 Constructor method (4-bit mode). More...
 
 hd44780 (uint8_t rs, uint8_t e, uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3, uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7)
 Constructor method (8-bit mode). More...
 
virtual ~hd44780 ()
 Destructor method.
 
void init (uint8_t cols, uint8_t rows, RomCodes rom_code=ROM_A00, bool font=0)
 Initializes the display. More...
 
void cmd (uint8_t data)
 Sends a command to the display. More...
 
void home ()
 Homes the cursor.
 
void move (uint8_t x, uint8_t y)
 Sets the position of the cursor on the display. More...
 
uint8_t getCursorX () const
 Returns the current x-position of the cursor. More...
 
uint8_t getCursorY () const
 Returns the current y-position of the cursor. More...
 
uint8_t getChar (uint8_t x, uint8_t y) const
 Reads a character from the buffer at specified position. More...
 
void newLine ()
 Moves the cursor to the new line.
 
void write (uint8_t c)
 Writes a character on the display. More...
 
void write (uint8_t x, uint8_t y, uint8_t c)
 Moves the cursor position and writes a character on the display. More...
 
void write (const std::string &text)
 Writes a string on the display. More...
 
void write (const std::string &text, uint8_t flags)
 Writes a string on the display. More...
 
void write (uint8_t x, uint8_t y, const std::string &text)
 Moves the cursor position and writes a string on the display. More...
 
void write (uint8_t x, uint8_t y, const std::string &text, uint8_t flags)
 Moves the cursor position and writes a string on the display. More...
 
void write (const std::u32string &text)
 Writes a unicode string on the display. More...
 
void write (const std::u32string &text, uint8_t flags)
 Writes a unicode string on the display. More...
 
void write (uint8_t x, uint8_t y, const std::u32string &text)
 Moves the cursor position and writes a unicode string on the display. More...
 
void write (uint8_t x, uint8_t y, const std::u32string &text, uint8_t flags)
 Moves the cursor position and writes a unicode string on the display. More...
 
void write (const std::wstring &text)
 Writes a unicode string on the display. More...
 
void write (const std::wstring &text, uint8_t flags)
 Writes a unicode string on the display. More...
 
void write (uint8_t x, uint8_t y, const std::wstring &text)
 Moves the cursor position and writes a unicode string on the display. More...
 
void write (uint8_t x, uint8_t y, const std::wstring &text, uint8_t flags)
 Moves the cursor position and writes a unicode string on the display. More...
 
void scrollLeft (bool cursor=1)
 Scrolls the contents of the display to the left. More...
 
void scrollRight (bool cursor=1)
 Scrolls the contents of the display to the right. More...
 
void scrollUp (bool cursor=1)
 Scrolls the contents of the display to the up. More...
 
void scrollDown (bool cursor=1)
 Scrolls the contents of the display to the down. More...
 
void scrollLeftLine (uint8_t line, bool cursor=1)
 Scrolls a line to the left. More...
 
void scrollRightLine (uint8_t line, bool cursor=1)
 Scrolls a line to the right. More...
 
void defChar (uint8_t index, const uint8_t *data)
 Defines a custom character. More...
 
void setCursor (uint8_t mode)
 Sets the cursor mode. More...
 
void setTypingDelay (size_t delay)
 Sets the typing delay between individual characters (milliseconds). More...
 
size_t getTypingDelay () const
 Returns the typing delay between individual characters (milliseconds). More...
 
void setAutoscroll (uint8_t mode)
 Sets the autoscroll mode. More...
 
void clear ()
 Clears the display.
 

Protected Member Functions

void strobe ()
 Toggles the enable pin.
 
void sendData (uint8_t data, size_t delay=0)
 Sends data to the display. More...
 
void sendSerial (uint8_t data, size_t delay=0)
 Sends a serial data to the display (a nibble at a time). More...
 
void putChar (uint8_t c)
 Puts a character on the display (low level). More...
 
uint8_t encodeChar (char32_t code)
 Maps a unicode character to the corresponding code. More...
 
uint8_t encodeCharA00 (char32_t code)
 Maps a unicode character to the corresponding code (ROM A00, Japanese version). More...
 
uint8_t encodeCharA02 (char32_t code)
 Maps a unicode character to the corresponding code (ROM A02, European version). More...
 

Protected Attributes

iface::outputm_mode
 Output interface to the control pins.
 
iface::outputm_data
 Output interface to the data pins.
 
uint8_t m_lines [4]
 DDRAM line addresses.
 
RomCodes m_rom_code
 ROM code.
 
uint8_t m_font_height
 Font height.
 
std::vector< uint8_t > m_buffer
 Text buffer.
 
size_t m_typing_delay = 0
 Typing delay (milliseconds).
 
uint8_t m_autoscroll = VSCROLL
 Autoscroll mode.
 
uint8_t m_width
 Size of the display.
 
uint8_t m_height
 
uint8_t m_pos_x
 Cursor position.
 
uint8_t m_pos_y
 

Detailed Description

Hitachi HD44780 LCD controller.

Examples:
display/lcd16x2.cpp, display/lcd16x2_unicode.cpp, and display/lcd20x4demo.cpp.

Definition at line 51 of file hd44780.hpp.

Member Enumeration Documentation

The autoscroll modes (bitwise flags).

Enumerator
NO_SCROLL 

No scroll.

VSCROLL 

Vertical scroll.

HSCROLL 

Horizontal scroll.

HSCROLL_LINE 

Horizontal scroll line.

Definition at line 115 of file hd44780.hpp.

The controller command set.

Enumerator
CLEAR 

Clear display.

HOME 

Cursor home.

ENTRY 

Entry mode set.

POWER 

Display on/off control.

SHIFT 

Cursor/display shift.

FUNC 

Function set.

CGRAM 

Set CGRAM address.

DDRAM 

Set DDRAM address.

Definition at line 63 of file hd44780.hpp.

The cursor modes (bitwise flags).

Enumerator
NO_CURSOR 

No cursor.

CURSOR_SOLID 

Solid cursor.

CURSOR_BLINKING 

Blinking the cursor.

Definition at line 107 of file hd44780.hpp.

The custom characters.

Enumerator
CCHAR0 

Custom character #0.

CCHAR1 

Custom character #1.

CCHAR2 

Custom character #2.

CCHAR3 

Custom character #3.

CCHAR4 

Custom character #4.

CCHAR5 

Custom character #5.

CCHAR6 

Custom character #6.

CCHAR7 

Custom character #7.

Definition at line 94 of file hd44780.hpp.

The ROM codes.

Enumerator
ROM_A00 

Japanese version.

ROM_A02 

European version.

Definition at line 56 of file hd44780.hpp.

The controller command set (bit flags).

Enumerator
ENTRY_S 

Shifts display when byte written to display.

ENTRY_ID 

Increments the cursor after each byte written to display.

POWER_B 

Sets a blinking cursor (else sets a solid cursor).

POWER_C 

Turns on the cursor (else turn off).

POWER_D 

Turns on the screen (else turn off).

SHIFT_RL 

Sets cursor shift direction to right (else to left).

SHIFT_SC 

Sets display-shift (else sets cursor-move).

FUNC_F 

Sets the 5x10 character font (else 5x8).

FUNC_N 

Sets number of display lines to 2/4 (else 1).

FUNC_DL 

Sets the 8 bit mode (else sets the 4 bit mode).

Definition at line 76 of file hd44780.hpp.

Constructor & Destructor Documentation

rpihw::display::hd44780::hd44780 ( uint8_t  rs,
uint8_t  e,
uint8_t  d4,
uint8_t  d5,
uint8_t  d6,
uint8_t  d7 
)

Constructor method (4-bit mode).

Parameters
[in]rsThe GPIO pin connected to the rs pin.
[in]eThe GPIO pin connected to the e pin.
[in]d4The GPIO pin connected to the d4 pin.
[in]d5The GPIO pin connected to the d5 pin.
[in]d6The GPIO pin connected to the d6 pin.
[in]d7The GPIO pin connected to the d7 pin.
rpihw::display::hd44780::hd44780 ( uint8_t  rs,
uint8_t  e,
uint8_t  d0,
uint8_t  d1,
uint8_t  d2,
uint8_t  d3,
uint8_t  d4,
uint8_t  d5,
uint8_t  d6,
uint8_t  d7 
)

Constructor method (8-bit mode).

Parameters
[in]rsThe GPIO pin connected to the rs pin.
[in]eThe GPIO pin connected to the e pin.
[in]d0The GPIO pin connected to the d0 pin.
[in]d1The GPIO pin connected to the d1 pin.
[in]d2The GPIO pin connected to the d2 pin.
[in]d3The GPIO pin connected to the d3 pin.
[in]d4The GPIO pin connected to the d4 pin.
[in]d5The GPIO pin connected to the d5 pin.
[in]d6The GPIO pin connected to the d6 pin.
[in]d7The GPIO pin connected to the d7 pin.

Member Function Documentation

void rpihw::display::hd44780::cmd ( uint8_t  data)
inline

Sends a command to the display.

Parameters
[in]dataThe command.

Definition at line 30 of file hd44780-inl.hpp.

void rpihw::display::hd44780::defChar ( uint8_t  index,
const uint8_t *  data 
)

Defines a custom character.

Parameters
[in]indexThe index position of the custom character.
[in]dataThe array containing the character's pixel data (an element per row).
Examples:
display/lcd20x4demo.cpp.
uint8_t rpihw::display::hd44780::encodeChar ( char32_t  code)
protected

Maps a unicode character to the corresponding code.

Parameters
[in]codeThe unicode character.
Returns
The character code.
uint8_t rpihw::display::hd44780::encodeCharA00 ( char32_t  code)
protected

Maps a unicode character to the corresponding code (ROM A00, Japanese version).

Parameters
[in]codeThe unicode character.
Returns
The character code.
uint8_t rpihw::display::hd44780::encodeCharA02 ( char32_t  code)
protected

Maps a unicode character to the corresponding code (ROM A02, European version).

Parameters
[in]codeThe unicode character.
Returns
The character code.
uint8_t rpihw::display::hd44780::getChar ( uint8_t  x,
uint8_t  y 
) const
inline

Reads a character from the buffer at specified position.

Parameters
[in]xThe horizontal position of the character.
[in]yThe vertical position of the character.
Returns
The 8-bit character at position.

Definition at line 54 of file hd44780-inl.hpp.

uint8_t rpihw::display::hd44780::getCursorX ( ) const
inline

Returns the current x-position of the cursor.

Returns
The cursor x-position.

Definition at line 40 of file hd44780-inl.hpp.

uint8_t rpihw::display::hd44780::getCursorY ( ) const
inline

Returns the current y-position of the cursor.

Returns
The cursor y-position.

Definition at line 47 of file hd44780-inl.hpp.

size_t rpihw::display::hd44780::getTypingDelay ( ) const
inline

Returns the typing delay between individual characters (milliseconds).

Returns
The typing delay.

Definition at line 159 of file hd44780-inl.hpp.

void rpihw::display::hd44780::init ( uint8_t  cols,
uint8_t  rows,
RomCodes  rom_code = ROM_A00,
bool  font = 0 
)

Initializes the display.

Parameters
[in]colsNumber of the display columns.
[in]rowsNumber of the display rows.
[in]rom_codeThe ROM code (ROM_A00 or ROM_A02).
[in]fontIf true uses 5x10 dots font, else uses 5x8 dots font.
Examples:
display/lcd16x2.cpp, display/lcd16x2_unicode.cpp, and display/lcd20x4demo.cpp.
void rpihw::display::hd44780::move ( uint8_t  x,
uint8_t  y 
)

Sets the position of the cursor on the display.

Parameters
[in]xThe new horizontal position of the cursor.
[in]yThe new vertical position of the cursor.
Examples:
display/lcd16x2.cpp, and display/lcd20x4demo.cpp.
void rpihw::display::hd44780::putChar ( uint8_t  c)
protected

Puts a character on the display (low level).

Parameters
[in]cThe 8-bit character.
void rpihw::display::hd44780::scrollDown ( bool  cursor = 1)

Scrolls the contents of the display to the down.

Parameters
[in]cursorIf true, will also moves the cursor.
Examples:
display/lcd20x4demo.cpp.
void rpihw::display::hd44780::scrollLeft ( bool  cursor = 1)

Scrolls the contents of the display to the left.

Parameters
[in]cursorIf true, will also moves the cursor.
Examples:
display/lcd20x4demo.cpp.
void rpihw::display::hd44780::scrollLeftLine ( uint8_t  line,
bool  cursor = 1 
)

Scrolls a line to the left.

Parameters
[in]lineThe number of the line to be moved.
[in]cursorIf true, will also moves the cursor.
void rpihw::display::hd44780::scrollRight ( bool  cursor = 1)

Scrolls the contents of the display to the right.

Parameters
[in]cursorIf true, will also moves the cursor.
Examples:
display/lcd20x4demo.cpp.
void rpihw::display::hd44780::scrollRightLine ( uint8_t  line,
bool  cursor = 1 
)

Scrolls a line to the right.

Parameters
[in]lineThe number of the line to be moved.
[in]cursorIf true, will also moves the cursor.
void rpihw::display::hd44780::scrollUp ( bool  cursor = 1)

Scrolls the contents of the display to the up.

Parameters
[in]cursorIf true, will also moves the cursor.
Examples:
display/lcd20x4demo.cpp.
void rpihw::display::hd44780::sendData ( uint8_t  data,
size_t  delay = 0 
)
protected

Sends data to the display.

Parameters
[in]dataThe 4-bit data to be sended.
[in]delayThe delay time after the sending of the data.
void rpihw::display::hd44780::sendSerial ( uint8_t  data,
size_t  delay = 0 
)
protected

Sends a serial data to the display (a nibble at a time).

Parameters
[in]dataThe 8-bit data to be sended.
[in]delayThe delay time after the sending of the data.
void rpihw::display::hd44780::setAutoscroll ( uint8_t  mode)
inline

Sets the autoscroll mode.

Parameters
[in]modeThe bitwise flags of the autoscroll mode. You can use NO_SCROLL, VSCROLL, HSCROLL and HSCROLL_LINE.
Examples:
display/lcd20x4demo.cpp.

Definition at line 166 of file hd44780-inl.hpp.

void rpihw::display::hd44780::setCursor ( uint8_t  mode)

Sets the cursor mode.

Parameters
[in]modeThe bitwise flags of the cursor mode. You can use NO_CURSOR, CURSOR_SOLID and CURSOR_BLINKING.
Examples:
display/lcd20x4demo.cpp.
void rpihw::display::hd44780::setTypingDelay ( size_t  delay)
inline

Sets the typing delay between individual characters (milliseconds).

Parameters
[in]delayThe typing delay.
Examples:
display/lcd20x4demo.cpp.

Definition at line 152 of file hd44780-inl.hpp.

void rpihw::display::hd44780::write ( uint8_t  c)

Writes a character on the display.

Parameters
[in]cThe 8-bit character.
Examples:
display/lcd16x2.cpp, display/lcd16x2_unicode.cpp, and display/lcd20x4demo.cpp.
void rpihw::display::hd44780::write ( uint8_t  x,
uint8_t  y,
uint8_t  c 
)
inline

Moves the cursor position and writes a character on the display.

Parameters
[in]xThe new horizontal position of the cursor.
[in]yThe new vertical position of the cursor.
[in]cThe 8-bit character.

Definition at line 61 of file hd44780-inl.hpp.

void rpihw::display::hd44780::write ( const std::string &  text)

Writes a string on the display.

Parameters
[in]textThe string to be written.
void rpihw::display::hd44780::write ( const std::string &  text,
uint8_t  flags 
)
inline

Writes a string on the display.

Parameters
[in]textThe string to be written.
[in]flagsThe parameters of the text.

Definition at line 71 of file hd44780-inl.hpp.

void rpihw::display::hd44780::write ( uint8_t  x,
uint8_t  y,
const std::string &  text 
)
inline

Moves the cursor position and writes a string on the display.

Parameters
[in]xThe new horizontal position of the cursor.
[in]yThe new vertical position of the cursor.
[in]textThe string to be written.

Definition at line 78 of file hd44780-inl.hpp.

void rpihw::display::hd44780::write ( uint8_t  x,
uint8_t  y,
const std::string &  text,
uint8_t  flags 
)
inline

Moves the cursor position and writes a string on the display.

Parameters
[in]xThe new horizontal position of the cursor.
[in]yThe new vertical position of the cursor.
[in]textThe string to be written.
[in]flagsThe parameters of the text.

Definition at line 88 of file hd44780-inl.hpp.

void rpihw::display::hd44780::write ( const std::u32string &  text)

Writes a unicode string on the display.

Parameters
[in]textThe unicode string to be written.
void rpihw::display::hd44780::write ( const std::u32string &  text,
uint8_t  flags 
)
inline

Writes a unicode string on the display.

Parameters
[in]textThe string to be written.
[in]flagsThe parameters of the text.

Definition at line 98 of file hd44780-inl.hpp.

void rpihw::display::hd44780::write ( uint8_t  x,
uint8_t  y,
const std::u32string &  text 
)
inline

Moves the cursor position and writes a unicode string on the display.

Parameters
[in]xThe new horizontal position of the cursor.
[in]yThe new vertical position of the cursor.
[in]textThe unicode string to be written.

Definition at line 105 of file hd44780-inl.hpp.

void rpihw::display::hd44780::write ( uint8_t  x,
uint8_t  y,
const std::u32string &  text,
uint8_t  flags 
)
inline

Moves the cursor position and writes a unicode string on the display.

Parameters
[in]xThe new horizontal position of the cursor.
[in]yThe new vertical position of the cursor.
[in]textThe unicode string to be written.
[in]flagsThe parameters of the text.

Definition at line 115 of file hd44780-inl.hpp.

void rpihw::display::hd44780::write ( const std::wstring &  text)

Writes a unicode string on the display.

Parameters
[in]textThe unicode string to be written.
void rpihw::display::hd44780::write ( const std::wstring &  text,
uint8_t  flags 
)
inline

Writes a unicode string on the display.

Parameters
[in]textThe string to be written.
[in]flagsThe parameters of the text.

Definition at line 125 of file hd44780-inl.hpp.

void rpihw::display::hd44780::write ( uint8_t  x,
uint8_t  y,
const std::wstring &  text 
)
inline

Moves the cursor position and writes a unicode string on the display.

Parameters
[in]xThe new horizontal position of the cursor.
[in]yThe new vertical position of the cursor.
[in]textThe unicode string to be written.

Definition at line 132 of file hd44780-inl.hpp.

void rpihw::display::hd44780::write ( uint8_t  x,
uint8_t  y,
const std::wstring &  text,
uint8_t  flags 
)
inline

Moves the cursor position and writes a unicode string on the display.

Parameters
[in]xThe new horizontal position of the cursor.
[in]yThe new vertical position of the cursor.
[in]textThe unicode string to be written.
[in]flagsThe parameters of the text.

Definition at line 142 of file hd44780-inl.hpp.


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