0% found this document useful (0 votes)
94 views

Microprocessor Systems & Interfacing EEE-342: Comsats University

The document describes a lab experiment on interfacing an LCD display with an AVR microcontroller. It includes: 1) An overview of LCD components and interfacing with a microcontroller using either 8-bit or 4-bit communication. 2) Instructions on initializing the LCD using specific command codes and sending data by setting the RS pin high or low. 3) A code example to initialize the LCD and send text to display on the LCD by calling functions to send commands and data. 4) The task of completing and simulating the code example to display text on the LCD.

Uploaded by

Bilal Habib
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
94 views

Microprocessor Systems & Interfacing EEE-342: Comsats University

The document describes a lab experiment on interfacing an LCD display with an AVR microcontroller. It includes: 1) An overview of LCD components and interfacing with a microcontroller using either 8-bit or 4-bit communication. 2) Instructions on initializing the LCD using specific command codes and sending data by setting the RS pin high or low. 3) A code example to initialize the LCD and send text to display on the LCD by calling functions to send commands and data. 4) The task of completing and simulating the code example to display text on the LCD.

Uploaded by

Bilal Habib
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

COMSATS UNIVERSITY

MICROPROCESSOR SYSTEMS & INTERFACING


EEE-342

Lab # 04 LCD Interfacing with AVR Microcontroller

Name

Registration Number

Instructor’s Name MA’AM ASMA RAMAY


OBJECTIVES:
 Overview of controller to controller communication.
 To understand LCD interfacing with AVR microcontroller.

TOOLS:

SOFTWARE TOOLS:
 Atmel Studio/ AVR Studio
 Proteus ISIS
 AVRDUDESS

HARDWARE TOOLS:

PRE-LAB

4.1 INTRODUCTION TO LCD

LCD provides an output interface to AVR microcontroller. It comes in various configurations


such as 20 x 2, 16 x 1, 40 x 1, 16 x 2 etc. with 5 x 8 or 5 x 11 dots resolution. Out of these, 16 x 2
is widely used.
LCD has a microcontroller in it which is already coded to display characters on the screen.
Therefor to use an LCD a controller to controller interface is required.
LCD controller is responsible for all the operations with in LCD such as movement of curser,
display clear, character printing and special character generation etc. HD44780U and S6A0069
are common examples of LCD control unit.
LCD controller’s internal memory comprises of Character Generator ROM (CGROM),
Character Generator RAM (CGRAM) and Display Data RAM (DDRAM).
 Character Generator ROM (CGROM) contain predefined character fonts table.
 Character Generator RAM (CGRAM) stores customized character table
 Display Data RAM (DDRAM) stores display data represented in 8-bit character codes.

4.1.1 LCD PIN CONFIGURATION


Figure 4.1 shows the pin configuration of LCD.
4.1.2 LCD COMMUNICATION MODES
The LCD can be used as 8-bit or 4-bit interface with microcontroller.
1. 8-bit communication.
2. 4-bit communication
In 8-bit communication 11 pins of MCU reserved as 8 pins for LCD data pins (D0-D7) and 3
pins for LCD Control Pins i.e. Enable (En is pin 6), Read/Write (RW is pin 5) and Register
Select (RS is pin 4). So each instruction executes in 1 cycle for 1byte instruction.
However, in 4-bit mode only 4 data pins (D0-D3) and 3 control pins are used so MCU reserves
7pins for LCD. Each instruction executes in normally 2 cycle for 1 byte instruction i.e. 1 nibble
per cycle
4.2 LCD INTERFACING
LCD controller has two 8-bit registers:
 Command Register allows the user to send commands such as clear display, cursor at
home etc.
 Data register allows the user to send the data to be displayed on LCD

Since same pins from D0 to D7 are used for both command and data, RS pin is used to identify
between the command and data.
Following steps are used to send command or data to LCD:
1. Initialize the LCD.
2. Send commands from Table 5.3 to LCD.
3. Send data to be displayed on LCD.

4.2.1 INITIALIZING THE LCD


To initialize the LCD for 5x7 matrix and 8-bit communication mode, following commands
should be send to LCD. See Table 5.3 for description of each command.
 Function Set: Select LCD mode to 8-bit interface, 2 line, and character size to 5x7.
 Display On/Off control: Display On, turn on the cursor, No blinking.
 Clear Display
 Entry mode set: Increment Cursor, No display shift

4.2.2 SENDING COMMANDS TO LCD:


To send any command from Table 5.3 to LCD, following steps should be followed.
 Set R/S and R/W pins to zero logic.
 Send the command code to pins D0-D07.
 Send a high to low pulse to Enable pin.

Enable pin is used to synchronize the whole operation of sending data or command to LCD. The
LCD will not read any pins for command or data until we give high to low transition level to
enable pin. After each command, add a delay of 100us to to wait for LCD controller to run the
command. After clear LCD and return home commands, wait for 2ms.

4.2.3 SENDING DATA TO LCD:


To send any data to be displayed LCD, following steps should be followed.
 Set R/S =1 and R/W = 0.
 Send the data to pins D0-D07.
 Send a high to low pulse to Enable pin.
PRE-LAB TASK
Find hexa-decimal codes for above mentioned commands using Table 4.3

CLEAR DISPLAY 01
RETURN HOME 02
ENTRY MODE 06
DISPLAY ON/ OFF CONTROL 0E
FUNCTION SET 38

IN-LAB TASK
Task-1: Complete the following code and simulate it on Proteus.
 Complete the LCD initialize function by using the command codes from Pre-Lab
task.
 Function to send commands to LCD is given, Write the function to send data on
LCD.

CODE TO BE IMPLEMENTED

#include <avr/io.h> 
#define F_CPU 16000000UL 
#include <util/delay.h> 
#define RS PB0 //En pin is connected to PORTB Pin 0
#define RW PB1 //En pin is connected to PORTB Pin 1
#define EN PB2 //En pin is connected to PORTB Pin 2

int LCD_init(void); 
void LCD_Send_Command(unsigned char);
void LCD_Send_Data(unsigned char); 
int LCD_Send_Array(char * ptr);

int main(void)

 { 
LCD_init(); 
  
 
LCD_Send_Array("TRIOGENS"); /* Replace with your application code */ 
 
while (1) {
}
return(0); 
 

int LCD_init() { 

DDRD = 0b11111111;
DDRB = 0b00000111;

UCSR0B&=~(1<<TXEN0); 
UCSR0B&=~(1<<RXEN0);   
    
_delay_ms(100);
 
PORTB |= (1<<EN); 
LCD_Send_Command(0x38); 
_delay_ms(2); 
LCD_Send_Command(0x0E); 
_delay_ms(2); 
LCD_Send_Command(0x01);  
_delay_ms(2); 
LCD_Send_Command(0x06); 
 
return(0); 

 
void LCD_Send_Command(unsigned char comm) 

PORTB &= ~(1<<RS); 
PORTB &= ~(1<<RW); 
PORTD = comm; 
PORTB &= ~(1<<EN); 
_delay_ms(1); 
PORTB |= (1<<EN); 
}
void LCD_Send_Data(unsigned char data) 

PORTB |= (1<<RS);
PORTB &= ~(1<<RW);
PORTD = data;
PORTB &= ~(1<<EN);
_delay_ms(1);
PORTB |= (1<<EN);

int LCD_Send_Array(char * ptr) 

while(*ptr != '\0') 

{
  LCD_Send_Data(*ptr); 
 
ptr++; 

PROTUES SIMULATION

IMPLEMENTATION ON HARDWARE

CRITICAL ANALYSIS / CONCLUSION


The objective of this lab was to learn about the controller to controller communication and to
understand LCD interfacing with AVR microcontroller.  

TASK 1 OUTCOMES: In this task a code was to given to display data on LCD using the
command LCD_Send_Array( ). A delay was called between displaying the data continuously. The Tx
and Rx pins were disconnected while burning the code on microcontroller.

You might also like