static int LcdInit(NUTDEVICE * dev) { LCD_RS_CLR(); LCD_RW_CLR(); LcdClrBits(LCD_DATA); NutMicroDelay(30); LCD_EN_CLR(); NutMicroDelay(30); NutSleep(18); /* This initialization will make sure, that the LCD is switched * to 8-bit mode, no matter which mode we start from or we finally * need. */ LcdWriteCmd(_BV(LCD_FUNCTION) | _BV(LCD_FUNCTION_8BIT)); NutSleep(16); LcdWriteCmd(_BV(LCD_FUNCTION) | _BV(LCD_FUNCTION_8BIT)); NutSleep(4); LcdWriteCmd(_BV(LCD_FUNCTION) | _BV(LCD_FUNCTION_8BIT)); NutSleep(2); LcdWriteInstruction((_BV(LCD_FUNCTION)) | (_BV(LCD_FUNCTION_8BIT)) | (_BV(LCD_EXT)) , LCD_SHORT_DELAY); /* Switch display and cursor off. */ LcdWriteNibble(_BV(LCD_ON_CTRL) >> 4); LcdWriteNibble(_BV(LCD_ON_CTRL)); NutSleep(2); /* Clear display. */ LcdClear(); /* Set entry mode. */ LcdWriteCmd(_BV(LCD_ENTRY_MODE) | _BV(LCD_ENTRY_INC)); /* Switch display on. */ LcdWriteCmd(_BV(LCD_ON_CTRL) | _BV(LCD_ON_DISPLAY)); /* Move cursor home. */ LcdCursorHome(); /* Set data address to zero. */ LcdWriteCmd(_BV(LCD_DDRAM)); return 0; }
static int LcdInit(NUTDEVICE * dev) { #if defined(PMC_PCER) outr(PMC_PCER, _BV(LCD_RS_PIO_ID) | _BV(LCD_EN_PIO_ID)); #endif /* Initialize GPIO lines. */ #ifdef LCD_RW_BIT outr(PMC_PCER, _BV(LCD_RW_PIO_ID)); LCD_RW_CLR(); #endif #ifdef LCD_EN2_BIT outr(PMC_PCER, _BV(LCD_EN2_PIO_ID)); LCD_EN2_CLR(); #endif #ifdef LCD_RST_BIT outr(PMC_PCER, _BV(LCD_RST_PIO_ID)); LCD_RST_CLR(); #endif LCD_RS_CLR(); LCD_RW_CLR(); LcdClrBits(LCD_DATA); NutMicroDelay(30); LCD_EN_CLR(); NutMicroDelay(30); /* Initial delay. Actually only required after power on. */ NutSleep(16); /* This initialization will make sure, that the LCD is switched * to 8-bit mode, no matter which mode we start from or we finally * need. */ LcdWriteNibble((_BV(LCD_FUNCTION) | _BV(LCD_FUNCTION_8BIT)) >> 4); NutSleep(15); LcdWriteNibble((_BV(LCD_FUNCTION) | _BV(LCD_FUNCTION_8BIT)) >> 4); NutSleep(4); LcdWriteNibble((_BV(LCD_FUNCTION) | _BV(LCD_FUNCTION_8BIT)) >> 4); NutSleep(2); #ifdef LCD_IF_4BIT /* We now switch to 4-bit mode */ LcdWriteNibble(_BV(LCD_FUNCTION) >> 4); NutSleep(2); // TODO: Add support for large font in single line displays /* Set number of lines and font. Can't be changed later. */ #if (LCD_ROWS == 2) || (LCD_ROWS==4) LcdWriteNibble((_BV(LCD_FUNCTION) | _BV(LCD_FUNCTION_2LINES)) >> 4); LcdWriteNibble(_BV(LCD_FUNCTION) | _BV(LCD_FUNCTION_2LINES)); #else LcdWriteNibble(_BV(LCD_FUNCTION) >> 4); LcdWriteNibble(_BV(LCD_FUNCTION) ); #endif #else /* LCD_IF_4BIT */ LcdWriteCmd(_BV(LCD_FUNCTION) | _BV(LCD_FUNCTION_8BIT)); #endif /* LCD_IF_4BIT */ NutSleep(2); /* Switch display and cursor off. */ LcdWriteNibble(_BV(LCD_ON_CTRL) >> 4); LcdWriteNibble(_BV(LCD_ON_CTRL)); NutSleep(2); /* Clear display. */ LcdClear(); /* Set entry mode. */ LcdWriteCmd(_BV(LCD_ENTRY_MODE) | _BV(LCD_ENTRY_INC)); /* Switch display on. */ LcdWriteCmd(_BV(LCD_ON_CTRL) | _BV(LCD_ON_DISPLAY)); /* Move cursor home. */ LcdCursorHome(); /* Set data address to zero. */ LcdWriteCmd(_BV(LCD_DDRAM)); return 0; }