diff --git a/src/ArduinoDUE/Repetier/ui.cpp b/src/ArduinoDUE/Repetier/ui.cpp index ba80225..30397d3 100644 --- a/src/ArduinoDUE/Repetier/ui.cpp +++ b/src/ArduinoDUE/Repetier/ui.cpp @@ -288,8 +288,12 @@ const long baudrates[] PROGMEM = {9600,14400,19200,28800,38400,56000,57600,76800 #define LCD_4BIT LCD_CONFIGURATION | 0x00 /**< 4 bits interface */ #define LCD_2LINE LCD_CONFIGURATION | 0x08 /**< 2 line display */ #define LCD_1LINE LCD_CONFIGURATION | 0x00 /**< 1 line display */ +//for HD44780 and clones #define LCD_5X10 LCD_CONFIGURATION | 0x04 /**< 5 X 10 dots */ #define LCD_5X7 LCD_CONFIGURATION | 0x00 /**< 5 X 7 dots */ +//for Winstar 1604A +#define LCD_5X11 LCD_CONFIGURATION | 0x04 /**< 5 X 18 dots */ +#define LCD_5X8 LCD_CONFIGURATION | 0x00 /**< 5 X 8 dots */ #define LCD_SETCGRAMADDR 0x40 @@ -412,6 +416,10 @@ void initializeLCD() #endif #if UI_DISPLAY_TYPE == DISPLAY_4BIT || UI_DISPLAY_TYPE == DISPLAY_8BIT +#if UI_DISPLAY_TYPE == DISPLAY_4BIT + +#define BIT_INTERFACE LCD_4BIT + void lcdWriteNibble(uint8_t value) { WRITE(UI_DISPLAY_D4_PIN,value & 1); @@ -419,10 +427,9 @@ void lcdWriteNibble(uint8_t value) WRITE(UI_DISPLAY_D6_PIN,value & 4); WRITE(UI_DISPLAY_D7_PIN,value & 8); WRITE(UI_DISPLAY_ENABLE_PIN, HIGH);// enable pulse must be >450ns - DELAY1MICROSECOND; - + HAL::delayMicroseconds(5); WRITE(UI_DISPLAY_ENABLE_PIN, LOW); - DELAY1MICROSECOND; + HAL::delayMicroseconds(15); //tc must be >1200ns } void lcdWriteByte(uint8_t c,uint8_t rs) @@ -443,13 +450,13 @@ void lcdWriteByte(uint8_t c,uint8_t rs) DELAY1MICROSECOND; busy = READ(UI_DISPLAY_D7_PIN); WRITE(UI_DISPLAY_ENABLE_PIN, LOW); - DELAY1MICROSECOND; + HAL::delayMicroseconds(5); WRITE(UI_DISPLAY_ENABLE_PIN, HIGH); - DELAY1MICROSECOND; + HAL::delayMicroseconds(5); WRITE(UI_DISPLAY_ENABLE_PIN, LOW); - DELAY1MICROSECOND; + HAL::delayMicroseconds(5); } while (busy); @@ -460,34 +467,96 @@ void lcdWriteByte(uint8_t c,uint8_t rs) WRITE(UI_DISPLAY_RW_PIN, LOW); #endif WRITE(UI_DISPLAY_RS_PIN, rs); - + HAL::delayMicroseconds(5); WRITE(UI_DISPLAY_D4_PIN, c & 0x10); WRITE(UI_DISPLAY_D5_PIN, c & 0x20); WRITE(UI_DISPLAY_D6_PIN, c & 0x40); WRITE(UI_DISPLAY_D7_PIN, c & 0x80); WRITE(UI_DISPLAY_ENABLE_PIN, HIGH); // enable pulse must be >450ns - DELAY1MICROSECOND; + HAL::delayMicroseconds(5); WRITE(UI_DISPLAY_ENABLE_PIN, LOW); - DELAY1MICROSECOND; + HAL::delayMicroseconds(5);//tc must be >1200ns WRITE(UI_DISPLAY_D4_PIN, c & 0x01); WRITE(UI_DISPLAY_D5_PIN, c & 0x02); WRITE(UI_DISPLAY_D6_PIN, c & 0x04); WRITE(UI_DISPLAY_D7_PIN, c & 0x08); WRITE(UI_DISPLAY_ENABLE_PIN, HIGH); // enable pulse must be >450ns - DELAY1MICROSECOND; + HAL::delayMicroseconds(5); WRITE(UI_DISPLAY_ENABLE_PIN, LOW); - DELAY1MICROSECOND; - + HAL::delayMicroseconds(5);//tc must be >1200ns } +#else //DISPLAY_8BIT + +#define BIT_INTERFACE LCD_8BIT + +void lcdWriteByte(uint8_t c,uint8_t rs) +{ +#if UI_DISPLAY_RW_PIN<0 + HAL::delayMicroseconds(UI_DELAYPERCHAR); +#else + SET_INPUT(UI_DISPLAY_D4_PIN); + SET_INPUT(UI_DISPLAY_D5_PIN); + SET_INPUT(UI_DISPLAY_D6_PIN); + SET_INPUT(UI_DISPLAY_D7_PIN); + WRITE(UI_DISPLAY_RW_PIN, HIGH); + WRITE(UI_DISPLAY_RS_PIN, LOW); + uint8_t busy; + do + { + WRITE(UI_DISPLAY_ENABLE_PIN, HIGH); + DELAY1MICROSECOND; + busy = READ(UI_DISPLAY_D7_PIN); + WRITE(UI_DISPLAY_ENABLE_PIN, LOW); + HAL::delayMicroseconds(5); + + WRITE(UI_DISPLAY_ENABLE_PIN, HIGH); + HAL::delayMicroseconds(5); + + WRITE(UI_DISPLAY_ENABLE_PIN, LOW); + HAL::delayMicroseconds(5); + + } + while (busy); + SET_OUTPUT(UI_DISPLAY_D4_PIN); + SET_OUTPUT(UI_DISPLAY_D5_PIN); + SET_OUTPUT(UI_DISPLAY_D6_PIN); + SET_OUTPUT(UI_DISPLAY_D7_PIN); + WRITE(UI_DISPLAY_RW_PIN, LOW); +#endif + WRITE(UI_DISPLAY_RS_PIN, rs); + HAL::delayMicroseconds(5); + WRITE(UI_DISPLAY_D0_PIN, c & 0x01); + WRITE(UI_DISPLAY_D1_PIN, c & 0x02); + WRITE(UI_DISPLAY_D2_PIN, c & 0x04); + WRITE(UI_DISPLAY_D3_PIN, c & 0x08); + WRITE(UI_DISPLAY_D4_PIN, c & 0x10); + WRITE(UI_DISPLAY_D5_PIN, c & 0x20); + WRITE(UI_DISPLAY_D6_PIN, c & 0x40); + WRITE(UI_DISPLAY_D7_PIN, c & 0x80); + WRITE(UI_DISPLAY_ENABLE_PIN, HIGH); // enable pulse must be >450ns + HAL::delayMicroseconds(5); + WRITE(UI_DISPLAY_ENABLE_PIN, LOW); //tc must be >1200ns + HAL::delayMicroseconds(5); +} + +#endif + void initializeLCD() { playsound(5000,240); - playsound(3000,240); - // SEE PAGE 45/46 FOR INITIALIZATION SPECIFICATION! - // according to datasheet, we need at least 40ms after power rises above 2.7V + playsound(3000,120); +#if UI_DISPLAY_TYPE == DISPLAY_8BIT + playsound(5000,120); + SET_OUTPUT(UI_DISPLAY_D0_PIN); + SET_OUTPUT(UI_DISPLAY_D1_PIN); + SET_OUTPUT(UI_DISPLAY_D2_PIN); + SET_OUTPUT(UI_DISPLAY_D3_PIN); +#endif + // SEE PAGE 45/46 FOR INITIALIZATION SPECIFICATION! + // according to HD44780 datasheet, we need at least 40ms after power rises above 2.7V // before sending commands. Arduino can turn on way before 4.5V. // is this delay long enough for all cases?? HAL::delayMilliseconds(500); @@ -496,56 +565,51 @@ void initializeLCD() SET_OUTPUT(UI_DISPLAY_D6_PIN); SET_OUTPUT(UI_DISPLAY_D7_PIN); SET_OUTPUT(UI_DISPLAY_RS_PIN); + + //init pins to a known state + WRITE(UI_DISPLAY_D0_PIN, HIGH); + WRITE(UI_DISPLAY_D1_PIN, HIGH); + WRITE(UI_DISPLAY_D2_PIN, HIGH); + WRITE(UI_DISPLAY_D3_PIN, HIGH); + WRITE(UI_DISPLAY_D4_PIN, HIGH); + WRITE(UI_DISPLAY_D5_PIN, HIGH); + WRITE(UI_DISPLAY_D6_PIN, HIGH); + WRITE(UI_DISPLAY_D7_PIN, HIGH); + #if UI_DISPLAY_RW_PIN>-1 SET_OUTPUT(UI_DISPLAY_RW_PIN); #endif - SET_OUTPUT(UI_DISPLAY_ENABLE_PIN); - // Now we pull both RS and R/W low to begin commands WRITE(UI_DISPLAY_RS_PIN, LOW); HAL::delayMicroseconds(5); + //move set output late to be sure pin is not affected before + SET_OUTPUT(UI_DISPLAY_ENABLE_PIN); + HAL::delayMicroseconds(5); WRITE(UI_DISPLAY_ENABLE_PIN, LOW); - - //put the LCD into 4 bit mode - // this is according to the hitachi HD44780 datasheet - // figure 24, pg 46 - - // we start in 8bit mode, try to set 4 bit mode - // at this point we are in 8 bit mode but of course in this - // interface 4 pins are dangling unconnected and the values - // on them don't matter for these instructions. - WRITE(UI_DISPLAY_RS_PIN, LOW); - HAL::delayMicroseconds(10); - lcdWriteNibble(0x03); - HAL::delayMicroseconds(5500); // I have one LCD for which 4500 here was not long enough. - // second try - lcdWriteNibble(0x03); - HAL::delayMicroseconds(150); // wait - // third go! - lcdWriteNibble(0x03); - HAL::delayMicroseconds(150); - // finally, set to 4-bit interface - lcdWriteNibble(0x02); + HAL::delayMilliseconds(10); // Just to be safe + //initialization sequence for 4bits/8bits of Winstar 1604A Screen + //16 rows, 4 lines +#if UI_DISPLAY_TYPE == DISPLAY_4BIT + lcdWriteNibble(0x03);//Init Function Set for 4bits + HAL::delayMicroseconds(150); //more than 39micro seconds +#endif + + lcdCommand( BIT_INTERFACE | LCD_2LINE | LCD_5X11); //LCD Configuration: Bits, Lines and Font + HAL::delayMicroseconds(150); //more than 39micro seconds + + lcdCommand(BIT_INTERFACE | LCD_2LINE | LCD_5X8);//LCD Configuration: Bits, Lines and Font + HAL::delayMicroseconds(150); //more than 39micro seconds + + lcdCommand( LCD_DISPLAYON | LCD_CURSOROFF | LCD_BLINKINGOFF); //Display Control : Display on/off, Cursor, Blinking Cursor HAL::delayMicroseconds(150); - lcdCommand(LCD_DISPLAYOFF); - HAL::delayMicroseconds(120); + lcdCommand(LCD_CLEAR); //Clear Screen + HAL::delayMilliseconds(8); // clear is slow operation more than 1.53ms - lcdCommand(LCD_CLEAR); //- Clear Screen - HAL::delayMilliseconds(10); // clear is slow operation - - // finally, set # lines, font size, etc. - lcdCommand(LCD_4BIT | LCD_2LINE | LCD_5X7); - HAL::delayMicroseconds(120); - - lcdCommand(LCD_DISPLAYON | LCD_CURSOROFF | LCD_BLINKINGOFF); //- Display on + lcdCommand(LCD_INCREASE | LCD_DISPLAYSHIFTOFF); //Entrymode: Sets cursor move direction (I/D); specifies to shift the display HAL::delayMicroseconds(150); - lcdCommand(LCD_INCREASE | LCD_DISPLAYSHIFTOFF); //- Entrymode (Display Shift: off, Increment Address Counter) - HAL::delayMicroseconds(150); - - lcdCommand(LCD_CLEAR); //- Clear Screen - HAL::delayMilliseconds(10); // clear is slow operation + HAL::delayMilliseconds(10);//no recommendation so just a feeling uid.lastSwitch = uid.lastRefresh = HAL::timeInMilliseconds(); uid.createChar(1,character_back); @@ -2220,7 +2284,7 @@ void UIDisplay::refreshPage() printRow(y,cache[y] + UI_COLS - scroll,&displayCache[y][off[y]],scroll); } } -#if DISPLAY_TYPE != 5 +#if UI_DISPLAY_TYPE != 5 HAL::delayMilliseconds(transition<3 ? 200 : 70); #endif HAL::pingWatchdog(); diff --git a/src/ArduinoDUE/Repetier/uiconfig.h b/src/ArduinoDUE/Repetier/uiconfig.h index af55478..fb0019a 100644 --- a/src/ArduinoDUE/Repetier/uiconfig.h +++ b/src/ArduinoDUE/Repetier/uiconfig.h @@ -105,7 +105,7 @@ What display type do you use? If you have Sanguino and want to use the library, you need to have Arduino 023 or older. (13.04.2012) 5 = U8G supported display */ -#define UI_DISPLAY_TYPE 1 +#define UI_DISPLAY_TYPE DISPLAY_8BIT #if UI_DISPLAY_TYPE == DISPLAY_U8G // Special case for graphic displays