11
LCD DISPLAY INTRODUCTION The most commonly used Character based LCDs are based on Hitachi's HD44780 controller or other which are compatible with HD44580. In this tutorial, we will discuss about character based LCDs, their interfacing with various microcontrollers, various interfaces (8-bit/4-bit), programming, special stuff and tricks you can do with these simple looking LCDs which can give a new look to your application. Pin Description The most commonly used LCDs found in the market today are 1 Line, 2 Line or 4 Line LCDs which have only 1 controller and support at most of 80 characters, whereas LCDs supporting more than 80 characters make use of 2HD44780controllers. Most

Lcd Display

Embed Size (px)

DESCRIPTION

lcd display commands mode pin connectoions

Citation preview

LCD DISPLAYINTRODUCTION The most commonly used Character based LCDs are based on Hitachi's HD44780 controller or other which are compatible with HD44580. In this tutorial, we will discuss about character based LCDs, their interfacing with various microcontrollers, various interfaces (8-bit/4-bit), programming, special stuff and tricks you can do with these simple looking LCDs which can give a new look to your application.Pin DescriptionThe most commonly used LCDs found in the market today are 1 Line, 2 Line or 4 Line LCDs which have only 1 controller and support at most of 80 characters, whereas LCDs supporting more than 80 characters make use of 2HD44780controllers. Most LCDs with 1 controller has 14 Pins and LCDs with 2 controller has 16 Pins (two pins are extra in both for back-light LED connections.

LCD HD44780 Pin Diagram

Pin No.NameDescription

Pin no. 1D7Data bus line 7 (MSB)

Pin no. 2D6Data bus line 6

Pin no. 3D5Data bus line 5

Pin no. 4D4Data bus line 4

Pin no. 5D3Data bus line 3

Pin no. 6D2Data bus line 2

Pin no. 7D1Data bus line 1

Pin no. 8D0Data bus line 0 (LSB)

Pin no. 9EN1Enable signal for row 0 and 1 (1stcontroller)

Pin no. 10R/W0 = Write to LCD module1 = Read from LCD module

Pin no. 11RS0 = Instruction input1 = Data input

Pin no. 12VEEContrast adjust

Pin no. 13VSSPower supply (GND)

Pin no. 14VCCPower supply (+5V)

Pin no. 15EN2Enable signal for row 2 and 3 (2ndcontroller)

Pin no. 16NCNot Connected

Table 4.2 LCD Pin Details

Commands and Instruction SetOnly the instruction register (IR) and the data register (DR) of the LCD can be controlled by the MCU. Before starting the internal operation of the LCD, control information is temporarily stored into these registers to allow interfacing with various MCUs, which operate at different speeds, or various peripheral control devices. which include register selection signal (RS), read/write signal (R/W), and the data bus (DB0 to DB7), make up the LCD instructions There are four categories of instructions that: Designate LCD functions, such as display format, data length, etc. Set internal RAM addresses Perform data transfer with internal RAM Perform miscellaneous functions

Figure. LCD Characters Code Map

Figure . LCD Characters Code Map For 5x10 Dots

LCD Interfacing with Microcontroller 4-Bit ModeNow whatever we discussed in the previous part of this LCD tutorial, we were dealing with 8-bit mode. Now we are going to learn how to use LCD in 4-bit mode. There are many reasons why sometime we prefer to use LCD in 4-bit mode instead of 8-bit. One basic reason is lesser number of pins are needed to interface LCD.In 4-bit mode the data is sent in nibbles, first we send the higher nibble and then the lower nibble. To enable the 4-bit mode of LCD, we need to follow special sequence of initialization that tells the LCD controller that user has selected 4-bit mode of operation. We call this special sequence as resetting the LCD. Following is the reset sequence of LCD. Wait for about 20mS Send the first init value (0x30) Wait for about 10mS Send second init value (0x30) Wait for about 1mS Send third init value (0x30) Wait for 1mS Select bus width (0x30 - for 8-bit and 0x20 for 4-bit) Wait for 1ms

The busy flag will only be valid after the above reset sequence. Usually we do not use busy flag in 4-bit mode as we have to write code for reading two nibbles from the LCD. Instead we simply put a certain ammount of delay usually 300 to 600uS. This delay might vary depending on the LCD you are using, as you might have a different crystal frequency on which LCD controller is running. So it actually depends on the LCD module you are using. So if you feel any problem running the LCD, simply try to increase the delay. This usually works. For me about 400uS works perfect.LCD (Liquid Crystal Display) screen is an electronic display module and find a wide range of applications. A 16x2 LCD display is very basic module and is very commonly used in various devices and circuits. These modules are preferred overseven segmentsand other multi segmentLEDs. The reasons being: LCDs are economical; easily programmable; have no limitation of displaying special & evencustom characters(unlike in seven segments),animationsand so on.

A16x2 LCDmeans it can display 16 characters per line and there are 2 such lines. In this LCD each character is displayed in 5x7 pixel matrix. This LCD has two registers, namely, Command and Data.

The commandregisterstores the command instructions given to the LCD. A command is an instruction given to LCD to do a predefined task like initializing it, clearing its screen, setting the cursor position, controlling display etc. The data register stores the data to be displayed on the LCD. The data is the ASCII value of the character to be displayed on the LCD.Clickto learn more about internal structure of aLCD.

Pin Description:Pin NoFunctionName

1Ground (0V)Ground

2Supply voltage; 5V (4.7V 5.3V)Vcc

3Contrast adjustment; through a variable resistorVEE

4Selects command register when low; and data register when highRegister Select

5Low to write to the register; High to read from the registerRead/write

6Sends data to data pins when a high to low pulse is givenEnable

78-bit data pinsDB0

8DB1

9DB2

10DB3

11DB4

12DB5

13DB6

14DB7

15Backlight VCC(5V)Led+

16Backlight Ground (0V)Led-

LCD InitializationBefore using the LCD for display purpose, LCD has to be initialized either by the internal reset circuit or sending set of commands to initialize the LCD. It is theuserwho has to decide whether an LCD has to be initialized by instructions or by internal reset circuit. we will dicuss both ways of initialization one by one.

Initialization by internal Reset CircuitAn 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). The busy state lasts for 10 ms after VCC rises to 4.5 V. Display clear Function set:DL = 1; 8-bit interface dataN = 0; 1-line displayF = 0; 5 x 8 dot character font Display on/off control:D = 0; Display offC = 0; Cursor offB = 0; Blinking off Entry mode set:I/D = 1; Increment by 1S = 0; No shiftThe 'Internal Reset' technique described above is relied upon by many programmers but, in my opinion, this is not a wise choice. Perhaps they are seduced by the first sentence with the promise of 'automatic' initialization. If you look at the result of this automatic initialization you will see that the controller is configured for a 1-line display when in fact the majority of LCD modules should be configured for a 2-line display. It also leaves the display off. This means that two of the four steps that were automatically performed are going to have to be redone.

But that is NOT the main reason that this technique should be avoided. The note at the bottom clearly states that this technique will fail if the power supply does not meet certain specifications, specifications that are buried elsewhere in the datasheet. In cases where the power supply cannot be guaranteed to meet those specification the datasheet recommends using "Initializing by Instruction".

Initialization by instructionsInitializing LCD with instructions is really simple. Given below is a flowchart that describles the step tofollow, to initialize the LCD.As you can see from the flow chart, the LCD is initialized in the following sequence...1. Send command 0x30 - Using 8-bit interface2. Delay 20ms3. Send command 0x30 - 8-bit interface4. Delay 20ms5. Send command 0x30 - 8-bit interface6. Delay 20ms7. Send Function set - see Table 4 for more information8. Display Clear command9. Set entry mode command - explained below

The first 3 commands are usually not required but are recomended when you are using 4-bit interface. So you can program the LCD starting from step 7 when working with 8-bit interface. LCD Entry mode:you can see that the two bits decide the entry mode for LCD, these bits are:a) I/D - Increment/Decrement bitb) S - Display shift.With these two bits we get four combinations of entry mode which are 0x04,0x05,0x06,0x07 (see table 3 inLCD Commandsection). So we get differentresultswith these different entry modes. Normally entry mode 0x06 is used which is No shift and auto incremement. I recommend you to try all the possible entry modes and see the results, I am sure you will be surprised.