/*! * \brief Send half byte to LCD controller. * * \param nib The four least significant bits are sent. */ static void LcdWriteNibble(unsigned int nib) { #ifdef LCD_DATA_LSB nib <<= LCD_DATA_LSB; #else { unsigned int val = 0; if (nib & 0x01) { val |= LCD_D0; } if (nib & 0x02) { val |= LCD_D1; } if (nib & 0x04) { val |= LCD_D2; } if (nib & 0x08) { val |= LCD_D3; } nib = val; } #endif LcdSetBits(nib & LCD_DATA); LcdClrBits(~nib & LCD_DATA); /* Create Enable Pulse: * For HD44780 Displays we need: * Vcc = 5.0V -> PWeh >= 230ns * Vcc = 3.3V -> PWeh >= 500ns */ LCD_EN_SET(); NutMicroDelay(LCD_SHORT_DELAY); LCD_EN_CLR(); }
/*! * \brief Send byte to LCD controller. * * \param data Byte to send. */ static void LcdWriteByte(unsigned int data) { /* If configured set RW low */ #ifdef LCD_RW_BIT LCD_RW_CLR(); #endif /* If using 4-bit access, write two nibbles now */ #ifdef LCD_IF_4BIT LcdWriteNibble(data >> 4); LcdNanoDelay(LCD_PW_EH); LcdWriteNibble(data); #else /* else write one byte */ data <<= LCD_DATA_LSB; LcdSetBits(data & LCD_DATA); LcdClrBits(~data & LCD_DATA); #endif /* If configured, let the task sleep before next character */ #if defined(LCD_SLEEP_DLY) NutSleep(1); #else /* or add a fixed delay and immediately process next char */ NutMicroDelay(LCD_E2E_DLY); #endif }
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; }