Interfacing LCD With Atmega32 Microcontroller Using Atmel Studio
Interfacing LCD With Atmega32 Microcontroller Using Atmel Studio
Interfacing LCD With Atmega32 Microcontroller Using Atmel Studio
o Hobby Circuits
o 555 Circuits
o Embedded
Tutorials
o PIC
o Raspberry Pi
o Arduino
o 8051
o ATMEL AVR
Forums
Contact Us
My Account
Register
Login
Home
Tutorials, ATMEL AVR
Interfacing LCD with Atmega32 Microcontroller using Atmel Studio
Contents
1 Function in lcd.h
2 8 Bit Mode Interfacing
o 2.1 Circuit Diagram
o 2.2 Atmel Studio C Code
3 4 Bit Mode Interfacing
o 3.1 Circuit Diagram
o 3.2 Atmel Studio C Code
4 How to use the Header File?
5 Optimize Code for More Efficiency
As we all know LCD (Liquid Crystal Display) is an electronic display which is commonly
used nowadays in applications such as calculators, laptops, tablets, mobile phones etc. 162
character LCD module is a very basic module which is commonly used by electronic
hobbyists and is used in many electronic devices and project. It can display 2 lines of 16
character and each character is displayed using 57 or 510 pixel matrix.
Interfacing 162 LCD with Atmega32 Atmel AVR Microcontroller using Atmel Studio is bit
complex as there is no built in libraries. To solve this difficulty we developed a LCD library
which includes the commonly used features. Just include our header file and enjoy. You can
download the header file from the bottom of this article.
162 LCD can be interfaced with a microcontroller in 8 Bit or 4 Bit mode. These differs in
how data and commands are send to LCD. In 8 Bit mode character data (as 8 bit ASCII) and
LCD command are sent through the data lines D0 to D7. That is 8 bit data is send at a time
and data strobe is given through E of the LCD.
But 4 Bit mode uses only 4 data lines D4 to D7. In this 8 bit data is divided into two parts and
are sent sequentially through the data lines. The idea of 4 bit communication is introduced to
save pins of microcontroller. 4 bit communication is bit slower than 8 bit but this speed
difference has no significance as LCDs are slow speed devices. Thus 4 bit mode data transfer
is most commonly used.
Function in lcd.h
Lcd8_Init() & Lcd4_Init() : These functions will initialize the 162 LCD module connected
to the microcontroller pins defined by the following constants.
#define D0 eS_PORTD0
#define D1 eS_PORTD1
#define D2 eS_PORTD2
#define D3 eS_PORTD3
#define D4 eS_PORTD4
#define D5 eS_PORTD5
#define D6 eS_PORTD6
#define D7 eS_PORTD7
#define RS eS_PORTC6
#define EN eS_PORTC7
#define D4 eS_PORTD4
#define D5 eS_PORTD5
#define D6 eS_PORTD6
#define D7 eS_PORTD7
#define RS eS_PORTC6
#define EN eS_PORTC7
These connections must be defined for the proper working of the LCD library. Dont forget
to define these pins as Output.
Lcd8_Clear() & Lcd4_Clear() : Calling these functions will clear the 162 LCD display
screen when interfaced with 8 bit and 4 bit mode respectively.
Lcd8_Set_Cursor() & Lcd4_Set_Cursor() : These function will set the cursor position on
the LCD screen by specifying its row and column. By using these functions we can change
the position of character and string displayed by the following functions.
Lcd8_Shift_Left() & Lcd4_Shift_Left() : This function will shift data in the LCD
display without changing data in the display RAM.
Lcd8_Shift_Right() & Lcd8_Shift_Right() : This function will shift data in the LCD
display without changing data in the display RAM.
#define D0 eS_PORTD0
#define D1 eS_PORTD1
#define D2 eS_PORTD2
#define D3 eS_PORTD3
#define D4 eS_PORTD4
#define D5 eS_PORTD5
#define D6 eS_PORTD6
#define D7 eS_PORTD7
#define RS eS_PORTC6
#define EN eS_PORTC7
#include <avr/io.h>
#include <util/delay.h>
#include "lcd.h" //Can be download from the bottom of this article
int main(void)
{
DDRD = 0xFF;
DDRC = 0xFF;
int i;
Lcd8_Init();
while(1)
{
Lcd8_Set_Cursor(1,1);
Lcd8_Write_String("electroSome LCD Hello World");
for(i=0;i<15;i++)
{
_delay_ms(500);
Lcd8_Shift_Left();
}
for(i=0;i<15;i++)
{
_delay_ms(500);
Lcd8_Shift_Right();
}
Lcd8_Clear();
Lcd8_Write_Char('e');
Lcd8_Write_Char('S');
_delay_ms(2000);
}
}
#include <avr/io.h>
#include <util/delay.h>
#include "lcd.h" //Can be download from the bottom of this article
int main(void)
{
DDRD = 0xFF;
DDRC = 0xFF;
int i;
Lcd4_Init();
while(1)
{
Lcd4_Set_Cursor(1,1);
Lcd4_Write_String("electroSome LCD Hello World");
for(i=0;i<15;i++)
{
_delay_ms(500);
Lcd4_Shift_Left();
}
for(i=0;i<15;i++)
{
_delay_ms(500);
Lcd4_Shift_Right();
}
Lcd4_Clear();
Lcd4_Set_Cursor(2,1);
Lcd4_Write_Char('e');
Lcd4_Write_Char('S');
_delay_ms(2000);
}
}
1. Right Click on your project folder on the solution explorer on the right side.
2. Add >> Existing Item
3. Then Browse lcd.h
4. Click Add
You can download header file, atmel studio files and proteus files here