LCD (Liquid Crystal Display) screen is an electronic display module and find a wide range of applications. A 16x2 LCD display is very basic module and is very commonly used in various devices and circuits. These modules are preferred over seven segments and other multi segment LEDs.
The reasons being:
1.LCDs are economical;
2.easily programmable;
3. have no limitation of displaying special & animation.
A 16x2 LCD means it can display 16 characters per line and there are 2 such lines. In this LCD each character is displayed in 5x7 pixel matrix. This LCD has two registers, namely, Command and Data.
The command register stores the command instructions given to the LCD. A command is an instruction given to LCD to do a predefined task like initializing it, clearing its screen, setting the cursor position, controlling display etc.
The data register stores the data to be displayed on the LCD. The data is the ASCII value of the character to be displayed on the LCD.
Liquid Crystal Display (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.
The most commonly used ALPHANUMERIC displays are:
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.
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, RS=0 for command values and RS=1 for data values. EN is enabled to see the character on LCD and disabled after sometimes so that new values can be passed.
The reasons being:
1.LCDs are economical;
2.easily programmable;
3. have no limitation of displaying special & animation.
A 16x2 LCD means it can display 16 characters per line and there are 2 such lines. In this LCD each character is displayed in 5x7 pixel matrix. This LCD has two registers, namely, Command and Data.
The command register stores the command instructions given to the LCD. A command is an instruction given to LCD to do a predefined task like initializing it, clearing its screen, setting the cursor position, controlling display etc.
The data register stores the data to be displayed on the LCD. The data is the ASCII value of the character to be displayed on the LCD.
Liquid Crystal Display (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.
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).
Pin Configuration:
A 16x2 LCD consist of 16 pin that make connections to display a text on it. It can be interfaced with any controller to control the displayed images on it.
pin configuration
LCD commands should know before programming
Interfacing with LCD:
These LCD's are very simple to interface with the controller as well as are cost effective.
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.
Circuit Diagram:
Code:
#include "REG52.h" #define LCD P3 sbit RS=P2^5; sbit RW=P2^6; sbit EN=P2^7; long int i; void CMD(char); void DATA1(char); void main() { CMD(0x38); for(i=0;i<=100;i++); CMD(0x0E); for(i=0;i<=100;i++); CMD(0x01); for(i=0;i<=100;i++); CMD(0x14); for(i=0;i<=100;i++); CMD(0x81); for(i=0;i<=100;i++); DATA1('K') ; for(i=0;i<=100;i++); DATA1('N') ; for(i=0;i<=100;i++); DATA1('I') ; for(i=0;i<=100;i++); DATA1('X') ; for(i=0;i<=100;i++); CMD(0xC6); for(i=0;i<=100;i++); DATA1('S') ; for(i=0;i<=100;i++); DATA1('O') ; for(i=0;i<=100;i++); DATA1('L') ; for(i=0;i<=100;i++); DATA1('U') ; for(i=0;i<=100;i++); DATA1('T') ; for(i=0;i<=100;i++); DATA1('I') ; for(i=0;i<=100;i++); DATA1('O') ; for(i=0;i<=100;i++); DATA1('N'); for(i=0;i<=100;i++); DATA1('S') ; for(i=0;i<=100;i++); } void CMD(unsigned char c) { LCD=c; RS=0; RW=0; EN=1; for(i=0;i<20;i++); EN=0; } void DATA1(unsigned char a) { LCD=a; RS=1; RW=0; EN=1; for(i=0;i<20;i++); EN=0; }Program to implement string function:
#include "REG52.h" #define LCD P3 sbit RS=P2^5; sbit RW=P2^6; sbit EN=P2^7; int i, j; unsigned char a[]="WELCOME"; unsigned char b[]="HOME"; void CMD(char); void DATA1(char); void main() { CMD(0x38); for(i=0;i<=500;i++); CMD(0x0E); for(i=0;i<=500;i++); CMD(0x01); for(i=0;i<=500;i++); CMD(0x14); for(i=0;i<=500;i++); CMD(0x85); for(i=0;i<=500;i++); for(j=0;a[j]!='';j++) { DATA1(a[j]); CMD(0xC6); for(i=0;i<=500;i++); for(j=0;b[j]!='';j++) DATA1(b[j]); } void CMD(unsigned char c) { LCD=c; RS=0; RW=0; EN=1; for(i=0;i<100;i++); EN=0; } void DATA1(unsigned char d) { LCD=d; RS=1; RW=0; EN=1; for(i=0;i<100;i++); EN=0; }
Explanation of code:
- Above code specify the implementation of 16x2 LCD with 8051 microcontroller. In this, you have to use Data pins of LCD (D0-D7) and RS, R/W and EN. The command and data function are necessary to define before the main function they define the pattern of alphabets on LCD. Command values are given in the hexadecimal chart above. And Data is what you want to display on LCD.Now, RS=0 for command values and RS=1 for data values. EN is enabled to see the character on LCD and disabled after sometimes so that new values can be passed.
Comments
Post a Comment