Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Microcontroller Programming. Thi Micro Chip PIC (Julio Sanchez, 2007).pdf
Скачиваний:
475
Добавлен:
12.08.2013
Размер:
4.99 Mб
Скачать

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