Sei sulla pagina 1di 21

.

A Presentation On

“16x2 LCD Interfacing with AVR atmega32


microcontroller”

Under subject of Microcontroller & Interfacing ,B.E. : Sem – 5

(Electronics and Communication Branch)


Submitted by:
Group: 5

Sr. No. Name Of Enrollment


Student No.
1 Bhagtani 130490111001
Namrata

2 Pathan Farhin 130490111022

3 Savaliya Juhi 130490111027

4 Shroff Megha 130490111030

Guided By : Prof. Vipul Mistry


Prof. Krunal Yadav
Head of Department: Prof. Vinesh Kapadia
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 4-bit 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 ic
 16x2 lcd display
 Breadboard
 8Mhz crystal oscillator
 Power supply

Software requirements:
 AVR studio 4
 Proteus 7
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
1 VCC
DC)
2 VDD Ground pin
3 VEE Contrast pin
Register
selection pin
(either data or
command)RS=0
4 RS
: Command
Register ,
RS=1: Data
Register
PIN NO. PIN NAME DESCRIPTION
Selects Read or
Write
5 RW operationRW=0:
for write
RW=1: for read
6 E Enable pin
7 D0 Data pin 0
8 D1 Data pin 1
9 D2 Data pin 2
10 D3 Data pin 3
11 D4 Data pin 4
12 D5 Data pin 5
13 D6 Data pin 6
14 D7 Data pin 7
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; // configure port A as output port
DDRB=0x07; // 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++) //for loop execution 7 times


{
data_write(data[i]); // data write from unsigned char
data
}

}
//subroutine
command_write (unsigned char m)
{
_delay_ms(5); //5ms delay
PORTA=m; // port A is equal to unsigned char m
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); //5ms delay
PORTA=n; // 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
}
 SIMULATION ON PROTEUS
Compile the above code and
dump the HEX file in AVR
microcontroller . Make
necessary settings and check
the display on LCD.
SCHEMATIC
We design our circuit on proteus. Circuit
diagram is given below:
BASIC COMMANDS USED IN
LCD DISPLAY
COMMANDS DESCRIPTION
0x01 Clear screen
0x02 return home
0x04 Cursor decrement
0x05 Display shifts to right
0x07 Display shifts to left
0x08 Cursor and display OFF
Cursor position Shifts to
0x10
left
Cursor position shifts to
0x14
right
COMMANDS DESCRIPTION
Move cursor to the beginning
0x80
of first line
0x0C Display ON, cursor OFF
Move cursor to the beginning
0XC0
of second line
0x0A Display OFF, cursor ON
0x0E Display ON, cursor blinking
For display in one line in 8-bit
0x30
mode
For display in one line in 4-bit
0x20
mode
Display data on cursor
0x0F
blinking
Shift complete data to left
0x18
side
Thank you

Potrebbero piacerti anche