GOVERNMENT ENGINEERING COLLEGE, BHAVNAGAR
ELECTRONICS AND COMMUNICATION
SEMESTER : 5
GOVERNMENT ENGINEERING COLLEGE, BHAVNAGAR
MICROCONTROLLER & INTERFACING
GUIDED BY: D. N. PATEL
PRESENTED BY: RAVIBHAN BHARGAV J. - 140210111095
LCD INTERFACING
Introduction
This presentation includes what LCD is and how to
interface LCD with AVR microcontroller Atmega32
using 8-bit mode.
What is the basic difference between 8-bit mode and 4bit mode?
How to write code for LCD interfacing in C language
and what are the basic commands used for LCD
programming.
It also includes how to program LCD and sends
command/ data to LCD.
Hardware requirements:
Atmega32
16x2
ic
lcd display
Breadboard
8Mhz
crystal oscillator
Power
supply
Software requirements:
AVR
studio 4
WHAT IS LCD?
LCD stands for Liquid Crystal Display, is an electronic
device which is used for data display.
LCDs are preferable over seven segments and LEDs
as they can easily represent data in form of alphabets,
characters, numbers or animations.
LCDs are very easy to program and make your work
quite attractive and simple.
Numerous types of LCDs are available in market such
as 16X2, 16X4, 20X2, 20X4, graphical LCDs (128X64)
etc.
The LCD which we are using is 16X2 alphanumeric
LCD, it display 32 characters in two rows means in one
row we have 16 characters.
PIN DESCRIPTION OF LCD
16X2 LCD can interface with AVR microcontroller by
using two modes, 4-bit mode or 8-bit mode.
Here we will use 8-bit mode for interfacing.
In 8-bit mode we send command to LCD by using eight
data lines (D0-D7) while in 4-bit mode we use four data
lines (D5-D7) for sending command and data.
These data lines can be connected to any port of
Atmega32.
PIN NO.
PIN NAME
DESCRIPTION
Supply pin (+5V
VCC
VDD
Ground pin
VEE
Contrast pin
DC)
Register
selection pin
(either data or
4
RS
command)RS=0:
PIN NO.
PIN NAME
DESCRIPTION
Selects Read or
Write
RW
operationRW=0: for
write
RW=1: for read
Enable pin
D0
Data pin 0
D1
Data pin 1
D2
Data pin 2
10
D3
Data pin 3
HOW TO PROGRAM LCD?
Basically there are two registers, command and data.
When we are giving command to LCD, we select
command register and when we are sending data to
LCD for display, we select data register.
Command is an instruction given to LCD in order to
perform required function according to the given
command.
In order to display textual information, data is send to
LCD.
SENDING COMMANDS ON LCD
For sending commands on LCD we have to write
command on data pins. For this, selects:
RS = 0 >> selects command register
RW = 0 >> selects write operation
E>> make enable pin from high to low
SENDING DATA ON LCD
For sending data on LCD we have to write data on
data pins. For this, selects:
RS = 1 >> selects data register
RW = 0 >> selects write operation
E >> make enable pin from high to low
CODE FOR INTERFACING LCD
#include<avr/io.h>
#include<avr/delay.h>
command_write (unsigned char);
data_write (unsigned char);
ready();
main();
delay();
{
unsigned char command[]={0x38,0x01,0x0e,0x06,0x80};
unsigned char data[]={'V','B','I','T'};
unsigned char i;
DDRA=0xFF;
DDRB=0x07;
// configure port A as output port
// configure port B as output port
for(i=0;i<=4;i++)
// for loop execution 4 times
{
command_write(command[i]); //command write from unsigned
char command
_delay_ms(2);
// 2ms delay
}
for(i=0;i<=7;i++)
{
data_write(data[i]);
}
}
//for loop execution 7 times
// data write from unsigned char
data
//subroutine
command_write (unsigned char m)
{
_delay_ms(5);
PORTA=m;
m
//5ms delay
// port A is equal to unsigned char
PORTB=PORTB & 0xFE; //logical END between port B and
0xFE
PORTB=PORTB & 0xFD;//logical END between port B and 0xFE
PORTB=PORTB |0x04; //logical OR between port B and 0x04
_delay_ms(2);
//2ms delay
PORTB=PORTB & 0xFB; //logical AND between port B and
0xFD
}
data_write(unsigned char n)
{
_delay_ms(5);
PORTA=n;
//5ms delay
// port A is equal to unsigned char
n
PORTB=PORTB | 0x01;
//logical OR between port B and
0x01
PORTB=PORTB & 0xFD;
//logical AND between port B and
0xFD
PORTB=PORTB | 0x04;
//logical OR between port B and
0x04
_delay_ms(2);
//2ms delay
PORTB=PORTB & 0xFB; //logical AND between port B and
0xFD
}
Void ready()
{
DDRB=DDRA & 0xFF;
//logical END between DDRA and
0xFF
PORTB=PORTB & 0xFE
//logical END between port B and
0xFE
PORTB=PORTB | 0x02;
//logical OR between port B and
0x02
PORTB=PORTB & 0xFB;
//logical END between DDRA and
0xFB
_delay_ms(2);
//2ms delay
PORTB=PORTB | 0x04;
//logical OR between port B and 0x04
while( PORTB&0x08);
// while loop execution and logical
AND
between port B and 0x08
DDRA=DDRA|0x01;
//logical END between DDRA and
0x01
BASIC COMMANDS USED IN
LCD
DISPLAY DESCRIPTION
COMMANDS
0x01
Clear screen
0x02
return home
0x04
Cursor decrement
0x05
Display shifts to right
0x07
Display shifts to left
0x08
Cursor and display OFF
0x10
Cursor position Shifts to
COMMANDS
0x80
0x0C
0XC0
DESCRIPTION
Move cursor to the beginning
of first line
Display ON, cursor OFF
Move cursor to the beginning
of second line
0x0A
Display OFF, cursor ON
0x0E
Display ON, cursor blinking
0x30
0x20
For display in one line in 8-bit
mode
For display in one line in 4-bit
THANK YOU