Skip to content

Add setCodePage() function for LCDs that support it #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions keywords.txt
Original file line number Diff line number Diff line change
@@ -31,6 +31,7 @@ scrollDisplayLeft KEYWORD2
scrollDisplayRight KEYWORD2
createChar KEYWORD2
setRowOffsets KEYWORD2
setCodePage KEYWORD2

#######################################
# Constants (LITERAL1)
19 changes: 18 additions & 1 deletion src/LiquidCrystal.cpp
Original file line number Diff line number Diff line change
@@ -67,6 +67,8 @@ void LiquidCrystal::init(uint8_t fourbitmode, uint8_t rs, uint8_t rw, uint8_t en
_data_pins[6] = d6;
_data_pins[7] = d7;

_cpage = LCD_CPAGE0;

if (fourbitmode)
_displayfunction = LCD_4BITMODE | LCD_1LINE | LCD_5x8DOTS;
else
@@ -148,7 +150,7 @@ void LiquidCrystal::begin(uint8_t cols, uint8_t lines, uint8_t dotsize) {
}

// finally, set # lines, font size, etc.
command(LCD_FUNCTIONSET | _displayfunction);
command(LCD_FUNCTIONSET | _displayfunction | _cpage);

// turn the display on with no cursor or blinking default
_displaycontrol = LCD_DISPLAYON | LCD_CURSOROFF | LCD_BLINKOFF;
@@ -270,6 +272,21 @@ void LiquidCrystal::createChar(uint8_t location, uint8_t charmap[]) {
}
}

// Set code page for characters. Defaults to 0.
// Caveat! If there is text on screen - it will be garbled!
void LiquidCrystal::setCodePage(uint8_t page) {
uint8_t opage = _cpage;

if (page == 0) {
_cpage = LCD_CPAGE0;
} else {
_cpage = LCD_CPAGE1;
}

if (opage != _cpage)
command(LCD_FUNCTIONSET | _displayfunction | _cpage);
}

/*********** mid level commands, for sending data/cmds */

inline void LiquidCrystal::command(uint8_t value) {
4 changes: 4 additions & 0 deletions src/LiquidCrystal.h
Original file line number Diff line number Diff line change
@@ -41,6 +41,8 @@
#define LCD_1LINE 0x00
#define LCD_5x10DOTS 0x04
#define LCD_5x8DOTS 0x00
#define LCD_CPAGE0 0x00
#define LCD_CPAGE1 0x02

class LiquidCrystal : public Print {
public:
@@ -80,6 +82,7 @@ class LiquidCrystal : public Print {
void setRowOffsets(int row1, int row2, int row3, int row4);
void createChar(uint8_t, uint8_t[]);
void setCursor(uint8_t, uint8_t);
void setCodePage(uint8_t);
virtual size_t write(uint8_t);
void command(uint8_t);

@@ -98,6 +101,7 @@ class LiquidCrystal : public Print {
uint8_t _displayfunction;
uint8_t _displaycontrol;
uint8_t _displaymode;
uint8_t _cpage;

uint8_t _initialized;