Sei sulla pagina 1di 19

Lab6: LCD Display with Arduino

LAB 6: LCD Display with Arduino

Introduction
! LCD modules can be split into two groups: those that have built-in
controller and driver chips, and those that have only driver chips. LCD
displays that do not have controllers are typically used with powerful
hardware, such as a laptop computer, where a video controller is available to
generate the complex drive signals necessary to run the display. Most color
and large (greater than 320x240) monochrome displays are of this type.

! The category of display modules that have built-in controllers can be


split again into character LCD modules and graphic LCD modules.
Character modules can display only text and perhaps some special symbols,
while graphic modules can display lines, circles, squares, and patterns in
addition to text. Some examples of graphic LCD controller chips are the
Toshiba T6963, Seiko-Epson SED1330, and Hitachi HD61202. Here, we will
be primarily concerned with character LCD modules that have the Hitachi
HD44780 controller built-in.

! Nearly every pixel-based alphanumeric LCD module made today uses


the Hitachi HD44780 LCD controller chip, or a derivative such as the
Seiko-Epson SED1278. This apparent standardization in character LCDs
has become extremely beneficial to design engineers and hobbyists. Dozens
of manufacturers produce literally hundreds of models of LCD modules using
this controller chip. The smallest of these displays is only one line of 8
characters; the largest is four lines of 40 characters each. Other common
sizes are 16x1,16x2, 20x1, 20x2, 20x4, 40x1, and 40x2 (characters x lines).
Microprocessor and Embedded Computer Systems! Sem.2 / 2013 ECE page 1 of 19
Lab6: LCD Display with Arduino

Interfacing LCD Module


! Most of the LCD Displays available in the market are 16X2 (That
means, the LCD displays are capable of displaying 2 lines each having 16
Characters a), 20X4 LCD Displays (4 lines, 20 characters). It has 14 pins. It
uses 8lines for parallel data plus 3 control signals, 2 connections to power,
one more for contrast adjustment and two connections for LED back light. Let
us have a look to typical pin configurations(Table1.):

Table1. Pin Configuration table for a 16X2 LCD character display:-


Pin Symbol Function
Number
1 Vss Ground Terminal
2 Vcc Positive Supply
3 Vdd Contrast adjustment
4 RS Register Select; 0Instruction Register, 1Data
Register
5 R/W Read/write Signal; 1Read, 0 Write
6 E Enable; Falling edge
7 DB0 Bi-directional data bus, data transfer is performed
8 DB1 once, thru DB0 to DB7, in the case of interface data
9 DB2 length is 8-bits; and twice, through DB4 to DB7 in the
10 DB3 case of interface data length is 4-bits. Upper four bits
11 DB4 first then lower four bits.
12 DB5
13 DB6
14 DB7
15 LED-(K) Back light LED cathode terminal
16 LED+(A) Back Light LED anode terminal
!
! LCD accepts two types of signals, one is data, and another is control.
These signals are recognized by the LCD module from status of the RS pin.
Now data can be read also from the LCD display, by pulling the R/W pin high.
As soon as the E pin is pulsed, LCD display reads data at the falling edge of
the pulse and executes it, same for the case of transmission.

! LCD display takes a time of 39-53S to place a character or execute a


command. Except for clearing display and to seek cursor to home position it
takes 1.53ms to 1.64ms. Any attempt to send any data before this interval
may lead to failure to read data or execution of the current data in some
devices. Some devices compensate the speed by storing the incoming data
to some temporary registers.
Microprocessor and Embedded Computer Systems! Sem.2 / 2013 ECE page 2 of 19
Lab6: LCD Display with Arduino

! LCD displays have two RAMs, naming DDRAM and CGRAM. DDRAM
registers in which position which character in the ASCII chart would be
displayed. Each byte of DDRAM represents each unique position on the LCD
display. The LCD controller reads the information from the DDRAM and
displays it on the LCD screen. CGRAM allows user to define their custom
characters. For that purpose, address space for first 16 ASCII characters are
reserved for users. After CGRAM has been setup to display characters, user
can easily display their custom characters on the LCD screen.

Fig1. Block Diagram of LCD

Interfacing to the Microprocessor and Microcontroller


The HD44780U can send data in either two 4-bit operations or one 8-bit
operation, thus allowing interfacing with 4- or 8-bit MPUs (Microprocessor
Units).

For 4-bit interface data, only four bus lines (DB4 to DB7) are used for
transfer. Bus lines DB0 to DB3 are disabled. The data transfer between
the HD44780U and the Microprocessor is completed after the 4-bit data
has been transferred twice. As for the order of data transfer, the four
high order bits (for 8-bit operation, DB4 to DB7) are transferred before
the four low order bits (for 8-bit operation, DB0 to DB3).
The busy flag must be checked (one instruction) after the 4-bit data has
been transferred twice. Two more 4-bit operations then transfer the
busy flag and address counter data.

Microprocessor and Embedded Computer Systems! Sem.2 / 2013 ECE page 3 of 19


Lab6: LCD Display with Arduino

Fig2. 4-Bit Transfer Example (more detail see HD44780U Data sheet) .
For 8-bit interface data, all eight bus lines (DB0 to DB7) are used.

Reset Function
1.Initializing by Internal Reset Circuit
! An internal reset circuit automatically initializes the HD44780U when
the power is turned on. The following instructions are executed during the
initialization. The busy flag (BF) is kept in the busy state until the initialization
ends (BF = 1).(more detail see HD44780U Data Sheet). The busy state lasts
for 10 ms after VCC rises to 4.5 V.

Microprocessor and Embedded Computer Systems! Sem.2 / 2013 ECE page 4 of 19


Lab6: LCD Display with Arduino

Instructions

Outline

Only the instruction register (IR) and the data register (DR) of the HD44780U
can be controlled by the MPU. Before starting the internal operation of the
HD44780U, control information is temporarily stored into these registers to
allow interfacing with various MPUs, which operate at different speeds, or
various peripheral control devices. The internal operation of the HD44780U is
determined by signals sent from the MPU. These signals, which include
register selection signal (RS), read/write signal (R/W), and the data bus (DB0
to DB7), make up the HD44780U instructions (Table 2). There are four
categories of instructions that:

Designate HD44780U functions, such as display format, data length,


etc.

Set internal RAM addresses

Perform data transfer with internal RAM

Perform miscellaneous functions

When an instruction is being executed for internal operation, no instruction


other than the busy flag/address read instruction can be executed.

Because the busy flag is set to 1 while an instruction is being executed,


check it to make sure it is 0 before sending another instruction from the MPU.

Note: Be sure the HD44780U is not in the busy state (BF = 0) before sending
an instruction from the MPU to the HD44780U. If an instruction is sent without
checking the busy flag, the time between the first instruction and next
instruction will take much longer than the instruction time itself. Refer to Table
2 for the list of each instruction execution time.

Microprocessor and Embedded Computer Systems! Sem.2 / 2013 ECE page 5 of 19


Lab6: LCD Display with Arduino

Table 2: LCD Instruction

Microprocessor and Embedded Computer Systems! Sem.2 / 2013 ECE page 6 of 19


Lab6: LCD Display with Arduino

2.Initializing by Instruction
If the power supply conditions for correctly operating the internal reset circuit
are not met, initialization by instructions becomes necessary. Refer to Figures
3 and 4 for the procedures on 8-bit and 4-bit initializations, respectively.

Fig.3 8-Bit Mode Initialization

Microprocessor and Embedded Computer Systems! Sem.2 / 2013 ECE page 7 of 19


Lab6: LCD Display with Arduino

Fig.4 4-Bit Mode Initialization

Fig.5 DDRAM address of 16x2 LCD

Microprocessor and Embedded Computer Systems! Sem.2 / 2013 ECE page 8 of 19


Lab6: LCD Display with Arduino

Fig.6 Frequency used commands and instructions for LCD (fromTable 2).

Example : 4-Bit Mode LCD Initialization With Delay Subroutine


(No Busy Flag Check)
! From 4-bit mode initialization flowchart in figure 4 can write a simple
step of program following this:
! 1. Wait for more 40 ms choose delay 50 ms
! 2. Write command 0x3=> 0x30 write high nibble 3 to LCD
! 3. Delay 4.1ms
! 4. Write command 0x3=> 0x30 write high nibble 3 to LCD
! 5. Delay 100us
! 6. Write command 0x3=> 0x30 write high nibble 3 to LCD
! 7. Delay 100us
! 8. Write command 0x2=> 0x20 write high nibble 2 to LCD
! 9. Delay 100us
10. Write command 0x28=>0x28 write high nibble 2 first ,
! [Set 2 Line 5*8dot] then write low nibble 8 to LCD
11. Delay 100us!
12. Write command 0x0C=>0x0C write high nibble 0 first ,
! [Display On,Cursor Off] then write low nibble C to LCD!

Microprocessor and Embedded Computer Systems! Sem.2 / 2013 ECE page 9 of 19


Lab6: LCD Display with Arduino

13. Delay 100us!


14. Write command 0x01=>0x01 write high nibble 0 first ,
! [Display Clear]!! then write low nibble 1 to LCD!
15. Delay 100us
16. Write command 0x06=>0x06 write high nibble 0 first ,
! [Entry Mode Set]! then write low nibble 6 to LCD!
17. Delay 100us
18. End of Initialze LCD

The LCD Initlalze subroutine show in figure 7.

Fig.7 Show LCD Initialize Subroutine


Microprocessor and Embedded Computer Systems! Sem.2 / 2013 ECE page 10 of 19
Lab6: LCD Display with Arduino

The two subroutines for write command to LCD :(show in figure 8)


- Sub. CMNDWRT41 => for write high nibble (send 4-bit one times) to LCD
and already have Delay_1us sub..
- Sub. CMNDWRT42 => for write high nibble and low nibble (Send 4-bit two-
times) and already have Delay_100us sub. and Delay_1us sub. .

Fig.8 Show write command subroutines CMNDWRT41,CMNDWRT42

Microprocessor and Embedded Computer Systems! Sem.2 / 2013 ECE page 11 of 19


Lab6: LCD Display with Arduino

The subroutine for write data to LCD: (show in figure 9)


- Sub. DATWRT42 => for write high nibble and low nibble (Send 4-bit two-
times) and already have Delay_100us sub. and Delay_1us sub.

Fig. 9 Show write data subroutines DATWRT42

! For write operation of LCD :

- write command and data that depend on an instruction register (IR) and a
data register (DR). If RS=0 => IR(Command), else => DR(Data)

- ex. write command => RS=0, R/W=0, and EN = 0->1 then 1->0

- The timing diagram of write operation is very important to design the


program. Figure 10 will show the assembly program that correspond to the
timing diagram.

Microprocessor and Embedded Computer Systems! Sem.2 / 2013 ECE page 12 of 19


Lab6: LCD Display with Arduino
Microprocessor and Embedded Computer Systems! Sem.2 / 2013 ECE page 13 of 19
Lab6: LCD Display with Arduino

Fig. 11 Show Clock Characteristic of LCD

From Table 2 see at the last column we can know the execution time of
instruction. The execution time depend on f(osc). The minimum f(osc) show in
figure 11 is 190MHz that mean the execution time of instruction more than
50 us. The Delay subroutine for LCD in a program we choose 100 us to wait
for the execution time of instruction.

MAIN Program
! 1.Declare
constant and
variables.
! 2.Initial
necessary value of
variables.
! 3.Initial Stack
and Direction port
! 4.Initial LCD 2
Line 16 columns 5x8
dot Matrix.
! 5.Polling for
send a string to the
LCD.

The main program


show in figure 12-13.

Fig. 12 Show initial Constant and variables of main program.


Microprocessor and Embedded Computer Systems! Sem.2 / 2013 ECE page 14 of 19
Lab6: LCD Display with Arduino

Fig. 13 Show the complete program of Main Program

Microprocessor and Embedded Computer Systems! Sem.2 / 2013 ECE page 15 of 19


Lab6: LCD Display with Arduino

Fig. 14 Show schematic diagram of LCD with Arduino.

Procedure I.
! 1. Use ISIS schematic capture of Proteus program draw the circuit
follow figure 14.
! 2. Write assembly program LCD 4-bit data mode correspond with
circuit in figure14.
! 3. Integrate main program and all subroutine follow figure 7 - 13 to
build a complete LCD assembly program.
! 4. Design all delay subroutine and some necessary code for
complement this program.
! 5. Use Atmel Studio complie this program and run the program with
circuit in figure 14 by ISIS-Proteus simulation.
! 6. Use Arduino UNO Board and Electronic parts from Arduino lab
box set build a real circuit from a figure 14.
! 7. Use Atmel Studio complie this program and upload hex files to
Arduino UNO Board for run the LCD program. (Hint:use external tools in
Menu Tools with some command line to upload ,so you have to find the
way from internet.)

Microprocessor and Embedded Computer Systems! Sem.2 / 2013 ECE page 16 of 19


Lab6: LCD Display with Arduino

! 8. Show the result both the simulation and the real hardware with a
staff of LAB. Send a short report and all assembly source code with their
comment and flow-chart.

Question (answer in a short report)


1.How the instruction LPM work? Give an example and explain it .
2.What is a busy flag in LCD? How to use busy flag for LCD program?

Fig. 15 Show Header and Main program C code for LCD 16x2 Line

Microprocessor and Embedded Computer Systems! Sem.2 / 2013 ECE page 17 of 19


Lab6: LCD Display with Arduino

Fig. 15 (cont.) Show Header and Main program C code for LCD 16x2 Line
Procedure II.
! 1.See C code in figure 15 that show header and main program for LCD
16x2 Line .Design body function of function prototype follow the
algorithm same previous assembly program in C language.
(Figure16:function prototype)

Fig. 16 Function Prototype for LCD program

Microprocessor and Embedded Computer Systems! Sem.2 / 2013 ECE page 18 of 19


Lab6: LCD Display with Arduino

! 2.Test program with the same circuit in Procedure I.Show the result
with a staff of LAB . Send a short report and all C source code with their
comment and flow-chart.

Question (answer in a short report)


1.Between Assembly and C language which language do you like? Give a
reason and compare both languages .
2. What is a intel hex file format ? How about hex code size of LCD
assembly program and C program?

Assignment
! 1.Write a C program for LCD show in 1st line Hello Thailand! and
2nd line . Show a result with a staff of LAB. Send a report and all
C source code with their comment and flow chart.

Microprocessor and Embedded Computer Systems! Sem.2 / 2013 ECE page 19 of 19

Potrebbero piacerti anche