m
m
 
(11 intermediate revisions by the same user not shown)
Line 3: Line 3:
 
=Video Tutorial=
 
=Video Tutorial=
  
{{#ev:youtube|YDJISiPUdA8|600}}
 
{{#ev:youtube|xG7uu98qz_A|200}}
 
{{#ev:youtube|jRA4gefNVhM|200}}
 
{{#ev:youtube|g-3Vt7SyL9w|200}}
 
 
=Introduction:LCD=
 
=Introduction:LCD=
  
Line 13: Line 9:
  
 
== LCD Internal Controller==
 
== LCD Internal Controller==
[[File:HD44780U Block diagram.png|570x250px|framed|Fig 1: LCD Block diagram]]<br />
 
  
The LCD is a simple device to use but the internal details are complex. Most of the 16x2 LCDs use a '''Hitachi HD44780''' or a compatible controller. Yes, a micrcontroller is present inside a Liquid crystal display as shown in figure 1.
+
The LCD is a simple device to use but the internal details are complex. Most of the 16x2 LCDs use a '''Hitachi HD44780''' or a compatible controller. Yes, a micrcontroller is present inside a Liquid crystal display as shown in figure 2.
[[File:LCD Char 5x7 Matrix.jpg|thumbnail]]
+
 
The Display Controller takes commands and data from a external microcontroller and drivers the LCD panel'''(LCDP)'''.
+
The Display Controller takes commands and data from a external microcontroller and drivers the LCD panel '''(LCDP)'''.
It takes a ASCII value as input and generate a patter for the dot matrix. E.g., to display letter 'A', it takes its value '''0X42(hex)''' or '''66(dec)''' decodes it into a dot matrix of 5x7 as shown in figure 2.
+
It takes a ASCII value as input and generate a patter for the dot matrix. E.g., to display letter 'A', it takes its value '''0X42(hex)''' or '''66(dec)''' decodes it into a dot matrix of 5x7 as shown in figure 1.
 +
 
 +
 
 +
[[File:LCD Char 5x7 Matrix.jpg|550px|framed|left|Fig 1: LCD Char 5x7 Matrix]]
 +
[[File:HD44780U Block diagram.png|570x250px|framed|Fig 2: LCD Block diagram]]
  
 
==Basic Commands==
 
==Basic Commands==
Line 274: Line 273:
  
 
=LCD UNIT=
 
=LCD UNIT=
{{Box|type=l_green_light|text=
 
  
 
Let us look at a pin diagram of a commercially available LCD like '''JHD162''' which uses a '''HD44780''' controller and then describe its operation.
 
Let us look at a pin diagram of a commercially available LCD like '''JHD162''' which uses a '''HD44780''' controller and then describe its operation.
Line 281: Line 279:
  
 
All the pins are identically to the lcd internal controller discussed above
 
All the pins are identically to the lcd internal controller discussed above
 
}}
 
  
 
{|class="wikitable "  
 
{|class="wikitable "  
Line 320: Line 316:
 
| 16 || Back-Light Cathode(-)  
 
| 16 || Back-Light Cathode(-)  
 
|}
 
|}
<br/>
 
<br/>
 
<br/>
 
<br/>
 
  
=Interfacing LCD with 8051=
+
===Schematic===
  
LCD can be interfaced with the 8051 micrcontroller in two modes, 8 bit and 4 bit.
+
LCD can be interfaced with the micrcontroller in two modes, 8 bit and 4 bit.
 
Let us Interface it in 8 bit mode first.  
 
Let us Interface it in 8 bit mode first.  
==8 bit Mode==
 
  
===Objective===
+
[[File:8051 LCD8BIT Interface.PNG|Fig 3: Schematic LCD 8 bit mode]]
[[File:LCD_output.PNG|thumbnail|fig LCD display ]]
+
 
There is lot of stuff that can be done with the LCDs, to start with we will simple display a couple of strings on the 2 lines of the LCD as shown in the image.
+
===Schematic Discription===
+
 
*'''Data  Lines:''' In this mode, all of the 8 datalines DB0 to DB7 are connected from the micrcontroller to a LCD module as shown the schematic.
 
*'''Data  Lines:''' In this mode, all of the 8 datalines DB0 to DB7 are connected from the micrcontroller to a LCD module as shown the schematic.
 
*'''Control Lines:'''' The RS, RW and E are control lines, as discussed earlier.
 
*'''Control Lines:'''' The RS, RW and E are control lines, as discussed earlier.
 
*'''Power & contrast''':Apart from that the LCD should be powered with 5V between '''PIN 2(VCC)''' and  '''PIN 1(gnd)'''. '''PIN 3''' is the contrast pin and is output of center terminal of potentiometer(voltage divider) which varies voltage between 0 to 5v to vary the contrast.
 
*'''Power & contrast''':Apart from that the LCD should be powered with 5V between '''PIN 2(VCC)''' and  '''PIN 1(gnd)'''. '''PIN 3''' is the contrast pin and is output of center terminal of potentiometer(voltage divider) which varies voltage between 0 to 5v to vary the contrast.
*'''Back-light:''' The PIN 15 and 16 are used as backlight. The led backlight can be powered through a simple current limiting resistor as we do with normal leds.  
+
*'''Back-light:''' The PIN 15 and 16 are used as backlight. The led backlight can be powered through a simple current limiting resistor as we do with normal leds.
 
+
 
+
===Schematic===
+
[[File:8051 LCD8BIT Interface.PNG|Fig 3: Schematic LCD 8 bit mode]]
+
 
+
 
+
  
 
===Practical Example===
 
===Practical Example===
[[A1.8051 Interfacing:LCD 16x2|8051 Interfacing:LCD 16x2]]
+
*[[A1.8051 Interfacing:LCD 16x2|8051 Interfacing:LCD 16x2]]
 
+
= Downloads=
+
{{Box|type=l_green_light|text="The code is given for 4 and 8 bit modes with and without busy Flag"}}
+
[http://exploreembedded.com/wiki/images/0/02/8051_LCD_Tutorial_Code.zip '''Code''']
+
 
+
 
+
[[File:SwitchesLEDs.jpg|left|thumbnail|x120px|{{Box|type=l_blue_light|text=Switches and LED Interfacing with 8051 }}|link=8051_Interfacing_swithes_leds|'''''PREVIOUS TUTORIAL''''']]
+
[[File:8051_Timers_Poster.jpg|right|thumbnail|x150px|link=8051_timers|'''''NEXT TUTORIAL''''']]
+
 
+
{{#widget:Facebook_Like_Box|profile=https://www.facebook.com/ExploreEmbedded}}
+
  
 
Have a opinion, suggestion , question or feedback about the article let it out here!
 
Have a opinion, suggestion , question or feedback about the article let it out here!
 
{{DISQUS}}
 
{{DISQUS}}

Latest revision as of 18:12, 21 March 2015


Video Tutorial

Introduction:LCD

Liquid Crystal Display(LCDs) provide a cost effective way to put a text output unit for a microcontroller. As we have seen in the previous tutorial, LEDs or 7 Segments do no have the flexibility to display informative messages. This display has 2 lines and can display 16 characters on each line. Nonetheless, when it is interfaced with the micrcontroller, we can scroll the messages with software to display information which is more than 16 characters in length.

LCD Internal Controller

The LCD is a simple device to use but the internal details are complex. Most of the 16x2 LCDs use a Hitachi HD44780 or a compatible controller. Yes, a micrcontroller is present inside a Liquid crystal display as shown in figure 2.

The Display Controller takes commands and data from a external microcontroller and drivers the LCD panel (LCDP). It takes a ASCII value as input and generate a patter for the dot matrix. E.g., to display letter 'A', it takes its value 0X42(hex) or 66(dec) decodes it into a dot matrix of 5x7 as shown in figure 1.


Fig 1: LCD Char 5x7 Matrix
Fig 2: LCD Block diagram

Basic Commands

The LCD controller uses RS and RW lines along with E to operate the LCD.

  • Resister Select (RS): Determines weather a command(RS = 0) is sent (to set up the display) or actual data(RS=1) is sent.
  • Read/Write RW=0; writes to the LCD. RW=1;Reads from the LCD.

The commonly used instructions are shown in the instruction set below. Observe the Bit names: I/D, S, D, C etc at the bottom of instruction set to decode the instructions completely.

  • Clear Display
  • Cursor Home
  • Set Entry Mode
  • Display on/off control
  • Cursor/display shift
  • Function Set
  • Read Busy Flag
  • Data Read
  • Data Write

Instruction Set

HD44780U based instruction set
Instruction Code Description
RS R/W B7 B6 B5 B4 B3 B2 B1 B0
Clear display 0 0 0 0 0 0 0 0 0 1 Clears display and returns cursor to the home position (address 0).
Cursor home 0 0 0 0 0 0 0 0 1 * Returns cursor to home position. Also returns display being shifted to the original position. DDRAM content remains unchanged.


Entry mode set 0 0 0 0 0 0 0 1 I/D S Sets cursor move direction (I/D); specifies to shift the display (S). These operations are performed during data read/write.


Display on/off control 0 0 0 0 0 0 1 D C B Sets on/off of all display (D), cursor on/off (C), and blink of cursor position character (B).


Cursor/display shift 0 0 0 0 0 1 S/C R/L * * Sets cursor-move or display-shift (S/C), shift direction (R/L). DDRAM content remains unchanged.


Function set 0 0 0 0 1 DL N F * * Sets interface data length (DL), number of display line (N), and character font (F).
Read busy flag &
address counter
0 1 BF CGRAM/DDRAM address Reads busy flag (BF) indicating internal operation being performed and reads CGRAM or DDRAM address counter contents (depending on previous instruction).
Write CGRAM or
DDRAM
1 0 Write Data Write data to CGRAM or DDRAM.
Write CGRAM or
DDRAM
1 0 Write Data Write data to CGRAM or DDRAM.
Instruction bit names —

I/D - 0 = decrement cursor position, 1 = increment cursor position;

S - 0 = no display shift, 1 = display shift;
D - 0 = display off, 1 = display on;
C - 0 = cursor off, 1 = cursor on;
B - 0 = cursor blink off, 1 = cursor blink on ;
S/C - 0 = move cursor, 1 = shift display;
R/L - 0 = shift left, 1 = shift right;
DL - 0 = 4-bit interface, 1 = 8-bit interface;
N - 0 = 1/8 or 1/11 duty (1 line), 1 = 1/16 duty (2 lines);
F - 0 = 5×8 dots, 1 = 5×10 dots;
BF - 0 = can accept instruction, 1 = internal operation in progress.

LCD UNIT

Let us look at a pin diagram of a commercially available LCD like JHD162 which uses a HD44780 controller and then describe its operation.

PIN Diagram.PNG

All the pins are identically to the lcd internal controller discussed above

PIN NUMBER FUNCTION
1 Ground
2 VCC
3 Contrast adjustment (VO)
4 Register Select (RS). RS=0: Command, RS=1: Data
5 Read/Write (R/W). R/W=0: Write, R/W=1: Read
6 Clock (Enable). Falling edge triggered
7 Bit 0 (Not used in 4-bit operation)
8 Bit 1 (Not used in 4-bit operation)
9 Bit 2 (Not used in 4-bit operation)
10 Bit 3 (Not used in 4-bit operation)
11 Bit 4
12 Bit 5
13 Bit 6
14 Bit 7
15 Back-light Anode(+)
16 Back-Light Cathode(-)

Schematic

LCD can be interfaced with the micrcontroller in two modes, 8 bit and 4 bit. Let us Interface it in 8 bit mode first.

Fig 3: Schematic LCD 8 bit mode

  • Data Lines: In this mode, all of the 8 datalines DB0 to DB7 are connected from the micrcontroller to a LCD module as shown the schematic.
  • Control Lines:' The RS, RW and E are control lines, as discussed earlier.
  • Power & contrast:Apart from that the LCD should be powered with 5V between PIN 2(VCC) and PIN 1(gnd). PIN 3 is the contrast pin and is output of center terminal of potentiometer(voltage divider) which varies voltage between 0 to 5v to vary the contrast.
  • Back-light: The PIN 15 and 16 are used as backlight. The led backlight can be powered through a simple current limiting resistor as we do with normal leds.

Practical Example

Have a opinion, suggestion , question or feedback about the article let it out here!