Exp7 LCD
Exp7 LCD
LCD
The model described here is for its low price and great capabilities most frequently used in practice
(LM016L LCD). It is based on the HD44780 microcontroller (Hitachi) and can display messages in
two lines with 16 characters each.
It displays all the letters of alphabet, Greek letters, punctuation marks, mathematical symbols etc. In
addition, it is possible to display symbols made up by the user. Other useful features include automatic
message shift (left and right), cursor appearance, LED backlight etc.
Function Description:
Registers
The HD44780U has two 8-bit registers, an instruction register (IR) and a data register (DR). The
IR stores instruction codes, such as display clear and cursor shift, and address information for
display data RAM (DDRAM) and character generator RAM (CGRAM).
The IR can only be written from the MPU. The DR temporarily stores data to be written into
DDRAM or CGRAM and temporarily stores data to be read from DDRAM or CGRAM.
Data written into the DR from the MPU is automatically written into DDRAM or CGRAM by
an internal operation. The DR is also used for data storage when reading data from DDRAM or
CGRAM. When address information is written into the IR, data is read and then stored into the
DR from DDRAM or CGRAM by an internal operation.
Memory
In 16×2 LCD controller HD44780, there are three memory are available to store characters,
numbers and special symbols. Which are DDRAM (data display RAM) which stores ASCII
codes, CGROM (character generating ROM) which is responsible for stored standard character
pattern, and CGRAM (character generating RAM) which holds custom character pattern space
total 8 in 2×16 module.
LCD Display
Along one side of a small printed board there are pins used for connecting to the
microcontroller. There are in total of 14 pins marked with numbers (16 if the backlight is built
in). Their function is described in the table below:
LCD Screen Modes
D0-D7 is the data bus and is used to pass commands and characters to the LCD. Data can be
transferred to and from the display either as a single 8-bit byte or two 4-bit nibbles.
In the second case only the upper four data lines (D4-D7) are used. This 4-bit mode is beneficial when
using a microcontroller with few input/output pins available.
For example, a character in both uppercase ‘A’ and lowercase ‘a’ is designed by energizing corresponding pixels as
shown below.
All these eight hexadecimal codes (referred as character pattern) of each character are stored in
character generator ROM (CGROM) area.
The Display Data RAM (DDRAM) stores the ASCII code of a character which is sent by the
microcontroller. Now the LCD controller (HD44780) maps the corresponding ASCII
Code in DDRAM with CGROM address to bring the hexadecimal codes (character pattern) of that
particular character. By using those hexadecimal codes the 5x7 matrix segment will light according to
that character pattern to display corresponding character on it as shown in figure 3.2.
Displaying Custom Characters on LCD display
To create custom characters on LCD, the display controller (HD44780) make use of CGRAM area to
store hexadecimal codes (character pattern) which are designed by user. In addition to CGRAM area,
DDRAM area is also used to store the CGRAM address of a particular character, which is sent by
microcontroller in hexadecimal format.
Lab Work
Lab Work 1
You are going to use these keywords when you search for parts in Proteus:
Write and simulate a program that displays your name on an LCD
int main()
{
unsigned char name[] = "ENCS4110";
IO1DIR = 0x00FE0000; /* LCD pins set as o/p????????? */
LCD_Init(); /* Initialise LCD */
while(1) {
LCD_Command1(FIRST_ROW);
LCD_String(name);
Delay(50);
LCD_Command1(SECOND_ROW);
LCD_String("Lab");
Delay(50);
}
Proteus: (lab work 1)
U1
62 19
XTAL1 P0.0/TxD0/PWM1
61 21
XTAL2 P0.1/RxD0/PWM3/EINT0
22
P0.2/SCL0/CAP0.0
3 26
RTXC1 P0.3/SDA0/MAT0..0/EINT1
5 27
RTXC2 P0.4/SCK0/CAP0.1/AD0.6
29
P0.5/MISO0/MAT0.1/AD0.7
57 30
RST P0.6/MOSI0/CAP0.2/AD1.0
31
P0.7/SSEL0/PWM2/EINT2
33
P0.8/TxD1/PWM4/AD1.1
34
P0.9/RxD1/PWM6/EINT3
35
P0.10/RTS1/CAP1.0/AD1.2
37
P0.11/CTS1/CAP1.1/SCL1
38
P0.12/DSR1/MAT1.0/AD1.3
39
P0.13/DTR1/MAT1.1/AD1.4
41
P0.14/DCD1/EINT1/SDA1
45
P0.15/RI1/EINT2/AD1.5
46 LCD1
P0.16/EINT0/MAT0.2/CAP0.2 LM016L
47
P0.17/CAP1.2/SCK1/MAT1.2 +5.0v
53
P0.18/CAP1.3/MISO1/MAT1.3
54
P0.19/MAT1.2/MOSI1/CAP1.2 RV1
55
P0.20/MAT1.3/SSEL1/EINT3 +5.0v
1
P0.21/PWM5/AD1.6/CAP1.3
2
P0.22/AD1.7/CAP0.0/MAT0.0
58
P0.23
VDD
VSS
VEE
9
RW
RS
D0
D1
D2
D3
D4
D5
D6
D7
P0.25/AD0.4/AOUT
E
10
P0.26/AD0.5
11 1k
+3.3v P0.27/AD0.0/CAP0.1/MAT0.1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
13
P0.28/AD0.1/CAP0.2/MAT0.2
14
P0.29/AD0.2/CAP0.3/MAT0.3
15
P0.30/AD0.3/EINT3/CAP0.0
17
P0.31
16
P1.16/TRACEPKT0
12
+3.3v P1.17/TRACEPKT1
49 8
VBAT P1.18/TRACEPKT2
4
P1.19/TRACEPKT3
63 48
VREF P1.20/TRACESYNC
7 44
V3A P1.21/PIPESTAT0
51 40
V3 P1.22/PIPESTAT1
43 36
V3 P1.23/PIPESTAT2
23 32
V3 P1.24/TRACECLK
28
P1.25/EXTIN0
59 24
VSSA P1.26/RTCK
50 64
VSS P1.27/TDO
42 60
VSS P1.28/TDI
25 56
VSS P1.29/TCK
18 52
VSS P1.30/TMS
6 20
VSS P1.31/TRST
LPC2138
Lab Work 2
You are going to use these keywords when you search for parts in Proteus:
Write a program that displays your name on LCD with movement. Your program should allow the
user to control the direction of the movement (shift left, right, clear or move to the second row) using
push buttons.
Keil: (lab work 2)
// Do not forget to copy the other LCD functions from the lab work 1 above.
#include <lpc213x.h>
#define RS 0x00020000 /* RS - P1.17 */
#define RW 0X00040000 /* R/W - P1.18 */
#define EN 0X00080000 /* E - P1.19 */
#define CLR 0X00FE0000
#define FIRST_ROW 0x80
#define SECOND_ROW 0xC0
#define LCD_CLEAR 0x01
int main()
{
unsigned char name[] = "ENCS4110";
int col = 0, row = 0;
IO1DIR = 0x00FE0000; /* LCD pins set as output P1.16 ..P1.19 */
IO0DIR &= (0xFFFFFFF0); //Push button keys as inputs P0.0 ..P0.3
LCD_Init(); /* Initialise LCD */
while(1) {
R2 R4 R3
R1 10k 10k 10k
10k
U1 Left
62 19
XTAL1 P0.0/TxD0/PWM1
61 21
XTAL2 P0.1/RxD0/PWM3/EINT0
22
P0.2/SCL0/CAP0.0
3 26 Right
RTXC1 P0.3/SDA0/MAT0..0/EINT1
5 27
RTXC2 P0.4/SCK0/CAP0.1/AD0.6
29
P0.5/MISO0/MAT0.1/AD0.7
57 30
RST P0.6/MOSI0/CAP0.2/AD1.0
31 Jump
P0.7/SSEL0/PWM2/EINT2
33
P0.8/TxD1/PWM4/AD1.1
34
P0.9/RxD1/PWM6/EINT3
35 Reset
P0.10/RTS1/CAP1.0/AD1.2
37
P0.11/CTS1/CAP1.1/SCL1
38
P0.12/DSR1/MAT1.0/AD1.3
39
P0.13/DTR1/MAT1.1/AD1.4
41
P0.14/DCD1/EINT1/SDA1
45
P0.15/RI1/EINT2/AD1.5
46 LCD1
P0.16/EINT0/MAT0.2/CAP0.2 LM016L
47
P0.17/CAP1.2/SCK1/MAT1.2 +5.0v
53
P0.18/CAP1.3/MISO1/MAT1.3
54
P0.19/MAT1.2/MOSI1/CAP1.2 RV1
55
P0.20/MAT1.3/SSEL1/EINT3 +5.0v
1
P0.21/PWM5/AD1.6/CAP1.3
2
P0.22/AD1.7/CAP0.0/MAT0.0
58
P0.23
VDD
VSS
VEE
9
RW
RS
D0
D1
D2
D3
D4
D5
D6
D7
P0.25/AD0.4/AOUT
E
10
P0.26/AD0.5
11 1k
+3.3v P0.27/AD0.0/CAP0.1/MAT0.1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
13
P0.28/AD0.1/CAP0.2/MAT0.2
14
P0.29/AD0.2/CAP0.3/MAT0.3
15
P0.30/AD0.3/EINT3/CAP0.0
17
P0.31
16
P1.16/TRACEPKT0
12
+3.3v P1.17/TRACEPKT1
49 8
VBAT P1.18/TRACEPKT2
4
P1.19/TRACEPKT3
63 48
VREF P1.20/TRACESYNC
7 44
V3A P1.21/PIPESTAT0
51 40
V3 P1.22/PIPESTAT1
43 36
V3 P1.23/PIPESTAT2
23 32
V3 P1.24/TRACECLK
28
P1.25/EXTIN0
59 24
VSSA P1.26/RTCK
50 64
VSS P1.27/TDO
42 60
VSS P1.28/TDI
25 56
VSS P1.29/TCK
18 52
VSS P1.30/TMS
6 20
VSS P1.31/TRST
LPC2138
Lab work 3
Write a program that displays "Hello" at the 1st raw and “World” on the 2nd raw on the
LCD. ( The upper word should be firstly appears from the left of the LCD then it is
shifted continually to the other side. The lower word must have the opposite movement at
the time .All that happen after a button press from the user )