Line 55: Line 55:
  
 
==Instruction Set==
 
==Instruction Set==
 +
 
The HD44780 instruction set is shown below:
 
The HD44780 instruction set is shown below:
 +
 
{|class="wikitable" border="1" cellpadding="5" cellspacing="0" align="center"
 
{|class="wikitable" border="1" cellpadding="5" cellspacing="0" align="center"
 +
 
|+ '''HD44780U based instruction set'''
 
|+ '''HD44780U based instruction set'''
 +
 
|-
 
|-
 +
 
! style="background: #efefef;" rowspan="2" | Instruction
 
! style="background: #efefef;" rowspan="2" | Instruction
 +
 
! style="background: #efefef;" colspan="10" | Code
 
! style="background: #efefef;" colspan="10" | Code
 +
 
! style="background: #efefef;" rowspan="2" | Description
 
! style="background: #efefef;" rowspan="2" | Description
! style="background: #efefef;" rowspan="2" | Execution<br> time (max)<br> (when f<sub>cp</sub> =  270&nbsp;kHz)
+
 
 
|-
 
|-
 +
 
! style="background: #efefef; border-right: 0px;" | RS
 
! style="background: #efefef; border-right: 0px;" | RS
 +
 
! style="background: #efefef; border-right: 0px; border-left: 0px;" | R/W
 
! style="background: #efefef; border-right: 0px; border-left: 0px;" | R/W
 +
 
! style="background: #efefef; border-right: 0px; border-left: 1px dashed;" | B7
 
! style="background: #efefef; border-right: 0px; border-left: 1px dashed;" | B7
 +
 
! style="background: #efefef; border-right: 0px; border-left: 0px;" | B6
 
! style="background: #efefef; border-right: 0px; border-left: 0px;" | B6
 +
 
! style="background: #efefef; border-right: 0px; border-left: 0px;" | B5
 
! style="background: #efefef; border-right: 0px; border-left: 0px;" | B5
 +
 
! style="background: #efefef; border-right: 0px; border-left: 0px;" | B4
 
! style="background: #efefef; border-right: 0px; border-left: 0px;" | B4
 +
 
! style="background: #efefef; border-right: 0px; border-left: 0px;" | B3
 
! style="background: #efefef; border-right: 0px; border-left: 0px;" | B3
 +
 
! style="background: #efefef; border-right: 0px; border-left: 0px;" | B2
 
! style="background: #efefef; border-right: 0px; border-left: 0px;" | B2
 +
 
! style="background: #efefef; border-right: 0px; border-left: 0px;" | B1
 
! style="background: #efefef; border-right: 0px; border-left: 0px;" | B1
 +
 
! style="background: #efefef; border-left: 0px;" | B0
 
! style="background: #efefef; border-left: 0px;" | B0
 +
 
|-
 
|-
 +
 
| Clear display
 
| Clear display
 +
 
|align="center" style="border-right: 0px;"| 0
 
|align="center" style="border-right: 0px;"| 0
 +
 
|align="center" style="border-right: 0px; border-left: 0px;"| 0
 
|align="center" style="border-right: 0px; border-left: 0px;"| 0
 +
 
|align="center" style="border-right: 0px; border-left: 1px dashed;"| 0
 
|align="center" style="border-right: 0px; border-left: 1px dashed;"| 0
 +
 
|align="center" style="border-right: 0px; border-left: 0px;"| 0
 
|align="center" style="border-right: 0px; border-left: 0px;"| 0
 +
 
|align="center" style="border-right: 0px; border-left: 0px;"| 0
 
|align="center" style="border-right: 0px; border-left: 0px;"| 0
 +
 
|align="center" style="border-right: 0px; border-left: 0px;"| 0
 
|align="center" style="border-right: 0px; border-left: 0px;"| 0
 +
 
|align="center" style="border-right: 0px; border-left: 0px;"| 0
 
|align="center" style="border-right: 0px; border-left: 0px;"| 0
 +
 
|align="center" style="border-right: 0px; border-left: 0px;"| 0
 
|align="center" style="border-right: 0px; border-left: 0px;"| 0
 +
 
|align="center" style="border-right: 0px; border-left: 0px;"| 0
 
|align="center" style="border-right: 0px; border-left: 0px;"| 0
 +
 
|align="center" style="border-left: 0px;"| 1
 
|align="center" style="border-left: 0px;"| 1
 +
 
|| Clears display and returns cursor to the home position (address 0).
 
|| Clears display and returns cursor to the home position (address 0).
|align="center"| 1.52 ms
+
 
 
|-
 
|-
 +
 
|| Cursor home
 
|| Cursor home
 +
 
|align="center" style="border-right: 0px;"| 0
 
|align="center" style="border-right: 0px;"| 0
 +
 
|align="center" style="border-right: 0px; border-left: 0px;"| 0
 
|align="center" style="border-right: 0px; border-left: 0px;"| 0
 +
 
|align="center" style="border-right: 0px; border-left: 1px dashed;"| 0
 
|align="center" style="border-right: 0px; border-left: 1px dashed;"| 0
 +
 
|align="center" style="border-right: 0px; border-left: 0px;"| 0
 
|align="center" style="border-right: 0px; border-left: 0px;"| 0
 +
 
|align="center" style="border-right: 0px; border-left: 0px;"| 0
 
|align="center" style="border-right: 0px; border-left: 0px;"| 0
 +
 
|align="center" style="border-right: 0px; border-left: 0px;"| 0
 
|align="center" style="border-right: 0px; border-left: 0px;"| 0
 +
 
|align="center" style="border-right: 0px; border-left: 0px;"| 0
 
|align="center" style="border-right: 0px; border-left: 0px;"| 0
 +
 
|align="center" style="border-right: 0px; border-left: 0px;"| 0
 
|align="center" style="border-right: 0px; border-left: 0px;"| 0
 +
 
|align="center" style="border-right: 0px; border-left: 0px;"| 1
 
|align="center" style="border-right: 0px; border-left: 0px;"| 1
 +
 
|align="center" style="border-left: 0px;"| *
 
|align="center" style="border-left: 0px;"| *
 +
 
|| Returns cursor to home position. Also returns display being shifted to the original position. DDRAM content remains unchanged.
 
|| Returns cursor to home position. Also returns display being shifted to the original position. DDRAM content remains unchanged.
|align="center"| 1.52 ms
+
 
 +
 
 
|-
 
|-
 +
 
|| Entry mode set
 
|| Entry mode set
 +
 
|align="center" style="border-right: 0px;"| 0
 
|align="center" style="border-right: 0px;"| 0
 +
 
|align="center" style="border-right: 0px; border-left: 0px;"| 0
 
|align="center" style="border-right: 0px; border-left: 0px;"| 0
 +
 
|align="center" style="border-right: 0px; border-left: 1px dashed;"| 0
 
|align="center" style="border-right: 0px; border-left: 1px dashed;"| 0
 +
 
|align="center" style="border-right: 0px; border-left: 0px;"| 0
 
|align="center" style="border-right: 0px; border-left: 0px;"| 0
 +
 
|align="center" style="border-right: 0px; border-left: 0px;"| 0
 
|align="center" style="border-right: 0px; border-left: 0px;"| 0
 +
 
|align="center" style="border-right: 0px; border-left: 0px;"| 0
 
|align="center" style="border-right: 0px; border-left: 0px;"| 0
 +
 
|align="center" style="border-right: 0px; border-left: 0px;"| 0
 
|align="center" style="border-right: 0px; border-left: 0px;"| 0
 +
 
|align="center" style="border-right: 0px; border-left: 0px;"| 1
 
|align="center" style="border-right: 0px; border-left: 0px;"| 1
 +
 
|align="center" style="border-right: 0px; border-left: 0px;"| I/D
 
|align="center" style="border-right: 0px; border-left: 0px;"| I/D
 +
 
|align="center" style="border-left: 0px;"| S
 
|align="center" style="border-left: 0px;"| S
 +
 
|| Sets cursor move direction (I/D); specifies to shift the display (S). These operations are performed during data read/write.
 
|| Sets cursor move direction (I/D); specifies to shift the display (S). These operations are performed during data read/write.
|align="center"| 37 μs
+
 
 +
 
 
|-
 
|-
 +
 
|| Display on/off control
 
|| Display on/off control
 +
 
|align="center" style="border-right: 0px;"| 0
 
|align="center" style="border-right: 0px;"| 0
 +
 
|align="center" style="border-right: 0px; border-left: 0px;"| 0
 
|align="center" style="border-right: 0px; border-left: 0px;"| 0
 +
 
|align="center" style="border-right: 0px; border-left: 1px dashed;"| 0
 
|align="center" style="border-right: 0px; border-left: 1px dashed;"| 0
 +
 
|align="center" style="border-right: 0px; border-left: 0px;"| 0
 
|align="center" style="border-right: 0px; border-left: 0px;"| 0
 +
 
|align="center" style="border-right: 0px; border-left: 0px;"| 0
 
|align="center" style="border-right: 0px; border-left: 0px;"| 0
 +
 
|align="center" style="border-right: 0px; border-left: 0px;"| 0
 
|align="center" style="border-right: 0px; border-left: 0px;"| 0
 +
 
|align="center" style="border-right: 0px; border-left: 0px;"| 1
 
|align="center" style="border-right: 0px; border-left: 0px;"| 1
 +
 
|align="center" style="border-right: 0px; border-left: 0px;"| D
 
|align="center" style="border-right: 0px; border-left: 0px;"| D
 +
 
|align="center" style="border-right: 0px; border-left: 0px;"| C
 
|align="center" style="border-right: 0px; border-left: 0px;"| C
 +
 
|align="center" style="border-left: 0px;"| B
 
|align="center" style="border-left: 0px;"| B
 +
 
|| Sets on/off of all display (D), cursor on/off (C), and blink of cursor position character (B).
 
|| Sets on/off of all display (D), cursor on/off (C), and blink of cursor position character (B).
|align="center"| 37 μs
+
 
 +
 
 
|-
 
|-
 +
 
|| Cursor/display shift
 
|| Cursor/display shift
 +
 
|align="center" style="border-right: 0px;"| 0
 
|align="center" style="border-right: 0px;"| 0
 +
 
|align="center" style="border-right: 0px; border-left: 0px;"| 0
 
|align="center" style="border-right: 0px; border-left: 0px;"| 0
 +
 
|align="center" style="border-right: 0px; border-left: 1px dashed;"| 0
 
|align="center" style="border-right: 0px; border-left: 1px dashed;"| 0
 +
 
|align="center" style="border-right: 0px; border-left: 0px;"| 0
 
|align="center" style="border-right: 0px; border-left: 0px;"| 0
 +
 
|align="center" style="border-right: 0px; border-left: 0px;"| 0
 
|align="center" style="border-right: 0px; border-left: 0px;"| 0
 +
 
|align="center" style="border-right: 0px; border-left: 0px;"| 1
 
|align="center" style="border-right: 0px; border-left: 0px;"| 1
 +
 
|align="center" style="border-right: 0px; border-left: 0px;"| S/C
 
|align="center" style="border-right: 0px; border-left: 0px;"| S/C
 +
 
|align="center" style="border-right: 0px; border-left: 0px;"| R/L
 
|align="center" style="border-right: 0px; border-left: 0px;"| R/L
 +
 
|align="center" style="border-right: 0px; border-left: 0px;"| *
 
|align="center" style="border-right: 0px; border-left: 0px;"| *
 +
 
|align="center" style="border-left: 0px;"| *
 
|align="center" style="border-left: 0px;"| *
 +
 
|| Sets cursor-move or display-shift (S/C), shift direction (R/L). DDRAM content remains unchanged.
 
|| Sets cursor-move or display-shift (S/C), shift direction (R/L). DDRAM content remains unchanged.
|align="center"| 37 μs
+
 
 +
 
 
|-
 
|-
 +
 
|| Function set
 
|| Function set
 +
 
|align="center" style="border-right: 0px;"| 0
 
|align="center" style="border-right: 0px;"| 0
 +
 
|align="center" style="border-right: 0px; border-left: 0px;"| 0
 
|align="center" style="border-right: 0px; border-left: 0px;"| 0
 +
 
|align="center" style="border-right: 0px; border-left: 1px dashed;"| 0
 
|align="center" style="border-right: 0px; border-left: 1px dashed;"| 0
 +
 
|align="center" style="border-right: 0px; border-left: 0px;"| 0
 
|align="center" style="border-right: 0px; border-left: 0px;"| 0
 +
 
|align="center" style="border-right: 0px; border-left: 0px;"| 1
 
|align="center" style="border-right: 0px; border-left: 0px;"| 1
 +
 
|align="center" style="border-right: 0px; border-left: 0px;"| DL
 
|align="center" style="border-right: 0px; border-left: 0px;"| DL
 +
 
|align="center" style="border-right: 0px; border-left: 0px;"| N
 
|align="center" style="border-right: 0px; border-left: 0px;"| N
 +
 
|align="center" style="border-right: 0px; border-left: 0px;"| F
 
|align="center" style="border-right: 0px; border-left: 0px;"| F
 +
 
|align="center" style="border-right: 0px; border-left: 0px;"| *
 
|align="center" style="border-right: 0px; border-left: 0px;"| *
 +
 
|align="center" style="border-left: 0px;"| *
 
|align="center" style="border-left: 0px;"| *
 +
 
|| Sets interface data length (DL), number of display line (N), and character font (F).
 
|| Sets interface data length (DL), number of display line (N), and character font (F).
|align="center"| 37 μs
+
 
 +
 
 +
 
 
|-
 
|-
 +
 
|| Set CGRAM address
 
|| Set CGRAM address
 +
 
|align="center" style="border-right: 0px;"| 0
 
|align="center" style="border-right: 0px;"| 0
 +
 
|align="center" style="border-right: 0px; border-left: 0px;"| 0
 
|align="center" style="border-right: 0px; border-left: 0px;"| 0
 +
 
|align="center" style="border-right: 0px; border-left: 1px dashed;"| 0
 
|align="center" style="border-right: 0px; border-left: 1px dashed;"| 0
 +
 
|align="center" style="border-right: 0px; border-left: 0px;"| 1
 
|align="center" style="border-right: 0px; border-left: 0px;"| 1
 +
 
|align="center" style="border-left: 0px;" colspan="6"| CGRAM address
 
|align="center" style="border-left: 0px;" colspan="6"| CGRAM address
 +
 
|| Sets the CGRAM address. CGRAM data are sent and received after this setting.
 
|| Sets the CGRAM address. CGRAM data are sent and received after this setting.
|align="center"| 37 μs
+
 
 +
 
 +
 
 
|-
 
|-
 +
 
|| Set DDRAM address
 
|| Set DDRAM address
 +
 
|align="center" style="border-right: 0px;"| 0
 
|align="center" style="border-right: 0px;"| 0
 +
 
|align="center" style="border-right: 0px; border-left: 0px;"| 0
 
|align="center" style="border-right: 0px; border-left: 0px;"| 0
 +
 
|align="center" style="border-right: 0px; border-left: 1px dashed;"| 1
 
|align="center" style="border-right: 0px; border-left: 1px dashed;"| 1
 +
 
|align="center" style="border-left: 0px;" colspan="7"| DDRAM address
 
|align="center" style="border-left: 0px;" colspan="7"| DDRAM address
 +
 
|| Sets the DDRAM address. DDRAM data are sent and received after this setting.
 
|| Sets the DDRAM address. DDRAM data are sent and received after this setting.
|align="center"| 37 μs
+
 
 +
 
 +
 
 
|-
 
|-
 +
 
|| Read busy flag &<br> address counter
 
|| Read busy flag &<br> address counter
 +
 
|align="center" style="border-right: 0px;"| 0
 
|align="center" style="border-right: 0px;"| 0
 +
 
|align="center" style="border-right: 0px; border-left: 0px;"| 1
 
|align="center" style="border-right: 0px; border-left: 0px;"| 1
 +
 
|align="center" style="border-right: 0px; border-left: 1px dashed;"| BF
 
|align="center" style="border-right: 0px; border-left: 1px dashed;"| BF
 +
 
|align="center" style="border-left: 0px;" colspan="7"| CGRAM/DDRAM address
 
|align="center" style="border-left: 0px;" colspan="7"| CGRAM/DDRAM address
 +
 
|| Reads busy flag (BF) indicating internal operation being performed and reads CGRAM or DDRAM address counter contents (depending on previous instruction).
 
|| Reads busy flag (BF) indicating internal operation being performed and reads CGRAM or DDRAM address counter contents (depending on previous instruction).
|align="center"| 0 μs
+
 
 +
 
 +
 
 
|-
 
|-
 +
 
|| Write CGRAM or<br> DDRAM
 
|| Write CGRAM or<br> DDRAM
 +
 
|align="center" style="border-right: 0px;"| 1
 
|align="center" style="border-right: 0px;"| 1
 +
 
|align="center" style="border-right: 0px; border-left: 0px;"| 0
 
|align="center" style="border-right: 0px; border-left: 0px;"| 0
 +
 
|align="center" style="border-left: 1px dashed;" colspan="8"| Write Data
 
|align="center" style="border-left: 1px dashed;" colspan="8"| Write Data
 +
 
|| Write data to CGRAM or DDRAM.
 
|| Write data to CGRAM or DDRAM.
|align="center"| 37 μs
+
 
 +
 
 +
 
 
|-
 
|-
 +
 
|| Read from CG/DDRAM
 
|| Read from CG/DDRAM
 +
 
|align="center" style="border-right: 0px;"| 1
 
|align="center" style="border-right: 0px;"| 1
 +
 
|align="center" style="border-right: 0px; border-left: 0px;"| 1
 
|align="center" style="border-right: 0px; border-left: 0px;"| 1
 +
 
|align="center" style="border-left: 1px dashed;" colspan="8"| Read Data
 
|align="center" style="border-left: 1px dashed;" colspan="8"| Read Data
 +
 
|| Read data from CGRAM or DDRAM.
 
|| Read data from CGRAM or DDRAM.
|align="center"| 37 μs
+
 
 
|-
 
|-
 +
 
|colspan="13" style="font-size: 90%;"| '''Instruction bit names —'''<br>
 
|colspan="13" style="font-size: 90%;"| '''Instruction bit names —'''<br>
 +
 
'''I/D''' - 0 = decrement cursor position, 1 = increment cursor position;
 
'''I/D''' - 0 = decrement cursor position, 1 = increment cursor position;
 +
 
'''S''' - 0 = no display shift, 1 = display shift;
 
'''S''' - 0 = no display shift, 1 = display shift;
 +
 
'''D''' - 0 = display off, 1 = display on;
 
'''D''' - 0 = display off, 1 = display on;
 +
 
'''C''' - 0 = cursor off, 1 = cursor on;
 
'''C''' - 0 = cursor off, 1 = cursor on;
 +
 
'''B''' - 0 = cursor blink off, 1 = cursor blink on ;
 
'''B''' - 0 = cursor blink off, 1 = cursor blink on ;
 +
 
'''S/C''' - 0 = move cursor, 1 = shift display;
 
'''S/C''' - 0 = move cursor, 1 = shift display;
 +
 
'''R/L''' - 0 = shift left, 1 = shift right;
 
'''R/L''' - 0 = shift left, 1 = shift right;
 +
 
'''DL''' - 0 = 4-bit interface, 1 = 8-bit interface;
 
'''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);
 
'''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;
 
'''F''' - 0 = 5×8 dots, 1 = 5×10 dots;
 +
 
'''BF''' - 0 = can accept instruction, 1 = internal operation in progress.
 
'''BF''' - 0 = can accept instruction, 1 = internal operation in progress.
 +
 
|}
 
|}

Revision as of 11:05, 21 December 2013


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.

16x2 LCD

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.

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.

Fig 1: LCD Block diagram

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 0X41(hex) or 65(dec) decodes it into a dot matrix of 5x9 as shown in figure 2.

Fig2: LCD_turn_on

It is also possible to generate dot matrix patterns for custom characters and special symbols.

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 NUMBER FUNCTION
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

Instruction Set

The HD44780 instruction set is shown below:

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).


Set CGRAM address 0 0 0 1 CGRAM address Sets the CGRAM address. CGRAM data are sent and received after this setting.


Set DDRAM address 0 0 1 DDRAM address Sets the DDRAM address. DDRAM data are sent and received after this setting.


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.


Read from CG/DDRAM 1 1 Read Data Read data from 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.