From c52292c802e74e51cfdcb617d99aa312c842d4bb Mon Sep 17 00:00:00 2001 From: "Collin J. Doering" Date: Mon, 26 Oct 2015 22:30:44 -0400 Subject: [PATCH] Support both 5x8 and 5x10 fonts Added LCD_FONT in lcdLib.h which is the bitmask to enable 5x8 or 5x10 font when doing the function set instruction (in the definition of initLCD). LCD_FONT_5x8 or LCD_FONT_5x10 should be defined to enable the intended font. One always needs to be defined. Signed-off-by: Collin J. Doering --- lcdLib.c | 4 ++-- lcdLib.h | 12 ++++++++++++ lcdLibConfig.h | 4 ++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/lcdLib.c b/lcdLib.c index 0521d23..3e5d1b8 100644 --- a/lcdLib.c +++ b/lcdLib.c @@ -320,11 +320,11 @@ void initLCD(void) { #if defined (FOUR_BIT_MODE) // Function Set (4-bit interface; 2 lines with 5x7 dot character font) writeLCDDBusNibble_(CMD_INIT_FOUR_BIT); - writeLCDInstr_(CMD_INIT_FOUR_BIT | (1 << INSTR_FUNC_SET_N)); + writeLCDInstr_(CMD_INIT_FOUR_BIT | (1 << INSTR_FUNC_SET_N) | LCD_FONT); #else // Function set (8-bit interface; 2 lines with 5x7 dot character font) // RS=RW=0, DBUS=b00111000,0x38 - writeLCDInstr_(INSTR_FUNC_SET | (1 << INSTR_FUNC_SET_DL) | (1 << INSTR_FUNC_SET_N)); + writeLCDInstr_(INSTR_FUNC_SET | (1 << INSTR_FUNC_SET_DL) | (1 << INSTR_FUNC_SET_N) | LCD_FONT); #endif /* BF now can be checked */ diff --git a/lcdLib.h b/lcdLib.h index 8ec18cc..c6dcdc8 100644 --- a/lcdLib.h +++ b/lcdLib.h @@ -214,6 +214,18 @@ void initLCDByInternalReset(void); #define LCD_CHARACTERS_PER_SCREEN (LCD_CHARACTERS_PER_LINE * LCD_NUMBER_OF_LINES) #endif +#if !defined(LCD_FONT_5x8) &&\ + !defined(LCD_FONT_5x10) +#error "All modes require LCD_FONT_5x8 or LCD_FONT_5x10 to be defined." +#elif defined(LCD_FONT_5x8) && \ + defined(LCD_FONT_5x10) +#error "LCD_FONT_5x8 and LCD_FONT_5x10 are mutually exclusive. Choose one." +#elif defined(LCD_FONT_5x8) +#define LCD_FONT 0 +#elif defined(LCD_FONT_5x10) +#define LCD_FONT (1 << INSTR_FUNC_SET_F) +#endif + #if !defined (LCD_RS) || \ !defined (LCD_RS_PORT) || \ !defined (LCD_RS_DDR) || \ diff --git a/lcdLibConfig.h b/lcdLibConfig.h index d4f3000..bdc9b58 100644 --- a/lcdLibConfig.h +++ b/lcdLibConfig.h @@ -52,6 +52,10 @@ 0x14, \ 0x54 ///< Memory locations for each physical line ordered 1 to LCD_NUMBER_OF_LINES +/* Which font to use (can only leave one uncommented) */ +#define LCD_FONT_5x8 +//#define LCD_FONT_5x10 + /* Support ANSI escapes; comment to disable */ #define LCD_ANSI_ESCAPE_ENABLE