Beruflich Dokumente
Kultur Dokumente
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: LCDs are economical; easily programmable; have no limitation of displaying special & even custom characters (unlike in seven segments), animations and so on. 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. Click to learn more about internal structure of a LCD.
Pin Description Pin No 1 2 3 4 5 Function Ground (0V) Supply voltage; 5V (4.7V 5.3V) Contrast adjustment; through a variable resistor Name Ground Vcc VEE
Selects command register when low; and data register Register when high Select Low to write to the register; High to read from the Read/write register Sends data to data pins when a high to low pulse is Enable given DB0 DB1 DB2 DB3 DB4 DB5 DB6 DB7 Led+ Led-
7 8 9 10 11 12 13 14 15 16
This LCD has two registers. 1. Command/Instruction Register - stores the command instructions given to the LCD. A command is an instruction given to LCD to do a predefined task like initializing, clearing the screen, setting the cursor position, controlling display etc.
2. 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. Commonly used LCD Command codes: Hex Code 1 2 4 6 E 80 C0 38 Command to LCD Instruction Register Clear screen display Return home Decrement cursor Increment cursor Display ON, Cursor ON Force the cursor to the beginning of the 1st line Force cursor to the beginning of the 2nd line Use 2 lines and 5x7 matrix
LCD1
LM016L
U1
19 XTAL1 P0.0/AD0 P0.1/AD1 P0.2/AD2 P0.3/AD3 P0.4/AD4 P0.5/AD5 P0.6/AD6 P0.7/AD7 P2.0/A8 P2.1/A9 P2.2/A10 P2.3/A11 P2.4/A12 P2.5/A13 P2.6/A14 P2.7/A15 P3.0/RXD P3.1/TXD P3.2/INT0 P3.3/INT1 P3.4/T0 P3.5/T1 P3.6/WR P3.7/RD 39 38 37 36 35 34 33 32 21 22 23 24 25 26 27 28 10 11 12 13 14 15 16 17
18
XTAL2
RS RW E 4 5 6
1 2 3
29 30 31
PSEN ALE EA
1 2 3 4 5 6 7 8
7 8 9 10 11 12 13 14
RST
D0 D1 D2 D3 D4 D5 D6 D7
PROGRAMMING THE LCD 1. First, we need to give command to LCD, like turn ON LCD, type of LCD, clear screen, cursor position. 2. To make these commands to work that set RS pin to 0. 3. The make R/W pin to 0 to indicate writing mode and make enable pin to 1 and give some time delay for the operation to be performed. Repeat these two steps for each and every command. 4. Then it is changed to data write mode i.e., to display the output. Now RS pin is set at 1, EN pin is set at 1 and give some time delay to move the data to LCD. Programming code: #include<reg51.h> void lcdcmd(unsigned char value); void lcddata(unsigned char value); void msdelay(unsigned int itime); void main() { lcdcmd(0x38); msdelay(250); lcdcmd(0x0e); msdelay(250); lcdcmd(0x01); msdelay(250); lcdcmd(0x06); msdelay(250); lcdcmd(0x80);
msdelay(250); lcddata('M'); msdelay(250); lcddata('e'); msdelay(250); lcddata('c'); msdelay(250); lcddata('h'); msdelay(250); lcddata('a'); msdelay(250); lcddata('t'); msdelay(250); lcddata('r'); msdelay(250); lcddata('i'); msdelay(250); lcddata('k'); msdelay(250); lcddata('s'); msdelay(250); while(1) {} }
#ifndef _leddatas_H #define _leddatas_H #include<reg51.h> sfr ldata=0xA0; sbit rs=P3^2; sbit rw=P3^3; sbit en=P3^4; void lcdcmd(unsigned char value) { ldata=value; rs=0; rw=0; en=1; msdelay(1); en=0; return; } void lcddata(unsigned char value) { ldata=value; rs=1; rw=0; en=1;
msdelay(1); en=0; return; } void msdelay(unsigned int itime) { unsigned int i,j; for(i=0;i<itime;i++) { } for(j=0;j<1275;j++) { } } #endif Reference: 1. http://ramoliyabiren.blogspot.in/2011/12/lcd-16x2-interface-with8051.html