 ____________________________________________________________________________________________________

Introduction

I think there is no more need to introduce how to interface LCD with microcontroller because we earlier learnt it. So in this module we learn how to interface LCD with micrcontroller in 4-bit mode rather than 8-bit conventional mode.

Benefit of LCD interfacing in  4-bit

There are limited numbers of GPIO (general purpose input outputs) pins in micrcontrollers. When we design the large embedded system with single micrcontroller, there is need of efficient use of GPIOs. And as a good programmer, it is nice practice to use GPIO pins efficiently. So interfacing LCD with microcontroller by using 4-bit mode, we save 4 GPIO pins.

Concept of 4-bit mode

Till now whatever we discussed in the previous part of ths LCD module, we were dealing with 8-bit mode. Now we are going to learn how to use LCD in 4-bit mode.

In 4-bit mode, the data is sent in nibbles(1 nibble= 4 bit)  form, first we send the higher nibble and then the lower nibble with same RS, RW and EN pin fuctioning as we were doing in 8-bit mode. 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.

Connection description:

Connections of LCD with microcontroller are shown in circuit diagram of next tab. In 4-bit mode, the Data lines must be connected with D4, D5, D6 and D7 pins of LCD module and RS, RW & EN pin functioning same as it was in 8-bit mode.

Configuring LCD to 4-bit mode:

The LCD can be configured in 4-bit mode by sending appropriate command which is called “Function set” to it. The Function set is hexadecimal code for LCD’s control unit, which selects working modes of LCD. The “Function Set” is mentioned below: DL – Data Length, DL = 1 for 8-bit mode, and  DL = 0 for 4-bit mode

N  –   No. of Lines N = 1 for 2 Lines selection , and N = 0 for  1Lines selection

F  –   Fonts F = 1 for 5×10 dots, and F = 0 for 5×7 dots

According to Function Set, the value of 4–bit mode will be 0010 0000(0x20) because DL=0. The value of “Function Set” for the LCD configuration 2 line (N=1), 5X7 dots (F=0) and 4-bit (DL=0) mode will be 0010 1000(0x28).

When the power supply is given to LCD, it remains in 8-bit mode(default). Now, if 0x20 is sent, lower nibble will not be received by LCD because four data lines (D4-D7) are connected, So 0x02 is sent instead of 0x20.

Steps of Programming

Step1: Initializing LCD in 4-bit mode.

Step2: Nibble sending.

For example, If lower 4 pins of any 8-bit port are connected to LCD’s data line. So, the lower nibble of a byte can be sent to LCD data lines by masking higher nibble. To send higher nibble, data byte is shifted right for four places. higher nibble replaces lower nibble by this shifting. Data is sent after masking the byte.

Example:    if you want to send 0x28, then

Step 3: Exactly the same way we send the data to LCD and function of RS, RW and EN is same as we were doing.

### 1. Circuit diagram of 4 bit mode LCD interfacing with AVR (ATmega16) ### 1. Program of  4 bit mode LCD interfacing with AVR (ATmega16)

PROTEUS File for SIMULATION(Password Of RAR file is :-firmcodes.com) coming soon………….