Chapter 8 - LCD

Download as pdf or txt
Download as pdf or txt
You are on page 1of 32

HCMC University of Technology and Education

Faculty of Electrical & Electronic Engineering


No.1 Vo Van Ngan Street, Thu Duc Dist., HCMC, VN

MICROCONTROLLERS

NGUYEN THANH NGHIA , PhD


6/23/2023 11
NGUYEN THANH NGHIA
HCMC University of Technology and Education
Faculty of Electrical & Electronic Engineering
No.1 Vo Van Ngan Street, Thu Duc Dist., HCMC, VN

CHAPTER 8:
LCD

NGUYEN THANH NGHIA , PhD


6/23/2023 22
NGUYEN THANH NGHIA
Outline
1. LCD Structure (HD44780 LCD).
2. DDRAM Memory (Display Data
RAM).
3. Important commands.
4. Application.

NGUYEN THANH NGHIA 3


Chapter 8: LCD
1. LCD Structure (HD44780 LCD)
❖ An alphanumeric low cost LCD Display is very
essential for may small and big projects to
Display various type of information.
❖ Hitachi HD44780 Chipset based 16x2 char LCD is
Really very cheap and easily available in the local
market.

NGUYEN THANH NGHIA 4


Chapter
PIN NUMBER8:SYMBOL
LCD FUNCTION
1 Vss GND
1. LCD Structure (HD44780 LCD)
2 Vdd + 3V or + 5V
❖ An3 alphanumeric
Vo low costAdjustment
Contrast LCD Display is very
essential
4 for
RS may H/L small and
Register Select big
Signal projects to
5 R/W H/L Read/Write Signal
Display
6
various
E
type ofH information.
→ L Enable Signal
❖ Hitachi
7 HD44780
DB0 Chipset based
H/L Data Bus Line16x2 char LCD is
8 very DB1
Really cheap andH/Leasily
Data Busavailable
Line in the local
9 DB2 H/L Data Bus Line
market.
10 DB3 H/L Data Bus Line
11 DB4 H/L Data Bus Line
12 DB5 H/L Data Bus Line
13 DB6 H/L Data Bus Line
14 DB7 H/L Data Bus Line
15 A/Vee + 3.5V for LED/Negative Voltage Output
16 K K Power
NGUYEN Supply
THANH for B/L (OV)
NGHIA 5
Chapter 8: LCD
1. Introduction

NGUYEN THANH NGHIA 6


Chapter 8: LCD LCD CONNECT
1. Introduction

NGUYEN THANH NGHIA 7


Chapter 8: LCD
1. Introduction
• DB0 - DB7, the 8 data bus lines, which perform
read/write of data
• Vss, Vdd - Voltage supply pins
• R/W – Pin writing/reading to/from - LCD
• RS - Pin selects registers between Instruction Register
and Data Register
• E - "Enabling" pin; when this pin is set to logical low,
the LCD does not care what is happening with R/W, RS,
and the data bus lines; when this pin is set to logical high,
the - LCD is processing the incoming data
• Vo - Pin for LCD contrast

NGUYEN THANH NGHIA 8


Chapter 8: LCD
1. Introduction

NGUYEN THANH NGHIA 9


Chapter 8: LCD
1. Introduction

NGUYEN THANH NGHIA 10


Chapter 8: LCD
1. Introduction

NGUYEN THANH NGHIA 11


Chapter 8: LCD
1. Introduction
LCD registers
The HD44780U controller has two 8-bit registers:
• an instruction register (IR) - 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).
• a data register (DR) - the DR temporarily stores data to be written into DDRAM
or CGRAM and temporarily stores data to be read from DDRAM or CGRAM. The
DR is also used for data storage when reading data from DDRAM or CGRAM.
The choice between the two registers is made by the register selector (RS) signal as
detailed the following table:

NGUYEN THANH NGHIA 12


Chapter 8: LCD
2. DDRAM Memory (Display Data RAM)
Display data RAM (DDRAM) stores the information we
send to LCD in ASCII Code. For each letter there is a
special code that represents it: for example, the letter A in
ASCII code, “receives” a value of 65 in base 10 or
01000001 in binary base, or 41 in the base 16. The
memory can contain up to 80 letters.

NGUYEN THANH NGHIA 13


Chapter 8: LCD
2. DDRAM Memory (Display Data RAM)
Some of the addresses represent the lines of LCD (0x00-
0x0F- first line; 0x40-0x4F – second line). The rest of the
addresses represent the “non-visible” memory of the
DRAM, which can be also used as a general memory. The
DDRAM address is the position of the cursor on the
display LCD (the received information will be written at
the place where the cursor is).

NGUYEN THANH NGHIA 14


Chapter 8: LCD
3. Important commands
COMMAND DESCRIPTION
0x38 Used 8 bit mode, enable display on 2 lines,
dot matrix is 5x7
0x0C Turn on display, turn off cursor
0X06 Cursor auto shift right
0x01 Clear display
0x80 Start address of line 1
0xC0 Start address of line 2

NGUYEN THANH NGHIA 15


Chapter 8: LCD
3. Important commands
STEPS TO WRITE LCD
1. Clear pin RW
2. Control pin RS base on what you want to write
❑ Command : RS = 0
❑ Data : RS = 1
3. Output what you want to write to data lines (D0-
D7)
4. Output one pulse from pin E
5. Delay to wait for LCD handling

NGUYEN THANH NGHIA 16


Chapter 8: LCD
3. Important commands
LCD instruction set
Clear Display:
This command clears the display and returns the cursor to the
home position (address 0) and sets I/D to 1 in order to
increment the cursor. Its line settings are as follows:

Home Cursor:
This returns the cursor to the home position, returns a shifted
display to the correct position, and sets the display data (DD)
RAM address to 0. Its line settings are as follows:

NGUYEN THANH NGHIA 17


Chapter 8: LCD
3. Important commands
LCD instruction set
Entry Mode Set:
This command sets the cursor move direction and specifies
whether toshift the display or not. These operations are
performed during the data write/read of the CG or DD RAM.
Its line settings are as follows:

I/D=0 means the cursor position is decremented (moves right to left).


I/D=1 means the cursor position is incremented (moves left to right).
S=0 means normal operation, the display remains still, and the cursor
moves.
S=1 means the display moves with the cursor.

NGUYEN THANH NGHIA 18


Chapter 8: LCD
3. Important commands
LCD instruction set
Display On/Off Control:
This command sets the ON/OFF display as well as the cursor
and blinking capabilities (0 equals OFF; 1 equals ON). D
controls whether the display is ON or OFF, C controls whether
the cursor is ON or OFF, B controls whether the blinking is
ON or OFF. The line settings are as follows:

NGUYEN THANH NGHIA 19


Chapter 8: LCD
3. Important commands
LCD instruction set
Cursor or Display Shift:
This moves the cursor and shifts the display without changing
DD RAM contents. The line settings are as follows:

S/C=0 means move the cursor.


S/C=1 means shift display.
R/L= 0 means shift to the left.
R/L= 1 means shift to the right.

NGUYEN THANH NGHIA 20


Chapter 8: LCD
3. Important commands
LCD instruction set
Function Set:
This sets the interface data length (DL), the number of display
lines (N), and character font (F). The line settings are as
follows:

DL=0 means 4 bits are being used (the standard)


DL=1 means a full 8 bits being utilized
N=0 means 1 line
N=1 means 2 lines or more
F=0 means that 5x7 dot characters are used (which is how 99% of all LCDs are
set up)
F=1 means 5x10 dot characters are used
NGUYEN THANH NGHIA 21
Chapter 8: LCD
4. Application
4.1 Display information on LCD
❖ Create a program to display information on two line of
LCD with the content as follows:

NGUYEN THANH NGHIA 22


Chapter 8: LCD
4. Application
4.1 Display information on LCD
❖ Schematic:

NGUYEN THANH NGHIA 23


Chapter 8: LCD
4. Application
4.1 Display information on LCD
❖ Flowchart:

NGUYEN THANH NGHIA 24


Chapter 8: LCD
4. Application
4.1 Display information on LCD
#INCLUDE <TV_16F887.C> ❖ Code:
#INCLUDE <TV_LCD.C>
UNSIGNED INT I;
const unsigned char HANG1[16]={" DH SP KY THUAT "};
const unsigned char HANG2[16]={" TP HO CHI MINH "};
VOID MAIN()
{
SET_TRIS_E(0x00);
SET_TRIS_D(0x00);
LCD_SETUP();
LCD_COMMAND(ADDR_LINE1);
DELAY_US(10);
FOR (I=0;I<16;I++) { LCD_DATA(HANG1[I]);}
LCD_COMMAND(ADDR_LINE2);
DELAY_US(10);
FOR (I=0;I<16;I++) { LCD_DATA(HANG2[I]);}
while(TRUE) {}
}

NGUYEN THANH NGHIA 25


Chapter 8: LCD
4. Application ❖ Code (TV_LCD.C):
4.1 Display information on LCD
void LCD_COMMAND(UNSIGNED CHAR MDK) //RS = 0
{
#IFNDEF LCD_RS
OUTPUT_LOW(LCD_RS); OUTPUT_LCD(MDK);
#DEFINE LCD_RS PIN_E0
OUTPUT_HIGH(LCD_E); DELAY_US(20);
#ENDIF
#IFNDEF LCD_RW OUTPUT_LOW(LCD_E); DELAY_US(20);
#DEFINE LCD_RW PIN_E1 }
#ENDIF void LCD_DATA(UNSIGNED CHAR MHT) //RS = 1
#IFNDEF LCD_E {
#DEFINE LCD_E PIN_E2 OUTPUT_HIGH(LCD_RS); OUTPUT_LCD(MHT);
#ENDIF OUTPUT_HIGH(LCD_E); DELAY_US(20);
#IFNDEF OUTPUT_LCD OUTPUT_LOW(LCD_E); DELAY_US(20);
#define OUTPUT_LCD OUTPUT_D }
#ENDIF void LCD_SETUP()
#DEFINE FUNCTION_SET 0X38 {
OUTPUT_LOW(LCD_E);
//GIAO TIEP 8 BIT, 2 HANG
OUTPUT_LOW(LCD_RS);
#DEFINE DISPLAY_CONTROL 0X0F
OUTPUT_LOW(LCD_RW);
#DEFINE CLEAR_DISPLAY 0X01 LCD_COMMAND(FUNCTION_SET); DELAY_MS(1);
#DEFINE ENTRY_MODE 0X06 LCD_COMMAND(DISPLAY_CONTROL);
#DEFINE SHIFT_LEFT 0X18 LCD_COMMAND(CLEAR_DISPLAY); DELAY_MS(2);
#DEFINE SHIFT_RIGHT 0X1C LCD_COMMAND(ENTRY_MODE);
#DEFINE ADDR_LINE1 0X80 }
#DEFINE ADDR_LINE2 0XC0
NGUYEN THANH NGHIA 26
Chapter 8: LCD
4. Application
4.2 Clock counter and display on LCD
❖ Create a program to display the message on two lines
of LCD as in Figure below. In particular, two characters
in the end of line 1 represent the second value of counter.

NGUYEN THANH NGHIA 27


Chapter 8: LCD
4. Application
4.2 Clock counter and display on LCD
❖ Create a program to display the message on two lines
of LCD as in Figure below. In particular, two characters
in the end of line 1 represent the second value of counter.

NGUYEN THANH NGHIA 28


Chapter 8: LCD
4. Application
4.2 Clock counter and display on LCD
❖ Code: VOID MAIN()
{
#INCLUDE<TV_16F887.C>
SET_TRIS_E(0x00); SET_TRIS_D(0x00);
#INCLUDE<TV_LCD.C> LCD_SETUP();
UNSIGNED CHAR I, GIAY; LCD_COMMAND(ADDR_LINE1); DELAY_US(10);
const unsigned char HANG1[16]={"DONG FOR (I=0;I<16;I++) {
HO: "}; LCD_DATA(HANG1[I]);}
LCD_COMMAND(ADDR_LINE2); DELAY_US(10);
const unsigned char HANG2[16]={"*TP FOR (I=0;I<16;I++) {
HO CHI MINH*"}; LCD_DATA(HANG2[I]);}
VOID LCD_HIENTHI() while(TRUE)
{ {
FOR(GIAY=0;GIAY<60;GIAY++)
LCD_COMMAND(0x8E); DELAY_US(10); {
LCD_DATA((GIAY/10)+0X30); LCD_HIENTHI();
LCD_DATA((GIAY%10)+0X30);
} DELAY_MS(1000);
}
}
}

NGUYEN THANH NGHIA 29


Chapter 8: LCD
4. Application
4.2 Clock counter and display on LCD
❖ Create a program to display the message on two lines
of LCD as in Figure below. In particular, two characters
SS in line 1 represent the second value of counter and
two characters MM in line 1 represent the minute value
of counter .

NGUYEN THANH NGHIA 30


Chapter 8: LCD
4. Application
4.2 Clock counter and display on LCD
VOID MAIN()
❖ Code: {
SET_TRIS_E(0x00); SET_TRIS_D(0x00);
#INCLUDE<TV_16F887.C> LCD_SETUP();
#INCLUDE<TV_LCD.C> LCD_COMMAND(ADDR_LINE1); DELAY_US(10);
UNSIGNED CHAR I, GIAY,PHUT; FOR (I=0;I<16;I++) {
LCD_DATA(HANG1[I]);}
const unsigned char HANG1[16]={"DONG LCD_COMMAND(ADDR_LINE2); DELAY_US(10);
HO: "}; FOR (I=0;I<16;I++) {
const unsigned char HANG2[16]={"*TP LCD_DATA(HANG2[I]);}
HO CHI MINH*"}; PHUT=0;
while(TRUE)
VOID LCD_HIENTHI()
{
{ FOR(GIAY=0;GIAY<60;GIAY++)
LCD_COMMAND(0x8B); DELAY_US(10); {
LCD_DATA((PHUT/10)+0X30); LCD_HIENTHI();
LCD_DATA((PHUT%10)+0X30);
DELAY_MS(1000);
LCD_DATA(0X20); }
LCD_DATA((GIAY/10)+0X30); IF (PHUT=60) {PHUT=0;}
LCD_DATA((GIAY%10)+0X30); ELSE {PHUT++;}
} }
}

NGUYEN THANH NGHIA 31


Chapter 8: LCD

The end!

NGUYEN THANH NGHIA 32

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy