MCU Examples.com
PIC Microcontroller Project Examples, free source codes and resources collection.


 

Using charactor LCD displays with PIC microcontrollers

Introduction

When it comes to interfacing display modules to a microcontroller, there are mainly two types of displays. Those are Seven Segment Displays and Liquid Crystal Displays (LCD). Even though LCD is more sophisticated than seven segment display, it is easier to use and program the LCD. In LCD, characters are represented by aligning small square shaped dots in a pattern. Unlike the seven segment display, LCD is smart enough to understand and remember the dot patterns of each character which can be represented by a LCD. There for, when the LCD is given a command to show some character (As an example, character “A”), it will show that character (“A”) without having the user to configure the dot patterns (dot pattern for “A”), where as in seven segment display, user must define the bar pattern of every single character which can be shown in seven segment display. Below are some advantages of using a LCD than using a seven segment display.

• It is less complicated when assembling the circuit

• It has less programming to be done

• More characters can be represented

• More functions are available such as, curser blink, writing from right to left and many more



Interfacing


LCD has two pin configuration types called 8 pin configuration (connects 8 data bus lines with the microcontroller) and 4 pin configuration (connects 4 data bus lines with the microcontroller). From these two configurations, most commonly used one is 4 pin configuration (which the programming is more complex than 8 pin configuration). Reason for that is, normally a LCD is not the only thing connected to the microcontroller. With the LCD, a matrix keypad, motors, serial port, sensors, switches and much more could be connected to the microcontroller simultaneously. But the microcontroller has limited number of pins available (PIC16F887 has only 40 pins) to connect all of these modules.  There for, it is difficult on even not possible some times to spare 11 pines (8 data bus lines and 3 control lines) just for the LCD. But, it could be manageable to spare 7 pines (4 data bus lines and 3 control lines) for the LCD if it can be fully operated only with 4 data bus lines. Even though 4 pin configuration is the most common configuration, using 8 pin configuration is less complex (the programming) when the microcontroller can spare 11 pines for the use of it.

As mentioned above, the programming of the LCD strongly depends on the selected pin configuration. Whichever the configuration that has been selected by the user, it has to be informed to the LCD display at the beginning before starting to use it. That informing and activation and deactivation of extra features (Which be seen below under the topic “Extra Features”) of the LCD is being done by sending selected commands (Which are described below under the topic “Assembly Language Instructions [Fully Commented] and Instruction Justifications”) to the LCD by the microcontroller at the start of program.

When it comes to the control lines of the LCD, there are 3 lines, which are called “R/W”, “RS” and “E”.  State of these control lines is the most impotent thing of all since they operate the LCD. Impotence of the state of R/W and RS can be understood by analyzing below table.


Control Line

Set (1)

Not Set (0)

R/W

Read from the LCD module

Write to the LCD module

RS

Sending Data to the LCD module

Sending Commands to the LCD module










By changing the state of R/W pin, it is possible to change the data flowing direction.  If it has been set (1), then the microcontroller can read from the LCD. So, any characters which are being displayed in the display can be read by the microcontroller, which makes the data flow direction from the LCD to the microcontroller. Where, if R/W is not set (0), LCD displays whatever the characters (which are possible to display in the LCD) are sent by the microcontroller, which makes the data flowing direction from microcontroller to the LCD.  Normally most of the times, R/W is always connected to the ground, so it’s always in not set (0) state, since normally always LCD is operated with the data flow direction of from microcontroller to the LCD. But if it’s necessary, that direction could be changed by simply making R/W set (1).

RS is also a very impotent control line. It informs the LCD that the data coming from the data bus lines are in fact commands to the LCD, which can change the setting of the display or character data, which should be displayed. If RS has been set (1), then the coming data is character data which should be displayed. Where, if RS is not set (0), the coming data is display settings changing commands which the display must adhere.  When the required RS state is set, LCD will understand the receiving binary strip and operate accordingly. If it’s a command binary strip for the LCD, that has to be sent to the LCD by first Setting (1) the RS and loading the command binary strip to the data bus connected registry and by using Control line “E” (which is explained in the below paragraph) it can be sent. And to send character data to the LCD, same operation has to be repeated with only changing the state of RS line to Not Set (0).  LCD will decode the binary strip and display the received character.

Control line “E” is not described in the above table, since it has a different functionality than R/W and RS. “E” line is the thing that opens the communication window for the microcontroller and the LCD.  “E” acts exactly like a window or a door between the microcontroller and the LCD.  Data (or commands) can only transfer between the two devices, only between the small period, when “E” is open (Set [1]) and close (Not Set [0]).

Main difficulty faced by the programmer when using the LCD with 4 pin configuration is to send the 8 bit (1 byte) data through 4 bits.  This is obtained by using a smart programming technique (which can be seen by analyzing the program).  But this technique can only be used since the LCD is smart enough to connect the two parts of the sequentially received data from the microcontroller and execute them. But according to the LCD protocol when sending an 8 bit binary strip as two parts, most significant 4 bits of the strip has to be sent first and the other 4 bits has to be sent secondly.


Summery



Character – Liquid Crystal Displays (LCDs) are the simplest LCD module available in the market. Unlike the well known seven segment display, LCD module has its own inbuilt memory and the display characters are stored in it. In order to display a character on the display, we have to instruct the module, where it should be displayed and what character to be displayed. Before simply feeding data or instructions into the LCD module, it should be initialized to suit with our requirement. There are two techniques of feeding data into the LCD module.

  • Eight-bit mode

In this mode, all the 8 data bits will be used to communicate between the PIC and the LCD module.

  • Four-bit mode

In this mode, only 4 data bits will be used to communicate between the PIC and the LCD module. This mode is more advantageous because the number of pins which will be occupied from the PIC is less and therefore this mode will be considered.

PIN CONFIGURATION

To communicate with the LCD module, there are 8 data bits and 3 instruction bits. If the 8 bit mode is used, all the 8 data bits should be connected to a PORT in the PIC whereas in 4 bit mode, only 4 data bits need to be connected.
The pin configuration of the LCD module is as follows;

 

Pin number

Symbol

 Level  

I/O to the PIC

Function

1

Vss

-

-

Power supply (GND)

2

Vcc

-

-

Power supply (+5V)

3

Vee

-

-

Contrast adjust

4

RS

0/1

I

0 = Instruction input
1 = Data input

5

R/W

0/1

I

0 = Write to LCD module
1 = Read from LCD module

6

E

1, 1->0

I

Enable signal

7

DB0

0/1

I/O

Data bus line 0 (LSB)

8

DB1

0/1

I/O

Data bus line 1

9

DB2

0/1

I/O

Data bus line 2

10

DB3

0/1

I/O

Data bus line 3

11

DB4

0/1

I/O

Data bus line 4

12

DB5

0/1

I/O

Data bus line 5

13

DB6

0/1

I/O

Data bus line 6

14

DB7

0/1

I/O

Data bus line 7 (MSB)


    • Pin 1 and 2 – Vss and Vcc

These pins supply power to the LCD module. Vcc should be connected to +5V supply whereas Vss to the ground line.

    • Pin 3 – Vee

 

The contrast of the display will vary with the voltage which appears at Vee pin and should be connected as shown above.

    • Pin 4 – RS

From RS pin, we can inform the module whether next input is going to be an instruction input (eg: Selecting the position of the cursor) or a data input (eg: Writing a character on the display).

    • Pin 5 – RW

RW pin is used to inform the module whether we are going to read data/instructions from the module or to write data/ instructions into the module. In this guide, we are only concerning about writing data into the module. Therefore, RW pin always lies on zero position. Therefore, it could be grounded straight a way through hardware and not necessary to connect to the PIC and make it zero by the software.

    • Pin 6 – E

A pulse will be sent to the pin E to inform the module to acknowledge instruction/data.

    • Pin 7 to 14 – data bits.

When using the 4-bit mode to communicate with the LCD module, only four bits of the LCD module will be connected to the PIC. It is necessary to connect either higher or lower 4 bits of the LCD module to either higher or lower 4 bits of a port of the PIC.

 

Custom Search