We can program 16*2 alphanumeric LCD in two modes 8 bit and 4 bit. In the previous article, I have already discussed the LCD and its pin configuration. See this link to know the LCD and its 8-bit mode programming.

In this article, I will discuss the steps to display the message on 16*2 alphanumeric LCD using the 4 bits mode.

We already know that microcontroller has fix number of GPIO pins, using the LCD 4-bit mode we can save the extra required pins of the microcontroller.

Note: In LCD 4-bit mode data write only on the upper nibble of the data bus, means that only D4, D5, D6 and D7 data bus are useful.

the connection of LCD in 4-bit mode

In 4-bit mode, the only upper nibble of the data bus is used for the reading and writing. So D4, D5, D6, and D7 will only attach with GPIO of the microcontroller for reading and writing. In below Image LCD data pins attached with PORT 2.
Other connection of LCD 4-bit mode is same like in 8-bit mode.

lcd4bit

Steps to display message on LCD using the 4 bits mode

  • Initialize the LCD in 4-bit mode and select the command or data resistor as per your requirement.
  • Mask the upper nibble and send to the upper nibble of LCD data bus.
  • Send low to high signal on Enable pin.
  • Mask the lower nibble and send to the upper nibble of LCD data bus.
  • Send low to high signal on Enable Pin.

Example

Suppose you want to send the 0x02 command on LCD, then you have to take following steps.

Simple Program to display message on LCD using the 4 bit mode