Example #1
0
void Max_LCD::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 befer 4.5V so we'll wait 50
  delayMicroseconds(50000);
  lcdPins = 0x30;
  SET_E;
  SENDlcdPins();
  CLR_E;
  SENDlcdPins();
  delayMicroseconds(10000); // wait min 4.1ms
  //second try
  SET_E;
  SENDlcdPins();
  CLR_E;
  SENDlcdPins();
  delayMicroseconds(10000); // wait min 4.1ms
  // third go!
  SET_E;
  SENDlcdPins();
  CLR_E;
  SENDlcdPins();
  delayMicroseconds(10000);
  // finally, set to 4-bit interface
    lcdPins = 0x20;
    //SET_RS;
    SET_E;
    SENDlcdPins();
    //CLR_RS;
    CLR_E;
    SENDlcdPins();
    delayMicroseconds(10000);
  // 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);
}
Example #2
0
void Max_LCD::sendbyte(uint8_t val) {
        lcdPins &= 0x0f; //prepare place for the upper nibble
        lcdPins |= (val & 0xf0); //copy upper nibble to LCD variable
        SET_E; //send
        SENDlcdPins();
        delayMicroseconds(2);
        CLR_E;
        delayMicroseconds(2);
        SENDlcdPins();
        lcdPins &= 0x0f; //prepare place for the lower nibble
        lcdPins |= (val << 4) & 0xf0; //copy lower nibble to LCD variable
        SET_E; //send
        SENDlcdPins();
        CLR_E;
        SENDlcdPins();
        delayMicroseconds(100);
}