changing to a 20 x 4 LCD

Now that my computer is at a stage where the LCD is working correctly and the code is written for 4-bit mode, a further improvement that I would like to make is to replace the LCD with a larger one, one with more columns and rows. As explained previously, what matters is the HD44780U controller. Using a single HD44780U controller, it is possible to have an LCD that is 20 x 4 – this is what I would like to use. The pinout is the same but brings its own quirks, which make sense when you understand how it is configured. Extra code will need to be written to compensate for the way that the controller was designed. When you move past the last character of the first line, you move to the first character of the third line! When you move past the last character of the third line, you move to the first character of the second line! When you move past the last character of the second line, you move to the first character of the fourth line! This might not seem logical but if you look at image 1, this should help to visualise what is happening.

20 x 4 HD44780 memory map
figure 1. 20 x 4 HD44780 memory map

These memory addresses are in hexadecimal and you can see that row one ends in 13 and row three starts at 14! This all needs to be accounted for in code:

enter
This is the structure of the program that I need to write to make enter work correctly for this LCD:

  1. What line is the cursor currently on?
  2. What line should the cursor be moved to?
  3. Move cursor

next character
I also need to account for when I am at the end of a line and the next character will need to appear at the first location of the next line.

To be able to achieve these goals, I need to be able to keep checking the location of the cursor. The way that I can do this is by looking at the DDRAM address of the LCD. DDRAM (Display Data RAM) is memory in the LCD module that stores the data that represents the character codes We can check the location of the cursor by setting the RS and RW pins of the module to 1 and then the cursor’s location will be on the data bus.

Now we need to write to the DDRAM to tell the module where to place the cursor. We want to say:

  • If cursor is at 13, move to 40.
  • If cursor is at 53, move to 14.
  • If cursor is at 27, move to 54.