0% found this document useful (0 votes)
15 views4 pages

EXP8

EXPERIOMNT PDF

Uploaded by

nidevm368
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views4 pages

EXP8

EXPERIOMNT PDF

Uploaded by

nidevm368
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Exp No.

8 Date: D D - M M - Y Y

INTERFACING 16x2 LCD


AIM
To interface 16x2 LCD with ATmega 32.

THEORY

Liquid Crystal Display (LCD) is widely used in various electronics’ applications to show different status
and parameters. LCD16x2 has 2 lines with 16 characters in each line. Each character is made up of 5x8
(column x row) pixel matrix. LCD 16x2 is a 16 pin device which has 8 data pins (D0-D7) and 3 control pins
(RS, RW, EN). The remaining 5 pins are for supply and backlight for the LCD. The control pins help us
configure the LCD in command mode or data mode.

To use LCD, need to initialize the LCD, by sending some commands.


Commonly Used LCD16x2 Commands
Code Execution
Command to LCD
(HEX) Time
0x01 Clear the display screen 1.64ms
Shift the cursor right (e.g. data gets written in an incrementing order, left to
0x06 40 us
right)
0x0C Display on, cursor off 40 us
0x0E Display on, cursor blinking 40 us
0x80 Force the cursor to the beginning of the 1st line 40 us
0xC0 Force the cursor to the beginning of the 2nd line 40 us
0x10 Shift cursor position to the left 40 us
0x14 Shift cursor position to the right 40 us
0x18 Shift entire display to the left 40 us
0x1C Shift entire display to the right 40 us
0x38 2 lines, 5x8 matrix, 8-bit mode 40 us
0x28 2 lines, 5x8 matrix,4-bit mode 40 us
0x30 1 line, 8-bit mode 40us
0x20 1 line, 4-bit mode 40us

C Program
// Code for LCD Interfacing with ATmega32 AVR microcontroller

#define F_CPU 16000000UL /* Define CPU Frequency e.g. here 16MHz */


#include <avr/io.h> /* Include AVR std. library file */
#include <util/delay.h> /* Include inbuilt defined Delay header file */

#define LCD_DATA PORTD //PORT D as data line


#define LCD_RS 6 //of PORT C
#define LCD_EN 7 //of PORT C

//------function declaration---------
void lcd_command(char c);
void lcd_data(char d);
void lcd_puts(const char *s);

//------main function----------------
main()
{
DDRC=0XFF; //PORT C as o/p line
DDRD=0XFF; //PORT D as o/p line
_delay_ms(20);

//-------passing commands to lcd for initialization------


lcd_command(0X38); //2 lines, 5x8 matrix, 8-bit mode
lcd_command(0X80); // cursor to the beginning of the 1st line
lcd_command(0X0C); // Display on, cursor off
lcd_command(0X06); // Shift the cursor right
lcd_command(0X01); // Clear the display screen
_delay_us(100);
lcd_puts("GPC MATTANUR"); // first line of data
lcd_command(0XC0); // cursor to the beginning of the 2nd line
lcd_puts("ELECTRONICS ENGG "); // second line of data
_delay_us(5);
while(1); // endless loop
}
//-----------function lcd command---------
void lcd_command(char c)
{
LCD_DATA=c;
PORTC&=~(1<<LCD_RS);
PORTC|=(1<<LCD_EN);
_delay_us(5);
PORTC&=~(1<<LCD_EN);
_delay_ms(1);
}

//-----------function lcd data---------


void lcd_data(char d)
{
LCD_DATA=d;
PORTC|=(1<<LCD_RS);
PORTC|=(1<<LCD_EN);
_delay_us(5);
PORTC&=~(1<<LCD_EN);
_delay_ms(1);
}
//-----------function lcd puts---------
void lcd_puts(const char *s)
{
while(*s)
{
lcd_data(*s++);
_delay_us(5);
}
}

RESULT

Interfacing program for 16x2 LCD is written in embedded C, compiled, downloaded to target board, and
implemented LCD interfacing.

You might also like