// write either command or data, with automatic 4/8-bit selection void PCFCrystal::send(uint8_t value, uint8_t mode) { /* // ORIGINAL CODE digitalWrite(_rs_pin, mode); // if there is a RW pin indicated, set it low to Write if (_rw_pin != -1) { digitalWrite(_rw_pin, LOW); } */ setBit(modeBuffer(), _rs_pin, mode); // if there is a RW pin indicated, set it low to Write if (_rw_pin) { setBit(modeBuffer(), _rw_pin, LOW); } writePCF(modeAddress(), *modeBuffer()); //return; if (_displayfunction & LCD_8BITMODE) { write8bits(value); } else { write4bits(value>>4); write4bits(value); } }
// write either command or data, with automatic 4/8-bit selection void ShiftLCD::send(uint8_t value, uint8_t mode) { if (_displayfunction & LCD_8BITMODE) { write8bits(value, mode); } else { write4bits(value>>4, mode); write4bits(value, mode); } }
void LCD_Low_Level::sendData(uint8_t value, uint8_t rs_bit) { writeControl(rs_bit, 0); if (_display_function & LCD_8BitMode) { write8bits(value); } else { write4bits((value & 0xF0)>>4); write4bits(value & 0x0F); } }
// write either command or data, with automatic 4/8-bit selection void LiquidCrystal::send(uint8_t value, uint8_t mode) { digitalWrite(_rs_pin, mode); // if there is a RW pin indicated, set it low to Write if (_rw_pin != 255) { digitalWrite(_rw_pin, LOW); } if (_displayfunction & LCD_8BITMODE) { write8bits(value); } else { write4bits(value>>4); write4bits(value); } }
void LCD::send(uint8_t value, uint8_t mode) { digitalOutput(pinRS, mode); if (pinRW != 255) digitalOutput(pinRW, LOW); if (displayFunction & LCD_8BITMODE) write8bits(value); else { write4bits(value>>4); write4bits(value); } }
// write either command or data, with automatic 4/8-bit selection void LiquidCrystal::send(uint8_t value, uint8_t mode) { IO::digitalWrite(LCD_RS_PIN, mode); // if there is a RW pin indicated, set it low to Write #ifdef LCD_RW_PIN IO::digitalWrite(LCD_RW_PIN, LOW); #endif #ifdef LCD_ENABLE_8BITMODE write8bits(value); #else write4bits(value>>4); write4bits(value); #endif //LCD_ENABLE_8BITMODE }
void LiquidCrystal_I2C::begin(uint8_t cols, uint8_t lines, uint8_t dotsize) { if (lines > 1) { _displayfunction |= LCD_2LINE; } _numlines = lines; // for some 1 line displays you can select a 10 pixel high font if ((dotsize != 0) && (lines == 1)) { _displayfunction |= LCD_5x10DOTS; } // SEE PAGE 45/46 FOR INITIALIZATION SPECIFICATION! // according to datasheet, we need at least 40ms after power rises above 2.7V // before sending commands. Arduino can turn on way befer 4.5V so we'll wait 50 delay(50); // Now we pull both RS and R/W low to begin commands expanderWrite(_backlightval); // reset expanderand turn backlight off (Bit 8 =1) delay(1000); //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 write4bits(0x03 << 4); delayMicroseconds(4500); // wait min 4.1ms // second try write4bits(0x03 << 4); delayMicroseconds(4500); // wait min 4.1ms // third go! write4bits(0x03 << 4); delayMicroseconds(150); // finally, set to 4-bit interface write4bits(0x02 << 4); // set # lines, font size, etc. command(LCD_FUNCTIONSET | _displayfunction); // turn the display on with no cursor or blinking default _displaycontrol = LCD_DISPLAYON | LCD_CURSOROFF | LCD_BLINKOFF; display(); // clear it off clear(); // Initialize to default text direction (for roman languages) _displaymode = LCD_ENTRYLEFT | LCD_ENTRYSHIFTDECREMENT; // set the entry mode command(LCD_ENTRYMODESET | _displaymode); home(); }
void CleanCrystal::begin() { delayMicroseconds(50000); digitalWrite(LCD_PIN_RESET, LOW); digitalWrite(LCD_PIN_ENABLE, LOW); write4bits(0x03); delayMicroseconds(4500); // wait min 4.1ms write4bits(0x03); delayMicroseconds(4500); // wait min 4.1ms write4bits(0x03); delayMicroseconds(150); write4bits(0x02); // finally, set # lines, font size, etc. command(LCD_FUNCTIONSET | LCD_4BITMODE | LCD_2LINE | LCD_5x8DOTS); // turn the display on with no cursor or blinking default _displaycontrol = LCD_DISPLAYON | LCD_CURSOROFF | LCD_BLINKOFF; display(); // clear it off clear(); // Initialize to default text direction (for romance languages) _displaymode = LCD_ENTRYLEFT | LCD_ENTRYSHIFTDECREMENT; // set the entry mode command(LCD_ENTRYMODESET | _displaymode); }
void SpiLcd::begin(uint8_t cols, uint8_t lines) { _numlines = lines; _currline = 0; _currpos = 0; // Set all outputs of shift register to low, this turns the backlight ON. _spiByte = 0x00; spiOut(); // The following initialization sequence should be compatible with: // - Newhaven OLED displays // - Standard HD44780 or S6A0069 LCD displays delayMicroseconds(50000); // wait 50 ms just to be sure that the lcd is initialized write4bits(0x03); //set to 8-bit delayMicroseconds(50000); // wait > 4.1ms write4bits(0x03); //set to 8-bit delayMicroseconds(1000); // wait > 100us write4bits(0x03); //set to 8-bit delayMicroseconds(50000); // wait for execution write4bits(0x02); //set to 4-bit delayMicroseconds(50000); // wait for execution command(0x28); // set to 4-bit, 2-line clear(); // display clear // Entry Mode Set: leftToRight(); noAutoscroll(); home(); //noCursor(); display(); }
void LiquidCrystal::begin(uint8_t cols, uint8_t lines, uint8_t dotsize) { if (lines > 1) { _displayfunction |= LCD_2LINE; } _numlines = lines; _currline = 0; // for some 1 line displays you can select a 10 pixel high font if ((dotsize != 0) && (lines == 1)) { _displayfunction |= LCD_5x10DOTS; } // SEE PAGE 45/46 FOR INITIALIZATION SPECIFICATION! // according to datasheet, we need at least 40ms after power rises above 2.7V // before sending commands. Arduino can turn on way before 4.5V so we'll wait 50 delayMicroseconds(50000); // Now we pull both RS and R/W low to begin commands digitalWrite(_rs_pin, LOW); digitalWrite(_enable_pin, LOW); if (_rw_pin != 255) { digitalWrite(_rw_pin, LOW); } //put the LCD into 4 bit or 8 bit mode if (! (_displayfunction & LCD_8BITMODE)) { // this is according to the hitachi HD44780 datasheet // figure 24, pg 46 // we start in 8bit mode, try to set 4 bit mode write4bits(0x03); delayMicroseconds(4500); // wait min 4.1ms // second try write4bits(0x03); delayMicroseconds(4500); // wait min 4.1ms // third go! write4bits(0x03); delayMicroseconds(150); // finally, set to 4-bit interface write4bits(0x02); } else { // this is according to the hitachi HD44780 datasheet // page 45 figure 23 // Send function set command sequence command(LCD_FUNCTIONSET | _displayfunction); delayMicroseconds(4500); // wait more than 4.1ms // second try command(LCD_FUNCTIONSET | _displayfunction); delayMicroseconds(150); // third go command(LCD_FUNCTIONSET | _displayfunction); } // finally, set # lines, font size, etc. command(LCD_FUNCTIONSET | _displayfunction); // turn the display on with no cursor or blinking default _displaycontrol = LCD_DISPLAYON | LCD_CURSOROFF | LCD_BLINKOFF; display(); // clear it off clear(); // Initialize to default text direction (for romance languages) _displaymode = LCD_ENTRYLEFT | LCD_ENTRYSHIFTDECREMENT; // set the entry mode command(LCD_ENTRYMODESET | _displaymode); }
void PCF8574_HD44780_I2C::begin(uint8_t cols, uint8_t lines, uint8_t dotsize) { if (lines > 1) { _displayfunction |= LCD_2LINE; } _numlines = lines; // for some 1 line displays you can select a 10 pixel high font if ((dotsize != 0) && (lines == 1)) { _displayfunction |= LCD_5x10DOTS; } // SEE PAGE 45/46 FOR INITIALIZATION SPECIFICATION! // according to datasheet, we need at least 40ms after power rises above 2.7V // before sending commands. Arduino can turn on way befer 4.5V so we'll wait 50 delay(50); // !NOT NECESSARY! // // Now we pull both RS and R/W low to begin commands //expanderWrite(_backlightval); // reset expanderand turn backlight off (Bit 8 =1) - _backlightval = LCD_NOBACKLIGHT; //delay(1000); // put the LCD into 4 bit mode // this is according to the hitachi HD44780 datasheet // figure 24, pg 46 // LCD automatically start in 8bit mode, but we manually repeat // the 8bit initialization instructions for safety write4bits(_BV(P4) | _BV(P5)); delay(5); // wait min 4.1ms write4bits(_BV(P4) | _BV(P5)); delayMicroseconds(150); // wait min 100us write4bits(_BV(P4) | _BV(P5)); // !NOT NECESSARY! // //delayMicroseconds(150); // Set interface to be 4 bits long write4bits(_BV(P5)); // set # lines, font size, etc. command(LCD_FUNCTIONSET | _displayfunction); // turn the display on with no cursor or blinking default _displaycontrol = LCD_DISPLAYON | LCD_CURSOROFF | LCD_BLINKOFF; display(); // clear it off clear(); // Initialize to default text direction (for roman languages) _displaymode = LCD_ENTRYLEFT | LCD_ENTRYSHIFTDECREMENT; // set the entry mode command(LCD_ENTRYMODESET | _displaymode); home(); }
void LCD::begin(uint8_t cols, uint8_t rows, uint8_t charsize) { if (rows > 1) { displayFunction |= LCD_2LINE; } numLines = rows; setRowOffsets(0x00, 0x40, 0x00 + cols, 0x40 + cols); if ((charsize != LCD_5x8DOTS) && (rows == 1)) { displayFunction |= LCD_5x10DOTS; } pinMode(pinRS, OUTPUT); pinMode(pinE, OUTPUT); if (pinRW != 255) pinMode(pinRW, OUTPUT); for (int i=0; i<((displayFunction & LCD_8BITMODE) ? 8 : 4); ++i) pinMode(pinData[i], OUTPUT); _delay_us(50000); digitalOutput(pinRS, LOW); digitalOutput(pinE, LOW); if (pinRW != 255) digitalOutput(pinRW, LOW); if (! (displayFunction & LCD_8BITMODE)) { write4bits(0x03); _delay_us(4500); write4bits(0x03); _delay_us(4500); write4bits(0x03); _delay_us(150); write4bits(0x02); } else { command(LCD_FUNCTIONSET | displayFunction); _delay_us(4500); command(LCD_FUNCTIONSET | displayFunction); _delay_us(150); command(LCD_FUNCTIONSET | displayFunction); } command(LCD_FUNCTIONSET | displayFunction); displayControl = LCD_DISPLAYON | LCD_CURSOROFF | LCD_BLINKOFF; display(); clear(); displayMode = LCD_ENTRYLEFT | LCD_ENTRYSHIFTDECREMENT; command(LCD_ENTRYMODESET | displayMode); }
void ControLeo_LiquidCrystal::begin(uint8_t cols, uint8_t lines, uint8_t dotsize) { // Start I2C _i2c.begin(); // Turn on the backlight setBacklight(HIGH); if (lines > 1) _displayfunction |= LCD_2LINE; _numlines = lines; _currline = 0; // For some 1 line displays you can select a 10 pixel high font if ((dotsize != 0) && (lines == 1)) { _displayfunction |= LCD_5x10DOTS; } // SEE PAGE 45/46 FOR INITIALIZATION SPECIFICATION! // According to datasheet, we need at least 40ms after power rises above 2.7V // before sending commands. Arduino can turn on way befer 4.5V so we'll wait 50 delayMicroseconds(50000); // Now we pull both RS and R/W low to begin commands _i2c.digitalWrite(_rs_pin, LOW); _i2c.digitalWrite(_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 write4bits(0x03); delayMicroseconds(4500); // wait min 4.1ms // Second try write4bits(0x03); delayMicroseconds(4500); // wait min 4.1ms // Third go! write4bits(0x03); delayMicroseconds(150); // Finally, set to 8-bit interface write4bits(0x02); // Finally, set # lines, font size, etc. command(LCD_FUNCTIONSET | _displayfunction); // Turn the display on with no cursor or blinking default _displaycontrol = LCD_DISPLAYON | LCD_CURSOROFF | LCD_BLINKOFF; display(); // Clear the display clear(); // Initialize to default text direction (for romance languages) _displaymode = LCD_ENTRYLEFT | LCD_ENTRYSHIFTDECREMENT; // Set the entry mode command(LCD_ENTRYMODESET | _displaymode); }
// write either command or data uint8_t LiquidCrystal_I2C::send(uint8_t value, uint8_t mode) { uint8_t ret; uint8_t highnib=value&0xf0; uint8_t lownib=(value<<4)&0xf0; ret = write4bits((highnib)|mode); if (ret != 0) return (ret); return write4bits((lownib)|mode); }
// // send - write either command or data void LiquidCrystal_I2C::send(uint8_t value, uint8_t mode) { // No need to use the delay routines since the time taken to write takes // longer that what is needed both for toggling and enable pin an to execute // the command. if (mode == FOUR_BITS) { write4bits( (value & 0xf), COMMAND ); } else { write4bits(value >> 4, mode); write4bits(value & 0xf, mode); } }
void OLEDFourBit::begin(uint8_t cols, uint8_t lines) { _numlines = lines; _currline = 0; pinMode(_rs_pin, OUTPUT); pinMode(_rw_pin, OUTPUT); pinMode(_enable_pin, OUTPUT); digitalWrite(_rs_pin, LOW); digitalWrite(_enable_pin, LOW); digitalWrite(_rw_pin, LOW); // SEE PAGE 20 of NHD-0420DZW-AY5 delayMicroseconds(50000); // wait 50 ms just to be sure tha the lcd is initialized // Now we pull both RS and R/W low to begin commands for (int i = 0; i < 4; i++) { pinMode(_data_pins[i], OUTPUT); digitalWrite(_data_pins[i], LOW); } delayMicroseconds(100000); write4bits(0x03); delayMicroseconds(100000); write4bits(0x02); delayMicroseconds(10000); write4bits(0x02); delayMicroseconds(10000); write4bits(0x08); //command(0x28); delayMicroseconds(10000); command(0x08); // Display off delayMicroseconds(10000); command(0x01); // display clear delayMicroseconds(10000); command(0x06); // Entry Mode Set: delayMicroseconds(10000); command(0x02); // Home delayMicroseconds(10000); command(0x0C); // display on/ cursor on/ cursor blink delayMicroseconds(10000); defineCustomCharacters(); // write custom characters to OLED }
// write either command or data, with automatic 4/8-bit selection void LiquidCrystal::send(uint8_t value, uint8_t mode) { s2pdriver.set(SR_RS, mode); s2pdriver.write(); write4bits(value>>4); write4bits(value); }
// write either command or data void OLEDFourBit::send(uint8_t value, uint8_t mode) { digitalWrite(_rs_pin, mode); pinMode(_rw_pin, OUTPUT); digitalWrite(_rw_pin, LOW); write4bits(value>>4); write4bits(value); }
void CleanCrystal::print(const char * value) { digitalWrite(LCD_PIN_RESET, HIGH); for (_bufferPos = 0; _bufferPos < 16; _bufferPos++) { if (value[_bufferPos] == '\0') return; write4bits(value[_bufferPos]>>4); write4bits(value[_bufferPos]); _cursorPos++; } }
void CleanCrystal::print(int value, char precede) { digitalWrite(LCD_PIN_RESET, HIGH); _bufferPos = (value / 10000); if (_bufferPos || (precede > 3)) { _bufferPos += '0'; write4bits(_bufferPos>>4); write4bits(_bufferPos); _cursorPos++; }
// write either command or data void LiquidCrystal::send(uint8_t value, uint8_t mode) { #if defined(__AVR_ATmega1284P__) || defined(__AVR_ATmega1284__) if (_type == LCD_I2C) { uint8_t highnib=value&0xf0; uint8_t lownib=(value<<4)&0xf0; write4bits((highnib)|mode); write4bits((lownib)|mode); } #endif if (_type == LCD_STD) { digitalWrite(_rs_pin, mode); // if there is a RW pin indicated, set it low to Write if (_rw_pin != 255) { digitalWrite(_rw_pin, LOW); } write4bits(value>>4); write4bits(value); }
// write either command or data void SpiLcd::send(uint8_t value, uint8_t mode) { if(mode){ bitSet(_spiByte, LCD_SHIFT_RS); } else{ bitClear(_spiByte, LCD_SHIFT_RS); } spiOut(); write4bits(value>>4); write4bits(value); }
// static declarations static upm_result_t send(const lcm1602_context dev, uint8_t value, int mode) { assert(dev != NULL); uint8_t h; uint8_t l; upm_result_t rv = UPM_SUCCESS; if (dev->isI2C) { h = value & 0xf0; l = (value << 4) & 0xf0; if (write4bits(dev, h | mode)) rv = UPM_ERROR_OPERATION_FAILED; if (write4bits(dev, l | mode)) rv = UPM_ERROR_OPERATION_FAILED; return rv; } // else, gpio (4 bit) // register select if (mraa_gpio_write(dev->gpioRS, mode)) { printf("%s: mraa_gpio_write() failed\n", __FUNCTION__); rv = UPM_ERROR_OPERATION_FAILED; } h = value >> 4; l = value & 0x0f; if (write4bits(dev, h)) rv = UPM_ERROR_OPERATION_FAILED; if (write4bits(dev, l)) rv = UPM_ERROR_OPERATION_FAILED; return rv; }
// write either command or data, with automatic 4/8-bit selection void PortDLCD::send(uint8_t value, uint8_t mode) { //digitalWrite(_rs_pin, mode); if (mode) { PORTD |= (1 << RS_PIN); } else { PORTD &= ~(1 << RS_PIN); } write4bits(value>>4); write4bits(value); }
// write either command or data, with automatic 4/8-bit selection void LiquidCrystal::send(unsigned char value, bool mode) { if (this->realTimeDisplay) { if (mode) { SET(_rs_pin); } else { RESET(_rs_pin); } write4bits(value >> 4); pulseEnable(1); write4bits(value); pulseEnable(delayAfterCommand); } else { if (!lcdActions.isFull()) {
void LiquidCrystalNew_T3TWI::initChip(uint8_t dotsize, byte witchEnablePin) { byte displayfunction = LCD_4BITMODE | LCD_1LINE | LCD_5x8DOTS; byte i; if (_lcd_lines > 1) displayfunction |= LCD_2LINE; // for some 1 line displays you can select a 10 pixel high font if ((dotsize != 0) && (_lcd_lines == 1)) displayfunction |= LCD_5x10DOTS; for (i=0;i<18;i++) { delayMicroseconds(LCD_STARTUP_DLY); } setDataMode(0);//COMMAND MODE writeGpio(_theData & ~witchEnablePin); // En LOW---------------------------------------*/ write4bits(0x03); delayMicroseconds(5000); // I have one LCD for which 4500 here was not long enough. // second try write4bits(0x03); delayMicroseconds(150); // wait // third go! write4bits(0x03); delayMicroseconds(150); // finally, set to 4-bit interface write4bits(0x02); delayMicroseconds(150); // finally, set # lines, font size, etc. command(LCD_FUNCTIONSET | displayfunction); // turn the display on with no cursor or blinking default _displaycontrol = LCD_DISPLAYON | LCD_CURSOROFF | LCD_BLINKOFF; display(); // clear it off clear(); // Initialize to default text direction (for romance languages) _displaymode = LCD_ENTRYLEFT | LCD_ENTRYSHIFTDECREMENT; // set the entry mode command(LCD_ENTRYMODESET | _displaymode); noAutoscroll(); }
void LiquidCrystal_EADIP204_6::begin(uint8_t dotsize) { // _displayfunction |= LCD_2LINE; setRowOffsets(0x00, 0x20, 0x40, 0x60); pinMode(_rs_pin, OUTPUT); // we can save 1 pin by not using RW. Indicate by passing 255 instead of pin# if (_rw_pin != 255) { pinMode(_rw_pin, OUTPUT); } pinMode(_enable_pin, OUTPUT); // Do these once, instead of every time a character is drawn for speed reasons. for (int i=0; i<((_displayfunction & LCD_8BITMODE) ? 8 : 4); ++i) { pinMode(_data_pins[i], OUTPUT); } // SEE PAGE 45/46 FOR INITIALIZATION SPECIFICATION! // according to datasheet, we need at least 40ms after power rises above 2.7V // before sending commands. Arduino can turn on way before 4.5V so we'll wait 50 delayMicroseconds(50000); // Now we pull both RS and R/W low to begin commands digitalWrite(_rs_pin, LOW); digitalWrite(_enable_pin, LOW); if (_rw_pin != 255) { digitalWrite(_rw_pin, LOW); } //put the LCD into 4 bit or 8 bit mode if (! (_displayfunction & LCD_8BITMODE)) { // this is according to the hitachi HD44780 datasheet // figure 24, pg 46 // we start in 8bit mode, try to set 4 bit mode write4bits(0x03); delayMicroseconds(4500); // wait min 4.1ms // second try write4bits(0x03); delayMicroseconds(4500); // wait min 4.1ms // third go! write4bits(0x03); delayMicroseconds(150); // finally, set to 4-bit interface write4bits(0x02); delayMicroseconds(4500); command(LCD_FSET | LCD_RE); //function set RE=1 lcd.command (0x24) / / delayMicroseconds(4500); command(LCD_4L5DF); delayMicroseconds(4500); command(LCD_SETCGRAMADDR); delayMicroseconds(4500); for (int i = 0; i < 16; ++i) { send(LCD_SYM_MODE_OFF, HIGH); } delayMicroseconds(4500); command(LCD_FSET); delayMicroseconds(4500); delayMicroseconds(4500); } else { // this is according to the hitachi HD44780 datasheet // page 45 figure 23 // Send function set command sequence command(LCD_FUNCTIONSET | _displayfunction); delayMicroseconds(4500); // wait more than 4.1ms // second try command(LCD_FUNCTIONSET | _displayfunction); delayMicroseconds(150); // third go command(LCD_FUNCTIONSET | _displayfunction); } // finally, set # lines, font size, etc. // command(LCD_FUNCTIONSET | _displayfunction); // turn the display on with no cursor or blinking default _displaycontrol = LCD_DISPLAYON | LCD_CURSOROFF | LCD_BLINKOFF; display(); // clear it off clear(); // Initialize to default text direction (for romance languages) _displaymode = LCD_ENTRYLEFT | LCD_ENTRYSHIFTDECREMENT; // set the entry mode command(LCD_ENTRYMODESET | _displaymode); }
// write either command or data void LiquidCrystal_I2C::send(uint8_t value, uint8_t mode) { uint8_t highnib=value&0xf0; uint8_t lownib=(value<<4)&0xf0; write4bits((highnib)|mode); write4bits((lownib)|mode); }
void LCD_Low_Level::begin(uint8_t columns, uint8_t rows, uint8_t dotsize) { if (rows > 1) { _display_function |= LCD_2Line; } if ((dotsize != LCD_5x8Dots) && (rows == 1)) { _display_function |= LCD_5x10Dots; } pinMode(_rs_pin, OUTPUT); pinMode(_rw_pin, OUTPUT); pinMode(_enable_pin, OUTPUT); // According to datasheet, we need at least 40ms after power rises above 2.7V // before sending commands. Wait 50ms to be safe. delayMicroseconds(50000); // Pull RS and RW low to begin sending commands digitalWrite(_rs_pin, LOW); digitalWrite(_rw_pin, LOW); // Put the LCD into 4 bit or 8 bit mode if (! (_display_function & LCD_8BitMode)) { // LCD starts in 8-bit mode. Try to set 4 bit mode write4bits(0x03); delayMicroseconds(4500); // wait min 4.1 ms // Second try write4bits(0x03); delayMicroseconds(4500); // wait min 4.1 ms // Third try write4bits(0x03); delayMicroseconds(150); // Fourth try will set the LCD to 4-bit interface write4bits(0x02); } else { // Send function set command sequence command(LCD_FunctionSet | _display_function); delayMicroseconds(4500); // wait more than 4.1 ms // Second try command(LCD_FunctionSet | _display_function); delayMicroseconds(150); // Third try command(LCD_FunctionSet | _display_function); } // Set # lines, font size, etc command(LCD_FunctionSet | _display_function); // turn the display on with no cursor or blinking default displayControl(LCD_DisplayOn, LCD_CursorOff, LCD_BlinkOn); // Clear the display clearDisplay(); // Initialize default text direction for romance language entrySetMode(LCD_CursorRight, LCD_DisplayLeft); }
lcm1602_context lcm1602_i2c_init(int bus, int address, bool is_expander, uint8_t num_columns, uint8_t num_rows) { lcm1602_context dev = (lcm1602_context)malloc(sizeof(struct _lcm1602_context)); if (!dev) return NULL; memset((void *)dev, 0, sizeof(struct _lcm1602_context)); // make sure MRAA is initialized int mraa_rv; if ((mraa_rv = mraa_init()) != MRAA_SUCCESS) { printf("%s: mraa_init() failed (%d).\n", __FUNCTION__, mraa_rv); lcm1602_close(dev); return NULL; } // initialize the MRAA context if (!(dev->i2c = mraa_i2c_init(bus))) { printf("%s: mraa_i2c_init failed.\n", __FUNCTION__); lcm1602_close(dev); return NULL; } // now check the address... if (mraa_i2c_address(dev->i2c, address) != MRAA_SUCCESS) { printf("%s: mraa_i2c_address failed.\n", __FUNCTION__); lcm1602_close(dev); return NULL; } dev->isI2C = true; dev->backlight = HD44780_BACKLIGHT; dev->columns = num_columns; dev->rows = num_rows; // if we are not dealing with an expander we will only initialize // the I2C context and bail, leaving it up to the caller to handle // further communications (like JHD1313M1) if (!is_expander) return dev; upm_delay_us(50000); lcm1602_backlight_on(dev, true); upm_delay_us(100000); // try to put us into 4 bit mode write4bits(dev, 0x03 << 4); upm_delay_us(4500); write4bits(dev, 0x30); upm_delay_us(4500); write4bits(dev,0x30); upm_delay_us(150); // Put us into 4 bit mode, for realz yo. write4bits(dev, 0x20); // Set number of lines lcm1602_command(dev, HD44780_FUNCTIONSET | 0x0f); // default display control dev->displayControl = HD44780_DISPLAYON | HD44780_CURSOROFF | HD44780_BLINKOFF; lcm1602_command(dev, HD44780_DISPLAYCONTROL | dev->displayControl); upm_delay_us(2000); lcm1602_clear(dev); // Set entry mode. dev->entryDisplayMode = HD44780_ENTRYLEFT | HD44780_ENTRYSHIFTDECREMENT; lcm1602_command(dev, HD44780_ENTRYMODESET | dev->entryDisplayMode); lcm1602_home(dev); return dev; }