Hi Guys this is my first tutorial on zemebdded site, please encourage me by commenting and making my write up more accurate and use full for newcomers in embedded field. Thanks to zemebdded admin for accepting this write up and publishing here. Hope you guys like this and with your appreciation I will be keep on writing more.
Evergreen LCD 16×2 is very easy to interface to almost any microcontroller irrespective to 8bit or 32 bit. An LCD can be a great addition to any project, specifically if you are in embedded development in an early stage of your carrier. In this tutorial we are going to understand in depth interfacing of 16×2 LCD commonly called HD44780 LCD. This is very handy and easily available with your local electronic dealers, and most important thing is easily affordable.
This tutorial Is divided in three sections:
- In first section we are going discuss about HD44780 hardware, Pin out and registers.
- In second section we are dig in deep with different memories blocks and command line
- In third and last section we will be interfacing LCD with Atmega16. I hope we will be creating our own library.
LCD is based on the HD44780 microcontroller (Hitachi) and can display messages in two lines with 16 characters each. It can display all the letters of alphabet, Greek letters, punctuation marks, mathematical symbols etc on a miniature liquid crystal display. It is also possible to display symbols made up by the user. Other useful features include automatic message shift (left and right), cursor appearance, LED backlight etc.
How LCD works?
An LCD (Liquid Crystal Display) basically works on the concept of Light Polarization of a ‘Liquid Crystal’ under the influence of an Electric Field. Every LCD contains a Back-Light behind the Liquid Crystal array, which acts as a light source. When an Electric Field is applied across certain fluids, it changes the way they allow light to pass through them, that is, it changes the orientation of the liquid crystal molecules as a result they do not allow light to pass through them.
Hence, by applying suitable potential difference, we can control if light passes or doesn’t pass through the LCD pixels.
LCD 16×2 can be interfaced in two different modes:
- 8-bit Mode
- In 8-bit mode pins from 7 to 14 (total 8 pins) are connected to eight I/o pins of microcontroller. Hence for this interface we need eight I/O pins. The advantage to operating in 8-bit mode is that the programming is a bit simpler and data can be updated more quickly.
- 4-bit mode
- In 4-bit mode pins from 11 to 14 (total 4 pins) are connected to four I/O pins of microcontroller. Hence for this interface we need only four I/O pins. The main reason to operate in 4-bit mode is to save four I/O pins.
There is one more way we can interface this LCD by using shift register, which is normally called three wire interface. In future we are going to add that tutorial on zembedded site.
Let’s check the pin out for HD44780:
VSS, VDD and VEE
These three pins are numbered 1, 2 and 3 respectively. Pin 1 (VSS) is a ground pin and it is certainly needed that this pin should be grounded for LCD to work properly. VEE and VDD are given +5 Volt’s normally. However VEE can have a potentiometer voltage divider network to adjust the contrast of LCD. As we knew VDD is always at +5V.
RS, R/W and E
As shown in image these three pins are numbered 4, 5 and 6. RS is used to make the selection between data and command register. For RS=0, command register is selected and for RS=1 data register is selected.
R/W gives you the choice between writing and reading. If set (R/W=1) reading is enabled. R/W=0 when writing.
Enable pins is used by the LCD to latch information presented to its data pins. When data is supplied to data pins, a high to low pulse must be applied to this pin in-order for the LCD to latch in the data present at the data pins. It may be noted here that the pulse must be of minimum 450ns wide.
The 8-bit data pins, D0-D7, are used to send information to the LCD or read the contents of LCD’s internal register.
The DR (Data Register) acts as a buffer, it temporarily stores data to be written into as well as read from DDRAM or CGRAM memory blocks. Data written into the DR is automatically written into DDRAM or CGRAM by an internal operation. The DR is also used for data storage when reading data from DDRAM or CGRAM.
The IR (Instruction Register) stores instruction codes, such as display clear and cursor shift, and address information for display data RAM (DDRAM) and character generator RAM (CGRAM).
As shown in the table, when reading or writing data, the register select (RS) line is always high; when reading the busy flag or writing a command, the RS line is always low.
Reading or writing to RAM:
When reading DDRAM or CGRAM data, or the busy flag, from the LCD, the R/W line is made high; when writing data to the DR register or commands to the IR register, the R/W line is made low. Should you decide to only write to the LCD and never read from it, you can save an I/O pin on your microcontroller by connecting the R/W line to directly to the ground.
After each read or write, the address counter on the HD44780 is automatically incremented or decremented, depending on whether you set the cursor moving right or left, respectively. This saves a lot of address writes to the LCD, since you only have to write the “set DDRAM (or CGRAM) address” instruction for the first byte, instead of having to write the address of each byte every time.
To write an instruction:
set the RW and RS control lines to the appropriate level, put the data or command on the I/O pins (by changing their logic levels), then toggle the EN line from low to high to low. The HD44780 latches data on the falling edge on the EN line.
In next tutorial we are going to see in depth access of different memory blocks and command lines. HD44780 datasheet link is providing below, this tutorial is a result to the study of hundreds of different tutorial from internet. I am thankful the internet community for sharing all those wonderful information with us. Please do read second section of this tutorial …thanks!