LCD Interfacing with AVR Microcontroller

 


COMSATS UNIVERSITY ISLAMABAD

 

MICROPROCESSOR SYSTEMS AND INTERFACING

                        LAB REPORT 5

SUBMITTED TO:

SIR KHIYAM IFTIKHAR

SUBMITTED BY:

JUNAID AHMAD

Ibrar ahmad

Jarrar malik

REGISTRATION NO:

CIIT/FA19-BEE-089/ISB

Ciit/fa19-bee-083/isb

Ciit/fa19-bee-087/isb

DATE:

25-10-2021

LCD Interfacing with AVR Microcontroller

 

Objectives:

              Overview of controller to controller communication

              To understand LCD interfacing with AVR microcontroller

Software Tools:

              Microchip Studio/ AVR Studio

              Proteus ISIS

              AVRDUDESS

 

 Hardware Tools:

              Microcontroller

              Breadboard

              16 x 2 LCD

              Variable Resistor

 

Ø 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 4.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

 

 

 

 

PRE-LAB TASK:

 

TASK 1:

Find hexa-decimal codes for commands mentioned in LCD initializing heading using Table 4.3.




 

CLEAR DISPLAY

01

RETURN HOME

02

ENTRY MODE

06

 

 

 

 

IN-LAB TASKS:

 

TASK 1:

Consider the basic wiring shown between an ATmega328P chip and an LCD in figure 4.2. Write and execute a C-program on Proteus that is able print your name on the first row of the LCD and your roll-number on the second row of the LCD.



Figure 4.2: Wiring of Atmega328P with LCD

 

CODE:

#define F_CPU 16000000

#include <avr/io.h>

#include <util/delay.h>

#include <string.h>

 

void LCD_init();

void cmdwrite(int command);

void LCD_display(char str[]);

void datawrite(char ch);

 

 

 

int main(void)

{

           

            char str[]="its working yoo";

            DDRD=0xFF;

            DDRB|=(1<<PORTB0)|(1<<PORTB1)|(1<<PORTB2);

           

            LCD_init();

           

            LCD_display(str) ;

           

           

           

           

            /* Replace with your application code */

            while (1)

            {

                       

            }

}

 

 

void LCD_display(char str[]){

           

            int i;

            //char ch;

            for (i=0; i<strlen(str);i++ ) {

                       

                        datawrite(str[i]);

                       

                        _delay_us(5000);

                       

                        if(i==15)                    //i.e first line is filled

                        cmdwrite(0xC0);                //Write address 0x40 which is starting address of next line

                        _delay_us(1000);

            }

}

 

 

 

void datawrite(char ch){

           

            PORTB|=(1<<PORTB2);                //RS=1 for Data

            PORTB&=~(1<<PORTB1);            //RW=0 for writing

 

            PORTD= ch;

            PORTB|=(1<<PORTB0);                //EN=1

 

            _delay_us(1);                                  //High to low pulse  (According to datasheet level 1 time is 450ns

 

            PORTB&=~(1<<PORTB0);            //EN=0

 

}

 

void LCD_init() {

           

           

            _delay_ms(5000); //>15ms

           

            cmdwrite(0x30);

           

            _delay_ms(5);         //4.1 ms

           

            cmdwrite(0x30);

           

            _delay_us(1000);   //>100us

           

            cmdwrite(0x30);

           

            _delay_us(1000);

           

            cmdwrite(0x38);    // interface length 8 bits, 2 lines, 5x7 font

           

            _delay_us(1000);                           //Check Busy bit or wait > 37us at 270kHz

           

            cmdwrite(0x08);    // Display Off

           

            _delay_us(1000);                           //Check Busy bit or wait > 37us at 270kHz

           

            cmdwrite(0x01);    //Clear LCD (and also returns cursor to home)

           

            _delay_ms(50);      // Clear Display command takes longer time to execute

           

            cmdwrite(0x06);    //Cursor move Direction set to right

           

            _delay_us(1000);                           //Check Busy bit or wait > 37us at 270kHz

           

            cmdwrite(0x0E);    // Display on, with Cursor, but no cursor blink

           

            _delay_us(1000);                           //Check Busy bit or wait > 37us at 270kHz

}

 

 

 

void cmdwrite(int command) {

           

            PORTB&=~(1<<PORTB2);            //RS=0 for Command

            PORTB&=~(1<<PORTB1);            //RW=0 for writing

           

            PORTD= command;

            PORTB|=(1<<PORTB0);                //EN=1

           

            _delay_us(1);                                  //High to low pulse  (According to datasheet level 1 time is 450ns

           

            PORTB&=~(1<<PORTB0);            //EN=0

           

}

 

 

Proteous simulation:



Hardware simulation:



CRITICAL ANAYSIS:

In this lab we were introduced to LCD interfacing with atmega328p microcontroller unit. LCD interfacing has many important details that need to be taken care of. There can be 2 modes i.e. command mode and data mode and same pins are used for both purposes but with different register bit configurations. Tx and Rx modes should also be disabled. The LCD have vast application in our daily life it is used to show the temperature. Also used in calculators.

 

 

 

 

 

 

 

 

إرسال تعليق

Post a Comment (0)

أحدث أقدم