Module4_1_LCD.pdf
Document Details
Uploaded by Ameera
University of Sharjah
Full Transcript
Embedded Systems Design Digital I/O - LCD Dr. Bilal Arain Parallel I/O Ports - Example Liquid Crystal Display (LCD) Liquid Crystal Displays (LCDs) are one of the most used devices for alphanumeric output in microcontroller-based circuits. LCDs are classified accordi...
Embedded Systems Design Digital I/O - LCD Dr. Bilal Arain Parallel I/O Ports - Example Liquid Crystal Display (LCD) Liquid Crystal Displays (LCDs) are one of the most used devices for alphanumeric output in microcontroller-based circuits. 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. Serial LCDs are considerably more expensive than parallel. The most widely and commonly used LCD devices are based on the Hitachi HD44780 character-based controller. Serial versus Parallel Interface The Hitachi HD44780 Controller The HD44780 is a dot-matrix liquid crystal display controller and driver. The device displays ASCII alphanumeric characters and some symbols. The HD44780 has an internal data memory called Data Display RAM (DDRAM) that can store the ASCII codes for up to 80 alphanumeric characters. These characters can be displayed in one or two lines. The Hitachi HD44780 Controller The LCD modules have a digital interface for the transfer of data and control signals between the module and the microcontroller. This interface consists of three control lines and four or eight data lines. Example interface of a PIC microcontroller and an LCD module using Port A and Port B. HD44780 The Hitachi HD44780 Hardware Elements 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 RAM area of display data (DDRAM) – 80 bytes (The displayed data stored in DDRAM) Character Generator RAM (CGRAM) – (CGRAM stores the user-defined character set) Character Generator ROM (CGROM) – (CGROM stores the fixed character set of the LCD) Timing generation circuit Liquid crystal display driver circuit Cursor and blink control circuit LCD Functions and Components Internal Registers The Instruction Register allows users to send commands, such as clearing the display, cursor at home, etc. The Data register allows the users to send/receive data to/from the LCD The Data register temporarily stores data read from Display Data RAM (DDRAM). Data placed in the data register is automatically written into Display Data RAM (DDRAM) by an internal operation. CGROM, Data Register and DDRAM: A Breakdown CGROM provides the basic building blocks (pixel patterns) for characters. Used by the LCD controller to convert ASCII codes into corresponding pixel patterns. Data Register acts as a temporary holding place for ASCII codes. Acts as a buffer between the microcontroller and the LCD controller. DDRAM stores the complete message, including the ASCII codes and their corresponding pixel patterns. Holds the final data that the LCD controller uses to generate the display. Example Interface: Hitachi HD44780 Register Select (RS): If RS=0 signal being sent through DB0- DB7 is a instruction signal If RS =1 signal being sent through DB0-DB7 is a data signal Read/write (R/W). This signal indicates reading (RW = 1) or writing (RW = 0). Enable (E). E = 1 enables the device. Example interface of a PIC microcontroller and an LCD Data bus (DB0-DB7). Bidirectional lines module using Port A and Port B. that transmit data and control signals. Communication Modes The LCD Controller can communicate with the PIC 16F877 in two modes: 4-bit mode 8-bit mode 4-bit mode and 8-bit mode in the HD44780 LCD controller refer to the number of data bits used to communicate with the microcontroller. 4-bit mode: In this mode, the LCD controller communicates with the microcontroller using 4 data lines. This means that each command or data byte is transmitted in two 4-bit chunks. 8-bit mode: In this mode, the LCD controller communicates with the microcontroller using 8 data lines. This means that each command or data byte is transmitted in a single 8-bit chunk. Communication Modes 4-bit mode DB0-DB3 are not used DB4-DB7 are used to transfer the data to/from the microcontroller Two clock cycles are required to transfer one data byte In the first clock cycle, the high 4 bits are transferred In the second clock cycle, the low 4-bits are transferred 8-bit mode DB0 – DB7 are used to transfer data to/from the microcontroller One clock is required to transfer one data byte Used to speed up transferring data to/from the microcontroller HD44780 Instruction Set The HD44780 instruction set includes operators to initialize the system and set operational Modes: clear the display, manipulate the cursor, set, reset, and control automatic Display address shift, set and reset the interface parameters, poll the busy flag, HD44780 Instruction Set LCD Lab: Commands and Instruction set Write Cycle - Timing Diagram The Enable line acts like a clock signal. The LCD controller reads all eight of its data pins each time the Enable pin is pulsed (falling edge). LCD Programming Example Example: The LCD module is connected to the PIC 16F877 microcontroller and is shown in the schematic. Write a simple code to initialize the LCD. TRIS & Ports: LCD Programming Example Example Code to setup TRIS and Port TRISD=0x00; TRISE=0x00; PORTEbits.RE1=0; // Enable = 0 PORTEbits.RE0=0; // RS = 0 (Control) Clear Display - LCD Programming Example Example Code to Clear Display PORTEbits.RE0=0; //RS=0 for control PORTD=0x01; // Clear display code // Toggle Enable PIN to write to LCD PORTEbits.RE1 = 1; delay_fn(3); PORTEbits.RE1 = 0; delay_fn(3); LCD Programming Example Code in MPLAB-X IDE Helper Functions Main Function LCD Programming Example Code in MikroC