To interface LCD with the microcontroller in default configuration requires 3 control signals and 8 data lines.This is known as 8 bit interfacing mode which requires total 11 I/O lines.
To reduce the number of I/Os required for LCD interfacing we can use 4 bit interfacing mode which requires 3 control signals with 4 data lines. In this mode upper nibble and lower nibble of commands/data set needs to be sent separately. Below block diagram shows LCD interfacing in 4 bit mode. The three control lines are referred to as EN, RS, and RW.
LCD Module Pins
Supply Voltage 5V
RS (Control Line)
RW (Control Line)
EN (Control Line)
PC4 – PC7
D4 – D7 (Data Line)
LCD Light +-
LCD Back Light
The EN line is called “Enable” and it is connected to PC2. This control line is used to tell the LCD that microcontroller has sent data to it or microcontroller is ready to receive data from LCD. This is indicated by a high-to-low transition on this line. To send data to the LCD, program should make sure that this line is low (0) and then set the other two control lines as required and put data on the data bus. When this is done, make EN high (1) and wait for the minimum amount of time as specified by the LCD datasheet, and end by bringing it to low (0) again.
The RS line is the “Register Select” line and it is connected to PC0. When RS is low (0), the data is treated as a command or special instruction by the LCD (such as clear screen, position cursor, etc.). When RS is high (1), the data being sent is treated as text data which should be displayed on the screen.
The RW line is the “Read/Write” control line and it is connected to PC1. When RW is low (0), the information on the data bus is being written to the LCD. When RW is high (1), the program is effectively querying (or reading from) the LCD.
Bi-Directional Data Bus:
The data bus is bidirectional, 4 bit wide and is connected to PC4 to PC7 of the microcontroller.
The MSB(Most Significant Bit) bit (DB7) of data bus is also used as a Busy flag. When the Busy flag is 1, the LCD is in internal operation mode, and the next instruction will not be accepted. When RS = 0 and R/W = 1, the Busy flag is output on DB7. The next instruction must be written after ensuring that the busy flag is 0.
Schematic of Interfacing 16×2 Lcd with AVR
The program provided below is for understanding purpose only. You can download AVR Studio files here
LCD header file functions:
The function in lcd.h file are defined we are calling these functions in main function.See the functions explained below:
lcd_clrscr(); : To clear the LCD and reset the cursor to initial state.
lcd_int : Initializing the LCD Display.
LCD_MOVE_DISP_LEFT : This command is used to sift text one character left.
lcd_gotoxy(column,row) : To move cursor to a row or column.
LCD_Interfacing with AVR ATMEGA
Written by: Sidhu Burre
AVR Studio Version 4
LCD Microcontroller Pins
RS --> PC0
RW --> PC1
EN --> PC2
DB7 --> PC7
DB6 --> PC6
DB5 --> PC5
DB4 --> PC4
Note: For ATMEGA16 we used 12MHz external crystal oscillator
#define F_CPU 12000000UL // defines the clock speed
#include"lcd.h" // include lcd_16.h
#include"lcd.c" // include lcd_16.c
intmain(void)// main function
lcd_init(LCD_DISP_ON);// initialize LCD
while(1)// infinite loop
lcd_puts(" CircuitStudy ");// Print the text on LCD
for(inti=0;i<15;i++)// for loop
lcd_command(LCD_MOVE_DISP_LEFT);// Shift display left