Liquid Crystal Display also called as LCD is very helpful in providing user interface as well as for debugging purpose. The most common type of LCD controller is HITACHI 44780 which provides a simple interface between the controller & an LCD. |
|||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||
These LCD's are very simple to interface with the controller as well as are cost effective. The most commonly used ALPHANUMERIC displays are 1x16 (Single Line & 16 characters), 2x16 (Double Line & 16 character per line), 4x20 (four lines & Twenty characters per line). |
|||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||
The LCD requires 3 control lines (RS, R/W & EN) & 8 (or 4) data lines. The number on data lines depends on the mode of operation. If operated in 8-bit mode then 8 data lines + 3 control lines i.e. total 11 lines are required. And if operated in 4-bit mode then 4 data lines + 3 control lines i.e. 7 lines are required. How do we decide which mode to use? It’s simple if you have sufficient data lines you can go for 8 bit mode & if there is a time constrain i.e. display should be faster then we have to use 8-bit mode because basically 4-bit mode takes twice as more time as compared to 8-bit mode. |
|||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||
When RS is low (0), the data is to be treated as a command. When RS is high (1), the data being sent is considered as text data which should be displayed on the screen. |
|||||||||||||||||||||||||||||||
When R/W is low (0), the information on the data bus is being written to the LCD. When RW is high (1), the program is effectively reading from the LCD. Most of the times there is no need to read from the LCD so this line can directly be connected to Gnd thus saving one controller line. |
|||||||||||||||||||||||||||||||
The ENABLE pin is used to latch the data present on the data pins. A HIGH - LOW signal is required to latch the data. The LCD interprets and executes our command at the instant the EN line is brought low. If you never bring EN low, your instruction will never be executed.
|
|||||||||||||||||||||||||||||||
For Contrast setting a 10K pot should be used as shown in the figure. |
|||||||||||||||||||||||||||||||
Display Data Ram (DDRAM) stores the display data. So when we have to display a character on LCD we basically write it into DDRAM. For a 2x16 LCD the DDRAM address for first line is from 80h to 8fh & for second line is 0c0h to 0cfh. So if we want to display 'H' on the 7th postion of the first line then we will write it at location 87h. |
|||||||||||||||||||||||||||||||
Now as you have noticed two types of data is given to the LCD data to be displayed, command or special instruction.So now let us write a subroutine for both the type of data |
|||||||||||||||||||||||||||||||
Data to be Displayed |
|||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||
Command or Special Instruction |
|||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||
Here I have used delay at the end of both the subroutines this is done to wait until the instruction is completely executed by the LCD. This will assure that our program gives the LCD the time it needs to execute instructions and also makes our program compatible with any LCD, regardless of how fast or slow it is. |
|||||||||||||||||||||||||||||||
"*" - Not Used/Ignored. This bit can be either "1" or "0" |
|||||||||||||||||||||||||||||||
Set Cursor Move Direction:
|
|||||||||||||||||||||||||||||||
Set Cursor Move Direction:
|
|||||||||||||||||||||||||||||||
Move Cursor/Shift Display
|
|||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||
Set Interface Length
Move Cursor to CGRAM/Display
Read/Write ASCII to the Display
|
|||||||||||||||||||||||||||||||
The above Table shows the different commands for the LCD. I wont go into its details. |
|||||||||||||||||||||||||||||||
Before starting to display on LCD we need to Initialize it. Firstly we must tell the LCD whether we'll be using 8-bit or 4-bit mode. Also we will be telling the LCD that we need 5x8 character font. Both these options are selected using a single command i.e. 38h. So to activate both these options we must execute following instructions: |
|||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||
Now that we have to Turn On the display & set the cursor option i.e. cursor ON/OFF & Cursor blinking ON/OFF for that we will use the command 0Eh i.e. Display On , Cursor ON but Cursor blinking OFF. |
|||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||
And the last command we require is to configure the LCD in such a way that everytime we send a character to it the cursor position automatically increments by one & moves to right i.e. 06h. |
|||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||
So the lcd_initialize contains the following instructions |
|||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||
Similarly another important instruction that we require is Clearing the LCD i.e. |
|||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||
Now we know all the commands to display on LCD. Let us write a program that will display 'DNA TECHNOLOGY' on LCD. |
|||||||||||||||||||||||||||||||
For delay subroutine please check the delay subroutines explained in LED interfacing Article or the 8051 Timer Article. |
|||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||
Debugging Procedure |
|||||||||||||||||||||||||||||||
If the above program does not work then follow these steps:- 1) Check if the supply is correct. 2) If all connections are correct. 3) Increase the delay time. |
|||||||||||||||||||||||||||||||
Check our CODE LIBRARY section for more code. |
- .