
- •Table of Contents
- •Preface
- •Additional Material
- •Basic Electronics
- •1.0 The Atom
- •1.1 Isotopes and Ions
- •1.2 Static Electricity
- •1.3 Electrical Charge
- •1.4 Electrical Circuits
- •1.5 Circuit Elements
- •1.6 Semiconductors
- •Number Systems
- •2.0 Counting
- •2.1 The Origins of the Decimal System
- •2.2 Types of Numbers
- •2.3 Radix Representations
- •2.4 Number System Conversions
- •Data Types and Data Storage
- •3.0 Electronic-Digital Machines
- •3.1 Character Representations
- •3.2 Storage and Encoding of Integers
- •3.3 Encoding of Fractional Numbers
- •3.4 Binary-Coded Decimals (BCD)
- •Digital Logic, Arithmetic, and Conversions
- •4.0 Microcontroller Logic and Arithmetic
- •4.1 Logical Instructions
- •4.2 Microcontroller Arithmetic
- •4.3 Bit Manipulations and Auxiliary Operations
- •4.4 Unsigned Binary Arithmetic
- •4.5 Signed Binary Arithmetic
- •4.6 Data Format Conversions
- •Circuits and Logic Gates
- •5.0 Digital Circuits
- •5.1 The Diode Revisited
- •5.2 The Transistor
- •5.3 Logic Gates
- •5.4 Transistor-Transistor Logic
- •5.5 Other TTL Logic Families
- •5.6 CMOS Logic Gates
- •Circuit Components
- •6.0 Power Supplies
- •6.1 Clocked Logic and Flip-flops
- •6.2 Clocks
- •6.3 Frequency Dividers and Counters
- •6.4 Multiplexers and Demultiplexers
- •6.5 Input Devices
- •The Microchip PIC
- •7.0 The PICMicro Microcontroller
- •7.1 PIC Architecture
- •Mid-range PIC Architecture
- •8.0 Processor Architecture and Design
- •8.1 The Mid-range Core Features
- •8.2 Mid-Range CPU and Instruction Set
- •8.3 EEPROM Data Storage
- •8.4 Data Memory Organization
- •8.5 Mid-range I/O and Peripheral Modules
- •PIC Programming: Tools and Techniques
- •9.0 Microchip’s MPLAB
- •9.1 Integrated Development Environment
- •9.2 Simulators and Debuggers
- •9.3 Programmers
- •9.4 Engineering PIC Software
- •9.5 Pseudo Instructions
- •Programming Essentials: Input and Output
- •10.0 16F84A Programming Template
- •10.1 Introducing the 16F84A
- •10.2 Simple Circuits and Programs
- •10.3 Programming the Seven-segment LED
- •10.4 A Demonstration Board
- •Interrupts
- •11.0 Interrupts on the 16F84
- •11.1 Interrupt Sources
- •11.2 Interrupt Handlers
- •11.3 Interrupt Programming
- •11.4 Sample Programs
- •Timers and Counters
- •12.0 The 16F84 Timer0 Module
- •12.1 Delays Using Timer0
- •12.2 Timer0 as a Counter
- •12.3 Timer0 Programming
- •12.4 The Watchdog Timer
- •12.5 Sample Programs
- •LCD Interfacing and Programming
- •13.0 LCD Features and Architecture
- •13.1 Interfacing with the HD44780
- •13.2 HD44780 Instruction Set
- •13.3 LCD Programming
- •13.4 Sample Programs
- •Communications
- •14.0 PIC Communications Overview
- •14.1 Serial Data Transmission
- •14.2 Parallel Data Transmission
- •14.4 PIC Protocol-based Serial Programming
- •14.5 Sample Programs
- •Data EEPROM Programming
- •15.0 PIC Internal EEPROM Memory
- •15.1 EEPROM Devices and Interfaces
- •15.2 Sample Programs
- •Analog to Digital and Realtime Clocks
- •16.0 A/D Converters
- •16.1 A/D Integrated Circuits
- •16.2 PIC On-Board A/D Hardware
- •16.3 Realtime Clocks
- •16.4 Sample Programs
- •Index

Chapter 13
LCD Interfacing and Programming
This chapter is about programming liquid crystal displays and interfacing the LCD with the PIC 16f84 microcontroller. LCDs are one of the most used devices for alphanumeric output in microcontroller-based circuits. Their advantages are their reduced size and cost and the convenience of mounting the LCD directly on the circuit board.
LCDs are classified according to their interface into serial and parallel. Serial LCDs require less I/O resources but execute slower than their parallel counterparts.
In addition, they are considerably more expensive. In this chapter we discuss paral- lel-driven LCD devices based on the Hitachi HD44780 character-based controller, which is by far the most popular controller for PIC-driven LCDs. Serial interface with LCD devices is discussed in Chapter 13.
13.0 LCD Features and Architecture
The HD44780 is a dot-matrix liquid crystal display controller and driver. The device displays ASCII alphanumeric characters, Japanese kana characters, and some symbols. A single HD44780 can display up to two 28-character lines. An available extension diver makes possible addressing up to 80 characters.
The HD44780U contains a 9,920 bit character-generator ROM that produces a total of 240 characters: 208 characters with a 5 × 8 dot resolution and 32 characters at a 5 × 10 dot resolution. The device is capable of storing 64 x 8-bit character data in its character generator RAM. This corresponds to eight custom characters in 5 x 8-dot resolution or four characters in 5 x 10-dot resolution.
The controller is programmable to three different dy cycles: 1/8 for one line of 5 × 8 dots with cursor, 1/11 for one line of 5 × 10 dots with cursor, and 1/16 for two lines of 5 × 8 dots with cursor. The built-in commands include clearing the display, homing the cursor, turning the display on and off, turning the cursor on and off, setting display characters to blink, shifting the cursor and the display left-to-right or right-to-left, and reading and writing data to the character generator and to display data ROM.
275
276 |
Chapter 13 |
13.0.1 LCD Functions and Components
The following hardware elements form part of the HD44780 controller: two internal registers labeled the data register and the instruction register, a busy flag, an address counter, a RAM area of display data (DDRAM), a character generator ROM, a character generator RAM, a timing generation circuit, a liquid crystal display driver circuit, and a cursor and blink control circuit. The controller itself is often referred to as the MPU in the Hitachi literature.
Internal Registers
The HD44780 contains an IR (instruction register) and a DR (data register). The IR is used to store instruction codes, such as those to clear the display, define an address, or store a bit-map in character generator RAM. The IR is written only from the controller.
The data register, DR, is used to temporarily store data to be written into DDRAM or CGRAM as well as temporarily store data read from DDRAM or CGRAM. Data placed in the data register is automatically written into DDRAM or CGRAM by an internal operation.
Busy Flag
When BF (the busy flag) is 1, the HD44780U is in the internal operation mode, and the next instruction not accepted. The busy flag is mapped to data bit 7. Software must ensure that the busy flag is reset (BF = 0) before the next instruction is entered.
Address Counter
AC (the address counter) stores the current address used in operations that access
DDRAM or CGRAM. When an instruction contains address information, the address is stored in the address counter. The RAM area accessed—DDRAM or CGRAM—is also determined by the instruction that stores the address in the AC.
The AC is automatically incremented or decremented after each instruction that writes or reads DDRAM or CGRAM data. The variations and options in operations that change the AC are described later in this chapter.
Display Data RAM (DDRAM)
DDRAM (the display data RAM area) is used to store the 8-bit bitmaps that represent the display characters and graphics. Display data is represented in 8-bit character codes. When equipped with the extension, its capacity is 80 x 8 bits, or 80 characters. The area not used for storing display character can be used by software for storing any other 8-bit data. The mapping of DDRAM locations to the LCD display is discussed in Section 13.1.4.
Character Generator ROM (CGROM)
The character generator is a ROM that has the bitmaps for 208 characters in 5 x 8 dot resolution or 32 characters in 5 x 10 dot resolution. Figure 13-1 shows the standard character set in the HD44780.

LCD Interfacing and Programming |
277 |
||||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Figure 13-1 HD44780 Character Set
With a few exceptions, the characters in the range 0x20 to 0x7f correspond to those of the ASCII character set. The remaining characters are Japanese kana characters and special symbols. The characters in the range 0x0 to 0x1f,ASCII control characters, do not function as such in the HD44780. Sending a backspace (0x08), a bell (0x07), or a carriage return (0x0d) code to the controller has no effect.
Character Generator RAM (CGRAM)
CGRAM (the character generator RAM) allows the creation of customized characters by defining the corresponding 5 x 8 bitmaps. Eight custom characters can be stored in the 5 x 8 dot resolution and four in the 5 x 10 resolution. The creation and use of custom characters is addressed later in this chapter.
Timing Generation Circuit
This circuit produces the timing signals for the operation of internal components circuits such as DDRAM, CGROM, and CGRAM. The timing generation circuit is not accessible to the program.

278 |
Chapter 13 |
Liquid Crystal Display Driver Circuit
The liquid crystal display driver circuit consists of 16 common signal drivers and 40 segment signal drivers. The circuit responds to the number of lines and the character font selected. Once this is done, the circuit performs automatically and is not otherwise accessible to the program.
Cursor/Blink Control Circuit
The cursor and blink control circuit generates both the cursor and the character blinking. The cursor or the character blinking is applied to the character located in the data RAM address referenced in the address counter (AC).
13.0.2 Connectivity and Pin-Out
LCDs are powerful yet complex devices. Fortunately, the programmer does not have to deal with all the complexities of LCD displays since these devices are usually furnished in a module that includes the LCD controller. Furthermore, most LCDs used in microcontroller circuits are equipped with the same controller, the Hitachi HD44780. This controller provides a relatively simple interface between a microcontroller and the LCD.
But the fact that the HD44780 has become almost ubiquitous in LCD controller technology does not mean that these devices are without complications. The first difficulty confronted by the circuit designer is selecting the most appropriate LCD for the application among dozens (perhaps hundreds) of available configurations, each one with its own resolution, interface technology, size, graphics options, pin patterns, and other individual features. In this sense, it may be better to experiment with a simple LCD in a breadboard circuit before attempting a final circuit with hardware.
Two common connectors used with the 44780-based LCDs have either 14 pins in a single row, each pin spaced 0.100" apart, or two rows of eight pins each, also spaced 0.100" apart. In both cases, the pins are labeled in the LCD board. The two common connectors are shown in Figure 13-2.
14 |
1 |
14 13
2 1
Figure 13-2 Typical HD44780 Connector Pin-Outs