AN-908 APPLICATION NOTE One Technology Way • P.O. Box 9106 • Norwood, MA 02062-9106, U.S.A. • Tel: 781.329.4700 • Fax: 781.461.3113 • www.analog.com Interfacing the HD44780-Based Character LCD to an ADuC702x MicroConverter ADuC702x Development System INTRODUCTION A vast array of LCD displays are currently available and, fortunately, many of these LCDs comply with the HD44780U standard. This standard refers to the LCD controller chip, which accepts data from the ADuC702x and communicates with the LCD screen. HD44780 standard LCD screens are available in numerous formats, the most popular of which are the 16 × 2 and 20 × 2 formats. This application note describes the commands to control the basic functions of the LCD. Register Select Line (RS) INTERFACING WITH AN HD44780 LCD When this line is low, the information on the data bus is written to the LCD controller. If this line is high, the LCD controller can be read. This is used to check the status of the LCD. This line indicates to the LCD controller whether to treat the data byte as a command or as text data to be displayed on the screen. If the RS line is high, the data byte is treated as text to be displayed; if the RS line is low, the data byte is treated as a command. Read/Write Line (R/W) The data bus that connects the HD44780 to the MicroConveter® can be 8 or 4 bits wide; in this application note, only the case of an 8-bit data bus is examined. In addition to the data bus, three control lines are required; thus, a total of 11 pins are required to interface the LCD to the MicroConverter. As shown in Figure 1, the eight data lines connect to Port 1 of the MicroConverter, and the three control lines connect to Port 0.5, Port 0.7, and Port 2.0. The eight data lines that form the data bus, are referred to as DB0, and DB1 through DB7. The source code used to define this interface is given as follows: The three control lines are referred to as EN, RS and R/W. Their functions are as follows: unsigned char Init_MC08_LCD() Enable Line (EN) GP0DAT = 0xA0000000; // P0.5 = RS, EN = P0.7 This line indicates the start of a transmission of a data byte to the LCD controller. To indicate the start of transmission, this line is brought high; when transmission is complete, the EN line is brought low indicating that the transmission is complete. GP1DAT = 0xFF000000; // P1.[7:0] = DB[0:7] GP2DAT = 0x01000000; // P2.0 = R/W { return 0x1; } DB0 P1.1 DB1 P1.2 DB2 P1.3 DB3 P1.4 DB4 P1.5 DB5 P1.6 DB6 P1.7 DB7 P0.7 EN P0.5 RS P2.0 3.3V HD44780 R/W VO VDD VSS Figure 1. Connecting an HD44780 LCD to an ADuC702x Rev. 0 | Page 1 of 8 06695-001 ADuC702x P1.0 AN-908 TABLE OF CONTENTS Introduction ...................................................................................... 1 Setting the Entry Mode.....................................................................5 Interfacing with an HD44780 LCD................................................ 1 Writing Text to the LCD Screen ......................................................6 Configuring the LCD Screen .......................................................... 3 Notes and References ........................................................................7 Clearing the LCD Screen ................................................................. 4 Rev. 0 | Page 2 of 8 AN-908 CONFIGURING THE LCD SCREEN To display text to the LCD screen, the LCD screen must be configured first. The configuration defines to the LCD controller the type of LCD screen that is being used, as well as the data bus format and font. The various commands available are listed in detail in any data sheet for an HD44780U-based LCD module. In the example that follows, the LCD is configured to use an 8-bit data bus and display in a 5 × 7 dot character font. This configuration is achieved by sending 0x38 to the LCD controller through the Select_Function_Set function. unsigned char Select_Function_Set(unsigned char ucFunctionSet) { unsigned long ulFunction = 0; delay (10000); RdStatus = ReadStatus(); ulFunction = ucFunctionSet; ulFunction = (ulFunction << 16); ulFunction |= 0xFF000000; GP0DAT = 0xA0000000; //Clear RS pin(P0.5), clear E pin (P0.7) = R/W) GP2DAT = 0x01000000; //Clear R/W pin (P2.0 = R/W) delay (5); GP0SET = 0x800000; // Set E high delay (5); // Allow min 800 ns setup time GP1DAT = ulFunction; // Write to register delay (5); // allow hold time of 500 ns min GP0CLR = 0x800000; // Set E low delay (5); return 0x1; } The ReadStatus function is used to read the busy signal output from the HD44780 module. Rev. 0 | Page 3 of 8 AN-908 CLEARING THE LCD SCREEN Before writing to the screen, it must first be cleared. To do this, use the function, Clear_Display_LCD, as outlined in the following: unsigned char Clear_Display_LCD(unsigned char ucFunctionSet) { unsigned long ulFunction = 0; delay (10000); RdStatus = ReadStatus(); ulFunction = ucFunctionSet; ulFunction = (ulFunction << 16); ulFunction |= 0xFF000000; GP0DAT = 0xA0000000; //Clear RS pin(P0.5), clear E pin (P0.7) = R/W) GP2DAT = 0x01000000; //Clear R/W pin (P2.0 = R/W) delay (5); GP0SET = 0x800000; // Set E high delay (5); // Allow min 800 ns setup time GP1DAT = ulFunction; // Write to register delay (5); // Allow hold time of 500 ns min GP0CLR = 0x800000; // Set E low delay (2000); // Minimum clear time of 1.58 ms return 0x1; } Rev. 0 | Page 4 of 8 AN-908 SETTING THE ENTRY MODE The entry mode must also be set. For this example, the increment is on and there is no shifting. This is achieved by sending 0x6 to the LCD controller through the Set_Entry_Mode function, as follows: unsigned char Set_Entry_Mode(unsigned char ucFunctionSet) { unsigned long ulFunction = 0; delay (10000); RdStatus = ReadStatus(); ulFunction = ucFunctionSet; ulFunction = (ulFunction << 16); ulFunction |= 0xFF000000; GP0DAT = 0xA0000000; //Clear RS pin(P0.5), clear E pin (P0.7) = R/W) GP2DAT = 0x01000000; //Clear R/W pin (P2.0 = R/W) delay (5); GP0SET = 0x800000; // Set E high delay (5); // Allow min 800 ns setup time GP1DAT = ulFunction; // Write to register delay (5); // Allow hold time of 500 ns min GP0CLR = 0x800000; // Set E low delay (5); return 0x1; } Rev. 0 | Page 5 of 8 AN-908 WRITING TEXT TO THE LCD SCREEN In the sample program, the following text is written to the LCD screen: Analog Devices ADuC7020 LCDdemo To do this, use the Wr_Data_LCD function, after the screen is cleared. For example, to output the Character A, use its hexadecimal representation, 0x41. All other characters must be represented in their hexadecimal forms and sent to the function to be processed as follows: unsigned char Wr_Data_LCD(unsigned char ucFunctionSet) { unsigned long ulFunction = 0; delay (10000); RdStatus = ReadStatus(); ulFunction = ucFunctionSet; ulFunction = (ulFunction << 16); ulFunction |= 0xFF000000; GP0DAT = 0xA0200000; //Set RS pin(P0.5), clear E pin (P0.7) = R/W) GP2DAT = 0x01000000; //Clear R/W pin (P2.0 = R/W) delay (5); GP0SET = 0x800000; // Set E high delay (5); // Allow min 800 ns setup time GP1DAT = ulFunction; // Write to register delay (5); // Allow hold time of 500 ns min GP0CLR = 0x800000; // Set E low delay (5); GP0CLR = 0x200000; // Set RS low return 0x1; } Rev. 0 | Page 6 of 8 AN-908 NOTES AND REFERENCES The dot matrix LCD screen used in implementation of all the processes described in this application note was the Samsung S6A0070 driver and controller. See the Samsung website for more information on their products. Table 1. Analog Devices ADuC702x Series For information on specific Analog Devices, Inc. products in the ADuC702x family, select from among the products listed in Table 1. Part No. ADuC7020 ADuC7021 ADuC7022 ADuC7024 ADuC7025 ADuC7026 ADuC7027 ADuC7028 Rev. 0 | Page 7 of 8 No. GPIO Pins 14 13 13 30 30 40 40 40 No. ADC Channels 5 8 10 10 12 12 16 16 No. 12-Bit DAC Outputs 4 2 N/A 2 N/A 4 N/A 4 Temp. Range (°C) −40 to +105 −40 to +85 −40 to +85 −40 to +105 −40 to +105 −40 to +125 −40 to +125 −40 to +125 AN-908 NOTES ©2007 Analog Devices, Inc. All rights reserved. Trademarks and registered trademarks are the property of their respective owners. AN06695-0-6/07(0) Rev. 0 | Page 8 of 8