From 435c8eb07b16b22b88b200fedf187e1a1c26619e Mon Sep 17 00:00:00 2001 From: "Collin J. Doering" Date: Tue, 6 Oct 2015 03:34:39 -0400 Subject: [PATCH] Fixed busy flag check Inspired by http://web.alfredstate.edu/weimandn/programming/lcd/ATmega328/LCD_code_index.html. Forgot about the 'data hold time', 'address hold time' and 'enable cycle time'. These delays should eventually be implemented as preprocessor constants. Signed-off-by: Collin J. Doering --- lcdLib.c | 22 ++++++++++++++++++---- lcdLibConfig.h | 2 +- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/lcdLib.c b/lcdLib.c index de4d8e9..15cfd10 100644 --- a/lcdLib.c +++ b/lcdLib.c @@ -55,6 +55,8 @@ void clkLCD(void) { } void loop_until_LCD_BF_clear(void) { + uint8_t bf; + LCD_RS_PORT &= ~(1 << LCD_RS); // RS=0 LCD_RW_PORT |= (1 << LCD_RW); // RW=1 @@ -63,8 +65,22 @@ void loop_until_LCD_BF_clear(void) { STATUS_LED_PORT |= 1 << STATUS_LED; // DEBUG do { - clkLCD(); - } while (bit_is_clear(LCD_DBUS7_PIN, LCD_BF)); + bf = 0; + LCD_ENABLE_PORT |= (1 << LCD_ENABLE); + _delay_us(1); // 'delay data time' and 'enable pulse width' + + bf |= (LCD_DBUS7_PIN & (1 << LCD_BF)); + + LCD_ENABLE_PORT &= ~(1 << LCD_ENABLE); + _delay_us(1); // 'address hold time', 'data hold time' and 'enable cycle width' + +#ifdef FOUR_BIT_MODE + LCD_ENABLE_PORT |= (1 << LCD_ENABLE); + _delay_us(1); // 'delay data time' and 'enable pulse width' + LCD_ENABLE_PORT &= ~(1 << LCD_ENABLE); + _delay_us(1); // 'address hold time', 'data hold time' and 'enable cycle width' +#endif + } while (bf); STATUS_LED_PORT &= ~(1 << STATUS_LED); // DEBUG #if defined (FOUR_BIT_MODE) || defined (EIGHT_BIT_ARBITRARY_PIN_MODE) @@ -207,7 +223,6 @@ void writeStringToLCD(const char* str) { void clearDisplay(void) { writeLCDInstr(CMD_CLEAR_DISPLAY); - _delay_us(LCD_CLEAR_DISPLAY_DELAY); // Reset line and char number tracking currentLineNum = 0; @@ -216,7 +231,6 @@ void clearDisplay(void) { void returnHome(void) { writeLCDInstr(CMD_RETURN_HOME); - _delay_us(LCD_RETURN_HOME_DELAY); // Reset line and char number tracking currentLineNum = 0; diff --git a/lcdLibConfig.h b/lcdLibConfig.h index 3ca86f8..82b44c9 100644 --- a/lcdLibConfig.h +++ b/lcdLibConfig.h @@ -59,7 +59,7 @@ //#define EIGHT_BIT_ARBITRARY_PIN_MODE // LCD in 4-bit mode (on arbitrary pins) -//#define FOUR_BIT_MODE +#define FOUR_BIT_MODE /* All mode options */