コード例 #1
0
void LiquidCrystal::begin(uint8_t cols, uint8_t lines, uint8_t dotsize) {
  _displayfunction |= LCD_2LINE;
  _numlines = lines;

  setRowOffsets(0x00, 0x40, 0x00 + cols, 0x40 + cols);  

  // Now we pull both RS and R/W low to begin commands
  digitalWrite(_rs_pin, LOW);
  digitalWrite(_enable_pin, LOW);
  digitalWrite(_rw_pin, LOW);
  
  // Send function set command sequence
  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);

}
コード例 #2
0
ファイル: LCD.cpp プロジェクト: Enigma0960/AVR_Clock
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);
}
コード例 #3
0
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);
}
コード例 #4
0
ファイル: LiquidCrystal.cpp プロジェクト: Alejandroem/Arduino
void LiquidCrystal::begin(uint8_t cols, uint8_t lines, uint8_t dotsize) {
  if (lines > 1) {
    _displayfunction |= LCD_2LINE;
  }
  _numlines = lines;

  setRowOffsets(0x00, 0x40, 0x00 + cols, 0x40 + cols);  

  // for some 1 line displays you can select a 10 pixel high font
  if ((dotsize != LCD_5x8DOTS) && (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);

}