LCD 20X4 Without using Liquid Crystal Library

Hi guys, anyone know how to initialize a 20x4 LCD in the arduino?. We really dont have any idea how to code it :frowning: our teacher said we will not use liquid crystal library. He said that at least one letter display only. pls teach me :frowning: I cant find any resources online. TIA

Without using any IC or Shift Register

Option a) Use a different library. Easy but probably not what your teacher want you to do....

Option b) Start reading the datasheet of the HD44780 which is on every 20x4 standard display.

We do sometimes do homework problems but we must insist that we be given full reign of the question. Post your teachers name and email in case we have specific questions about the homework we are doing for you. It always sucks trying to do homework when you can't speak to the teacher. Surely your teacher knows that your coming here to get your homework done so he or she won't mind us asking.

If you can't give us the teacher because you think the teacher might call this cheating then you need to do your own damn homework.

xmaspoke13245:
I cant find any resources online

Then you didn't look:

http://lmgtfy.com/?q=how+does+hd44780+work

Everything you need to know about initialization is in the spec sheet and liquid crystals library's begin function:

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);

}

There are lots of comments to help you with the code. Now you just have to find the spec sheets to cross reference and understand.

liudr:
Everything you need to know about initialization is in the spec sheet and liquid crystals library's begin function:

I would not recommend looking at the LiquidCrystal library or using it as a model to understand how the hd44780 interface works.
The datasheet is very clear and even has nice table for how to do initialization.
The LiquidCrystal code supports both 4 and 8 bit mode and has a full API which is overkill for this class exercise; plus, there are several cases in the LiquidCrystal code where the comments are just plain wrong as to what is really happening or what needs to be done. And there are a few places in the code where the code is not correctly following the hd44780 datasheet.

I'm assuming that this exercise is for some sort of EE or CE type class and that the point of the exercise to try get students used to reading and understanding datasheets to help prepare them for the real word.
In this case the part is fairly simple so the datasheet is fairly straight forward and the code to communicate with the LCD including for initialization is fairly straight forward, especially if using 8 bit mode.

--- bill

xmaspoke13245:
our teacher said we will not use liquid crystal library. He said that at least one letter display only. pls teach me

Going OT here, sorry.

As an educator myself I'm very much in favour of project work which involves research. But on the other hand, teachers do, by definition, need to teach. It's a very fine line between giving enough info and advice and clues up front to get the student off and going with the project, and abrogating the responsibility of teaching to the interwebz.

I'm wondering how much teaching this teacher does?

xmaspoke13245:
Without using any IC or Shift Register

I doubt if you can get a 20x4 LCD that doesn't come with an integrated IC for handling the display. If there was no integrated display handler, you would require in the worst case, with no multiplexing, one wire exposed per pixel ( say 20 x 4 x 7 x 5 = 2800). With multiplexing at the single character granularity, you'd still require 80 + 35 = 115 wires exposed.

6v6gt:
I doubt if you can get a 20x4 LCD that doesn't come with an integrated IC for handling the display.

I'm assuming that means that the requirement is to drive the hd44780 module pins directly vs say use a shift register or a PCF8574 to interface the host/Arduino to the module.

xmaspoke13245 also said:

He said that at least one letter display only.

It is quite trivial to print a single character on a hd44780 display using direct pin control and 8 bit mode.
This is a very simple exercise as it only requires knowledge of how the host interface transfers bytes to the module and that information is easily found in the datasheet.

--- bill