Microprocessor Systems & Interfacing EEE-342: Comsats University
Microprocessor Systems & Interfacing EEE-342: Comsats University
Name
Registration Number
TOOLS:
SOFTWARE TOOLS:
Atmel Studio/ AVR Studio
Proteus ISIS
AVRDUDESS
HARDWARE TOOLS:
PRE-LAB
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.
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.
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
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.