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 <collin.doering@rekahsoft.ca>
This commit is contained in:
Collin J. Doering 2015-10-25 03:54:54 -04:00
parent 7c18941836
commit 7977f14d5a
2 changed files with 26 additions and 25 deletions

View File

@ -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)

View File

@ -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.