Esempio n. 1
0
/** Send data to LCD 8 or 4 bits */
void lcd_send(u8 value, u8 mode)
{
	digitalwrite(_rs_pin, mode);
  
	if (_displayfunction & LCD_8BITMODE)
	{
		lcd_write8bits(value); 
	}
	else
	{
		lcd_write4bits(value >> 4);	// Upper 4 bits first
		lcd_write4bits(value);	    // Lower 4 bits second
	}
}
Esempio n. 2
0
// write either command or data, with automatic 4/8-bit selection
void lcd_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) {
    lcd_write8bits(value); 
  } else {
    lcd_write4bits(value>>4);
    lcd_write4bits(value & 0x0F);
  }
}
Esempio n. 3
0
/** Initial Display settings! */
void lcd_begin(u8 lines, u8 dotsize)
{
    if (lines > 1)
        _displayfunction |= LCD_2LINE;

    _numlines = lines;
    _currline = 0;

    // Some one line displays can select 10 pixel high font
    if ((dotsize != 0) && (lines == 1))
        _displayfunction |= LCD_5x10DOTS;

    Delayms(15);								// Wait more than 15 ms after VDD rises to 4.5V

    // Now we pull both RS and R/W low to begin commands
    digitalwrite(_rs_pin, LOW);
    digitalwrite(_enable_pin, LOW);

    //put the LCD into 4 bit mode
    if (! (_displayfunction & LCD_8BITMODE) )
    {
        // this is according to the hitachi HD44780 datasheet p46, figure 24

        // we start in 8bit mode, try to set 4 bit mode
        lcd_write4bits(0x03);
        Delayms(5);									// Wait for more than 4.1 ms
        // second try
        lcd_write4bits(0x03);
        Delayus(150);								// Wait more than 100 μs
        // third go!
        lcd_write4bits(0x03); 
        Delayus(150);								// Wait more than 100 μs
        // finally, set to 8-bit interface
        lcd_write4bits(0x02); 
    }
    //put the LCD into 8 bit mode
    else
    {
        // this is according to the hitachi HD44780 datasheet p45, figure 23

        // Send function set command sequence
        lcd_command(LCD_FUNCTIONSET | _displayfunction);
        Delayms(5);									// Wait for more than 4.1 ms

        // second try
        lcd_command(LCD_FUNCTIONSET | _displayfunction);
        Delayms(5);									// Wait for more than 4.1 ms
        //		Delayus(150);

        // third go
        lcd_command(LCD_FUNCTIONSET | _displayfunction);
    }

    // finally, set # lines, font size, etc.
    lcd_command(LCD_FUNCTIONSET | _displayfunction);  

    // turn the display on with no cursor or blinking default
    _displaycontrol = LCD_DISPLAYON | LCD_CURSOROFF | LCD_BLINKOFF;  
    lcd_command(LCD_DISPLAYCONTROL | _displaycontrol);

    // clear it off
    lcd_command(LCD_CLEARDISPLAY);  // clear display, set cursor position to zero
    Delayms(2);

    // Initialize to default text direction (for romance languages)
    _displaymode = LCD_ENTRYLEFT | LCD_ENTRYSHIFTDECREMENT;
    // set the entry mode
    lcd_command(LCD_ENTRYMODESET | _displaymode);
}
Esempio n. 4
0
void lcd_begin(uint8_t cols, uint8_t rows) 
{
  uint8_t dotsize = LCD_5x8DOTS;

  if (rows > 1) {
    _displayfunction |= LCD_2LINE;
  }
  _numlines = rows;
  _currline = 0;

  // for some 1 line displays you can select a 10 pixel high font
  if ((dotsize != 0) && (rows == 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(_enable_pin, LOW);
  digitalWrite(_rs_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
    // page 46, figure 24

    // we may not start in 8bit mode, try to set 8 bit mode
    lcd_write4bits(0x03);
    delayMicroseconds(4500); // wait min 4.1ms

    // second try
    lcd_write4bits(0x03);
    delayMicroseconds(4500); // wait min 4.1ms
    
    // third go!
    lcd_write4bits(0x03); 
    delayMicroseconds(150);

    // finally, set to 4-bit interface
    lcd_write4bits(0x02); 

  } else {
    // this is according to the hitachi HD44780 datasheet
    // page 45 figure 23

    // Send function set command sequence
    lcd_command(LCD_FUNCTIONSET | _displayfunction);
    delayMicroseconds(4500);  // wait more than 4.1ms

    // second try
    //lcd_command(LCD_FUNCTIONSET | _displayfunction);
    delayMicroseconds(150);

    // third go
    lcd_command(LCD_FUNCTIONSET | _displayfunction);
  }

//return;

  // finally, set # lines, font size, etc.
  lcd_command(LCD_FUNCTIONSET | _displayfunction);  

  // turn the display on with no cursor or blinking default
  _displaycontrol = LCD_DISPLAYON | LCD_CURSOROFF | LCD_BLINKOFF;  
  lcd_display();

  // Initialize to default text direction (for romance languages)
  _displaymode = LCD_ENTRYLEFT | LCD_ENTRYSHIFTDECREMENT;
  // set the entry mode
  lcd_command(LCD_ENTRYMODESET | _displaymode);

  // clear it off
  lcd_clear();

}