From 7977f14d5ae6dcbfbfecbe36b69c95a71865a753 Mon Sep 17 00:00:00 2001 From: "Collin J. Doering" Date: Sun, 25 Oct 2015 03:54:54 -0400 Subject: [PATCH] Refactor naming to be more consistent Change the name of the following functions: writeLCDNibble_ -> writeLCDDBusNibble_ writeLCDByte_ -> writeLCDDBusByte_ Created a function 'writeLCDDBusByte' which waits for the busy flag (BF) to be cleared and then writes the given 8-bit integer to the LCD data bus regardless of the mode the LCD is operating in (default (8-bit mode), 8-bit arbitrary pin mode, or 4-bit mode). Signed-off-by: Collin J. Doering --- lcdLib.c | 41 ++++++++++++++++++----------------------- lcdLib.h | 10 ++++++++-- 2 files changed, 26 insertions(+), 25 deletions(-) diff --git a/lcdLib.c b/lcdLib.c index 26649c4..e9d3afb 100644 --- a/lcdLib.c +++ b/lcdLib.c @@ -91,7 +91,7 @@ void loop_until_LCD_BF_clear(void) { } #ifdef FOUR_BIT_MODE -void writeLCDNibble_(uint8_t b) { +void writeLCDDBusNibble_(uint8_t b) { // Reset data lines to zeros LCD_DBUS7_PORT &= ~(1 << LCD_DBUS7); LCD_DBUS6_PORT &= ~(1 << LCD_DBUS6); @@ -109,10 +109,10 @@ void writeLCDNibble_(uint8_t b) { } #endif -void writeLCDByte_(uint8_t b) { +void writeLCDDBusByte_(uint8_t b) { #ifdef FOUR_BIT_MODE - writeLCDNibble_(b); - writeLCDNibble_(b << 4); + writeLCDDBusNibble_(b); + writeLCDDBusNibble_(b << 4); #elif defined (EIGHT_BIT_ARBITRARY_PIN_MODE) // Reset data lines to zeros LCD_DBUS7_PORT &= ~(1 << LCD_DBUS7); @@ -141,22 +141,22 @@ void writeLCDByte_(uint8_t b) { #endif } +void writeLCDDBusByte(uint8_t b) { + loop_until_LCD_BF_clear(); // Wait until LCD is ready for new instructions + writeLCDDBusByte_(b); +} + /* Sets RS=RW=0 and writes the given 8 bit integer to the LCD databus. In the default 8-bit mode and EIGHT_BIT_ARBITRARY_PIN_MODE, the given data is written in one cycle using the - writeLCDByte_ function. In FOUR_BIT_MODE however, the given data is written in two cycles - using two successive calls to the writeLCDNibble_ function. + writeLCDDBusByte_ function. In FOUR_BIT_MODE however, the given data is written in two cycles + using two successive calls to the writeLCDDBusNibble_ function. */ void writeLCDInstr_(uint8_t instr) { LCD_RS_PORT &= ~(1 << LCD_RS); // RS=0 LCD_RW_PORT &= ~(1 << LCD_RW); // RW=0 -#ifdef FOUR_BIT_MODE - writeLCDNibble_(instr); - writeLCDNibble_(instr << 4); -#else - writeLCDByte_(instr); -#endif + writeLCDDBusByte_(instr); } void writeLCDInstr(uint8_t instr) { @@ -167,19 +167,14 @@ void writeLCDInstr(uint8_t instr) { /* Sets RS=1, RW=0 and accepts a char (8 bit) and outputs it to the current cursor position of the LCD. In the default 8-bit mode and EIGHT_BIT_ARBITRARY_PIN_MODE, the given data is - written in one cycle using the writeLCDByte_ function. In FOUR_BIT_MODE however, the given - data is written in two cycles using two successive calls to the writeLCDNibble_ function. + written in one cycle using the writeLCDDBusByte_ function. In FOUR_BIT_MODE however, the given + data is written in two cycles using two successive calls to the writeLCDDBusNibble_ function. */ void writeCharToLCD_(char c) { LCD_RS_PORT |= (1 << LCD_RS); // RS=1 LCD_RW_PORT &= ~(1 << LCD_RW); // RW=0 -#ifdef FOUR_BIT_MODE - writeLCDNibble_(c); - writeLCDNibble_(c << 4); -#else - writeLCDByte_(c); -#endif + writeLCDDBusByte_(c); } /* @@ -710,9 +705,9 @@ static inline void softwareLCDInitPulse(void) { LCD_RW_PORT &= ~(1 << LCD_RW); // RW=0 #ifdef FOUR_BIT_MODE - writeLCDNibble_(CMD_INIT); + writeLCDDBusNibble_(CMD_INIT); #else - writeLCDByte_(CMD_INIT); + writeLCDDBusByte_(CMD_INIT); #endif } @@ -731,7 +726,7 @@ void initLCD (void) { #if defined (FOUR_BIT_MODE) // Function Set (4-bit interface; 2 lines with 5x7 dot character font) - writeLCDNibble_(CMD_INIT_FOUR_BIT); + writeLCDDBusNibble_(CMD_INIT_FOUR_BIT); writeLCDInstr_(CMD_INIT_FOUR_BIT | (1 << INSTR_FUNC_SET_N)); #else // Function set (8-bit interface; 2 lines with 5x7 dot character font) diff --git a/lcdLib.h b/lcdLib.h index 62b0ee1..56400fc 100644 --- a/lcdLib.h +++ b/lcdLib.h @@ -94,7 +94,7 @@ void loop_until_LCD_BF_clear(void); Note: this is only defined in FOUR_BIT_MODE */ #ifdef FOUR_BIT_MODE -void writeLCDNibble_(uint8_t); +void writeLCDDBusNibble_(uint8_t); #endif /** @@ -103,7 +103,13 @@ void writeLCDNibble_(uint8_t); This function does not ensure the LCD is ready to accept new data and thus needs to be handled by the caller. */ -void writeLCDByte_(uint8_t); +void writeLCDDBusByte_(uint8_t); + +/** + Given an 8 bit integer, writes it to the LCD data bus, regardless of its + configuration (default 8-bit mode, 8-bit arbitrary pin mode and 4-bit mode). + */ +void writeLCDDBusByte(uint8_t b); /** Given a 8 bit integer representing a LCD instruction, sends it to the LCD display.