Exemple #1
0
// initiatize lcd after a short pause
//while there are hard-coded details here of lines, cursor and blink settings, you can override these original settings after calling .init()
void LCD4Bit_mod::begin ()
{
  pinMode(Enable,OUTPUT);
  pinMode(RS,OUTPUT);
  if (USING_RW) { pinMode(RW,OUTPUT); }
  pinMode(DB[0],OUTPUT);
  pinMode(DB[1],OUTPUT);
  pinMode(DB[2],OUTPUT);
  pinMode(DB[3],OUTPUT);

  delay(50);

  //The first 4 nibbles and timings are not in my DEM16217 SYH datasheet, but apparently are HD44780 standard...
  commandWriteNibble(0x03);
  delay(5);
  commandWriteNibble(0x03);
  delayMicroseconds(100);
  commandWriteNibble(0x03);
  delay(5);

  // needed by the LCDs controller
  //this being 2 sets up 4-bit mode.
  commandWriteNibble(0x02);
  commandWriteNibble(0x02);
  //todo: make configurable by the user of this library.
  //NFXX where
  //N = num lines (0=1 line or 1=2 lines).
  //F= format (number of dots (0=5x7 or 1=5x10)).
  //X=don't care

  byte num_lines_ptn = (num_lines - 1) << 3;
  byte dot_format_ptn = 0x00;      //5x7 dots.  0x04 is 5x10

  commandWriteNibble(num_lines_ptn | dot_format_ptn);
  delayMicroseconds(60);

  //The rest of the init is not specific to 4-bit mode.
  //NOTE: we're writing full bytes now, not nibbles.

  // display control:
  // turn display on, cursor off, no blinking
  commandWrite(0x0C);
  delayMicroseconds(60);

  //clear display
  commandWrite(0x01);
  delay(3);

  // entry mode set: 06
  // increment automatically, display shift, entire shift off
  commandWrite(0x06);

  delay(1);//TODO: remove unnecessary delays
}
Exemple #2
0
// initialize LCD after a short pause
//while there are hard-coded details here of lines, cursor and blink settings, you can override these original settings after calling .init()
void LCD4Bit_mod::init() {
  // Configure pins as outputs
  setbits(CONTROL_DDR, CONTROL_EN | CONTROL_RS);
#ifdef USING_RW
  setbits(CONTROL_DDR, CONTROL_RW);
#endif
  setbits(DATA_DDR, DATA_PINS);

  delay(50);

  //The first 4 nibbles and timings are not in my DEM16217 SYH datasheet, but apparently are HD44780 standard...
  commandWriteNibble(0x03);
  delay(5);
  commandWriteNibble(0x03);
  delayMicroseconds(100);
  commandWriteNibble(0x03);
  delay(5);

  // needed by the LCDs controller
  //this being 2 sets up 4-bit mode.
  commandWriteNibble(0x02);
  commandWriteNibble(0x02);
  //todo: make configurable by the user of this library.
  //NFXX where
  //N = num lines (0=1 line or 1=2 lines).
  //F= format (number of dots (0=5x7 or 1=5x10)).
  //X=don't care

  uint8_t num_lines_ptn = g_num_lines - 1 << 3;
  uint8_t dot_format_ptn = 0x00;      //5x7 dots.  0x04 is 5x10

  commandWriteNibble(num_lines_ptn | dot_format_ptn);
  delayMicroseconds(60);

  //The rest of the init is not specific to 4-bit mode.
  //NOTE: we're writing full bytes now, not nibbles.

  // display control:
  // turn display on, cursor off, no blinking
  // 
  commandWrite(CMD_DISPLAY | CMD_DISPLAY_DISPLAY_ON/*0x0C*/);
  delayMicroseconds(60);

  //clear display
  commandWrite(CMD_CLEAR);
  delay(3);

  // entry mode set: 06
  // increment automatically, display shift, entire shift off

  commandWrite(0x06);
  delay(1);//TODO: remove unnecessary delays
}
Exemple #3
0
// initiatize lcd - cursor and blink settings could be overriden after initializing
void init_lcd() {
  pinMode(EN_PORT, EN_BIT, OUTPUT);
  pinMode(RS_PORT, RS_BIT, OUTPUT);
  set_db_pin_mode(OUTPUT);

  digitalWrite(EN_PORT, EN_BIT, 0);

  _delay_ms(20);

  //init (interface still 8-bit)
  commandWriteNibble(0x03);
  _delay_ms(5);
  commandWriteNibble(0x03);
  _delay_us(100);
  commandWriteNibble(0x03);
  _delay_us(100);

  // needed by the LCDs controller
  //this being 2 sets up 4-bit mode.
  commandWriteNibble(0x02);
  commandWriteNibble(0x02);
  //todo: make configurable by the user of this library.
  //NFXX where
  //N = num lines (0=1 line or 1=2 lines).
  //F= format (number of dots (0=5x7 or 1=5x10)).
  //X=don't care

  int num_lines_ptn = (g_num_lines - 1) << 3;
  int dot_format_ptn = 0x00;      //5x7 dots.  0x04 is 5x10

  commandWriteNibble(num_lines_ptn | dot_format_ptn);
  _delay_us(60);

  //The rest of the init is not specific to 4-bit mode.
  //NOTE: we're writing full bytes now, not nibbles.

  // display control:
  // turn display on, cursor off, no blinking
  set_display_cursor_blink(0b100);

  //clear display
  clear();

  // entry mode set: 06
  // increment automatically, display shift, entire shift off
  commandWrite(0x06);

  _delay_ms(1);//TODO: remove unnecessary delays
}
// initiatize lcd - cursor and blink settings could be overriden after initializing
void init_lcd() {
//Power-up delay
	_delay_ms(100);
	
  pinMode(EN_PORT, EN_BIT, OUTPUT);
  pinMode(RS_PORT, RS_BIT, OUTPUT);
#if USING_RW != 0
  if (USING_RW) { pinMode(RW_PORT, RW_BIT, OUTPUT); }
#endif
  pinMode(DB0_PORT, DB0_BIT,OUTPUT);
  pinMode(DB1_PORT, DB1_BIT,OUTPUT);
  pinMode(DB2_PORT, DB2_BIT,OUTPUT);
  pinMode(DB3_PORT, DB3_BIT,OUTPUT);
  digitalWrite(EN_PORT, EN_BIT, 1);
	
  commandWriteNibble(lcd_FunctionReset);	// first part of reset sequence
  _delay_ms(10);
  commandWriteNibble(lcd_FunctionReset);	// second part of reset sequence
  _delay_us(200);
  commandWriteNibble(lcd_FunctionReset);	// third part of reset sequence
  _delay_us(200);							// this delay is omitted in the data sheet
	
	commandWriteNibble(lcd_Home);
	_delay_ms(1);
	commandWriteNibble(lcd_Home);
	_delay_ms(1);
	commandWriteNibble(lcd_DisplayOn);
	_delay_us(80);
	commandWriteNibble(lcd_DisplayOff);
	_delay_us(80);
	commandWriteNibble(0x00);
	_delay_ms(1);
	commandWriteNibble(lcd_Clear);
	_delay_ms(4);
	commandWriteNibble(0x00);
	_delay_ms(1);
	commandWriteNibble(lcd_EntryMode);
	_delay_us(80);

  // needed by the LCDs controller
  //this being 2 sets up 4-bit mode.
  commandWriteNibble(lcd_Home);
  commandWriteNibble(lcd_Home);
  //todo: make configurable by the user of this library.
  //NFXX where
  //N = num lines (0=1 line or 1=2 lines).
  //F= format (number of dots (0=5x7 or 1=5x10)).
  //X=don't care

  int num_lines_ptn = (g_num_lines - 1) << 3;
  int dot_format_ptn = 0x00;      //5x7 dots.  0x04 is 5x10

  commandWrite(num_lines_ptn | dot_format_ptn | 0x20);
  _delay_us(60);

  //The rest of the init is not specific to 4-bit mode.
  //NOTE: we're writing full bytes now, not nibbles.

  // display control:
  // turn display on, cursor off, no blinking
  commandWrite(lcd_DisplayOn);
  _delay_us(60);

  //clear display
  commandWrite(lcd_Clear);
  _delay_ms(3);

  // entry mode set: 06
  // increment automatically, display shift, entire shift off
  commandWrite(lcd_EntryMode);
  _delay_ms(1);//TODO: remove unnecessary delays
   
}