PIC 18 LCD - Intro to LCD Displays

HD44780 Character LCD Displays— PIC Unit #02 — LCD — Episode #00

J3
Jungletronics
6 min readNov 24, 2019

--

Introduction

LCD character displays can be found in espresso machines, laser printers, children’s toys and maybe even the odd toaster:)

Fig 1. LCD industrial uses

The Hitachi HD44780 controller has become an industry standard for these types of displays.

Fig 2.Hitachi HD44780 LCD controller

This tutorial will teach you the basics of interfacing with an HD44780 compatible display using a nice LCDSim 1.0 simulator from Fred Cox and a custom spreadsheet:

Fig 3. Using Simulator and a custom spreadsheet to understand LCD:)

To run this simulator, please unzip this package and run .exe file.

Pins Configuration — Lcd 16×2 Pinout

The 16 × 2 LCD packs 32 characters into an outline smaller than that of most two-line displays. An LED backlight enables optimal viewing in all lighting conditions.

Fig 4. LCD pinout

All character LCDs have:

Eight(8) data pins D0-D7
Vcc (Apply +5 volt here)
Gnd (Ground this pin)
Rc (Register select)
Rw (read — write)
En (Enable)
V0 (Set Lcd contrast)

There are two 8-bit registers in HD44780 controller Instruction and a Data register.

Instruction register (IR) corresponds to the register where you send commands to LCD e.g LCD shift command, LCD clear, LCD address, etc. and the Data register is used for storing data which is to be displayed on LCD. when send the enable signal of the LCD is asserted, the data on the pins is latched into the data register and data is then moved automatically to the DDRAM and hence is displayed on the LCD.
Data Register is not only used for sending data to DDRAM but also for CGRAM, the address where you want to send the data, is decided by the instruction you send to LCD.

You will notice that pin 5 (RW) can be tied to the ground. This pin is used to control whether you are reading or writing to the display. Since reading from the display is very rare, most people just tie this pin to the ground.

Memories

We mount a spreadsheet to show you all the important addresses that you need to know to deal with this device.

Here is the datasheet link:

CGRAM — Character Generator RAM (0x40)

Fig 5. CGRAM firsts addresses

As clear from the name, the CGRAM area is used to create custom characters in LCD. In the character generator RAM, the user can rewrite character patterns by the program. For 5 x 8 dots, eight-character patterns can be written, and for 5 x 10 dots, four-character patterns can be written.

Now I will explain how to use the CGRAM area to make custom characters and also making animations to give nice effects to your application using the simulator.

As you can see in both the code maps, the character code from 0x00 to 0x07 is occupied by the CGRAM characters or the user-defined characters. If a user wants to display the fourth custom character then the code to display it is 0x03 i.e. when the user sends 0x03 code to the LCD DDRAM then the fourth user-created character or pattern will be displayed on the LCD.

Fig 6. Video how LCD works :)

CGROM — Character Generator ROM — ASCII TABLE

Please open mikoC PRO for PIC, go to menu Tools > Ascii Chart.

In the top region, there are non-printable characters. Mainly used for commands. Some are well known like:
LF — A line feed means moving one line forward. The code is \n.
CR — A carriage return means moving the cursor to the beginning of the line. The code is \r. Windows editors often still use the combination of both as \r\n in text files. Unix uses mostly only the \n. The separation comes from typewriter times when you turned the wheel to move the paper to change the line and moved the carriage to restart typing at the beginning of a line. This was two steps.

Now you might be thinking that when you send an ASCII value to DDRAM, how the character is displayed on LCD? so the answer is CGROM.
The character generator ROM generates 5 x 8 dot or 5 x 10 dot character patterns from 8-bit character codes (see Figure 5 and Figure 6 for more details).
It can generate 208 5 x 8 dot character patterns and 32 5 x 10 dot character patterns. User-defined character patterns are also available by mask-programmed ROM.

DDRAM — Display Data RAM (0x80)

Fig 7. DDRAM firsts addresses

Display data RAM (DDRAM) stores display data represented in 8-bit character codes. Its extended capacity is 80 X 8 bits or 80 characters. The area in display data RAM (DDRAM) that is not used for display can be used as general data RAM. So whatever you send on the DDRAM is actually displayed on the LCD. For LCDs like 1x16, 2x16 only 16 characters are visible, so whatever you write after 16 chars is written in DDRAM but is not visible to the user.

Fig 8. 16 x 2 LCD dimensions and signals

BF — Busy Flag

Busy Flag is a status indicator flag for LCD. When we send a command or data to the LCD for processing, this flag is set (i.e BF =1) and as soon as the instruction is executed successfully this flag is cleared (BF = 0). This is helpful in producing and the exact amount of delay. for the LCD processing.

To read Busy Flag, the condition RS = 0 and R/W = 1 must be met and The MSB of the LCD data bus (D7) acts as a busy flag. When BF = 1 means LCD is busy and will not accept the next command or data and BF = 0 means LCD is ready for the next command or data to process.
Instruction Register (IR) and Data Register (DR)

As we tied the RW pin to the ground, we will not probe the status of BF. In our code, we gonna make delays to deal with the timing LCD issue :/

And that’s it!

In the next lesson let’s make our first PIC’s LCD code :)

Thanks a lot! See you in the next episode.

Bye!

Download All Files for this project

Related posts

0º Episode — LCD — unit#02 — PIC 18 LCD Intro — HD44780 Character LCD Displays

1º Episode — LCD — unit#02 — PIC LCD First Print — Let’s make our first print

2º Episode — LCD — unit#02 — PIC LCD First Animation — Let’s Unveil The LCD’s Animations Techniques

3º Episode — LCD — unit#02 — PIC LCD Key & Counter — Pressing One key Increment or Pressing Other Key Decrements a Counter

4º Episode — LCD — unit#02 — PIC LCD Custom Symbols — How to Create a Custom Character on CGRAM

5º Episode — LCD — unit#02 — PIC 18 Digital Thermometer — Designing a Digital Thermometer w/ LM35

6º Episode — LCD — unit#02 — PIC 18 LCD Calculator — Let’s Make an Awesome CalculatorApp

7º Episode — LCD — unit#02 — PIC 18 LCD Keypad Discovery — Let’s Unveil Our Board Keypad

8º Episode — LCD — unit#02 — PIC 18 LCD Menu Template — Get A Nice Template For Your Menu App

References & Credits

Fred Cox page

ASCII Table

pololu/pololu-hd44780-arduino

LCD Tutorial for interfacing with Microcontrollers

The Graphic logotype on text LCD

Pololu 16x2 Character LCD Tutorial

Hitachi HD44780U (LCD-II) datasheet

Using LCD Module with AVRs from extreme electronics

Fig 9. LCD in Proteus :D

--

--

J3
Jungletronics

Hi, Guys o/ I am J3! I am just a hobby-dev, playing around with Python, Django, Ruby, Rails, Lego, Arduino, Raspy, PIC, AI… Welcome! Join us!