You are on page 1of 8

SUBJECT:

 

TITLE:

 

Microprocessor & Microcontroller Architecture & Interfacing (2150907)

Interfacing of LCD with 8051

EXPERIMENT NO.

DATE :

DOC. CODE: DIET/EC/SEM5

REV. NO.: 1.00/JUNE-2015

THEORY:

  • LCD is finding widespread use replacing LEDs, because of

    • The declining prices of LCD

    • The ability to display numbers, characters, and graphics

    • Incorporation of a refreshing controller into the LCD, thereby relieving the CPU of the task of refreshing the LCD

    • Ease of programming for characters and graphics

  • The LCD requires 3 control lines (RS, R/W & EN) & 8 (or 4) data lines.
    The number on data lines depends on the mode of operation. If operated in 8-bit mode, there are 8 data lines + 3 control lines i.e. total 11 lines are required. And if operated in 4-bit mode, there are 4 data lines + 3 control lines i.e. 7 lines are required.

  • How do we decide which mode to use? It’s simple if you have sufficient data lines you can go for 8 bit mode & if there is a time constrain i.e. display should be faster then we have to use 8-bit mode because basically 4-bit mode takes twice as more time as compared to 8-bit mode.

  • PIN DESCRIPTION:

    Pin

    Symbol

    I/O

    Descriptions

    1.

    V

    SS

    --

    Ground

    2.

    V

    CC

    --

    +5V power supply

    3.

    V

    EE

    --

    Power supply to control contrast

    4.

    RS

    I

    RS=0 to select command register, RS=1 to select data register

    5.

    R/W

    I

    R/W=0 for write, R/W=1 for read

    6.

    E

    I/O

    Enable

    7.

    DB0

    I/O

    The 8-bit data bus

    8.

    DB0

    I/O

    The 8-bit data bus

    9.

    DB0

    I/O

    The 8-bit data bus

     
    • 10. DB0

    I/O

    The 8-bit data bus

     
    • 11. DB0

    I/O

    The 8-bit data bus

     
    • 12. DB0

    I/O

    The 8-bit data bus

     
    • 13. DB0

    I/O

    The 8-bit data bus

     
    • 14. DB0

    I/O

    The 8-bit data bus

    • 15. A

     

    --

    GND for the backlight

    • 16. K

     

    --

    Vcc for backlight

    SUBJECT:

     

    TITLE:

     

    Microprocessor & Microcontroller Architecture & Interfacing (2150907)

    Interfacing of LCD with 8051

    EXPERIMENT NO.

    DATE :

    DOC. CODE: DIET/EC/SEM5

    REV. NO.: 1.00/JUNE-2015

    SUBJECT: TITLE: Microprocessor & Microcontroller Architecture & Interfacing (2150907) Interfacing of LCD with 8051 EXPERIMENT NO.
    • When RS is low (0), the data is to be treated as a command. When RS is high (1), the data being sent is considered as text data which should be displayed on the screen.

    • When R/W is low (0), the information on the data bus is being written to the LCD. When RW is high (1), the program is effectively reading from the LCD. Most of the times there is no need to read from the LCD so this line can directly be connected to GND thus saving one controller line.

    • The ENABLE pin is used to latch the data present on the data pins. A HIGH - LOW signal is required to latch the data. The LCD interprets and executes our command at the instant the EN line is brought low. If you never bring EN low, your instruction will never be executed.

    COMMAND LIST:

    Code (Hex)

    Command to LCD Instruction Register

    1

    Clear display screen

    2

    Return home

    4

    Decrement cursor (shift cursor to left)

    6

    Increment cursor (shift cursor to right)

    5

    Shift display right

    7

    Shift display left

    8

    Display off, cursor off

    A

    Display off, cursor on

    C

    Display on, cursor off

    E

    Display on, cursor blinking OFF

    F

    Display on, cursor blinking ON

    10

    Shift cursor position to left

    14

    Shift cursor position to right

    18

    Shift the entire display to the left

    1C

    Shift the entire display to the right

    80

    Force cursor to beginning to 1st line

    SUBJECT:

       

    TITLE:

     

    Microprocessor & Microcontroller Architecture & Interfacing (2150907)

    Interfacing of LCD with 8051

     

    EXPERIMENT NO.

    DATE :

    DOC. CODE: DIET/EC/SEM5

    REV. NO.: 1.00/JUNE-2015

     
     

    C0

    Force cursor to beginning to 2nd line

     

    38

    2 lines and 5x7 matrix

     

    EXERCISE:

    1. Write a Program to send string “GTU IS BEST” to LCD in „C‟ Language. Use LCD in 8-bit mode.

    INTERFACE DIAGRAM:

    As in figure following are connections of LCD with 8051

    DB0 to DB7 is connected with port P0

    RS is connected with P2.0

    RW is connected with P2.1

    EN is connected with P2.2

    SUBJECT: TITLE: Microprocessor & Microcontroller Architecture & Interfacing (2150907) Interfacing of LCD with 8051 EXPERIMENT NO.

    #include <reg52.h> sbit rs= P2^0; sbit rw=P2^1; sbit en=P2^2; void lcdcmd(unsigned char); void lcddata(unsigned char); void msdelay(unsigned char);

    SUBJECT:

     

    TITLE:

     

    Microprocessor & Microcontroller Architecture & Interfacing (2150907)

    Interfacing of LCD with 8051

    EXPERIMENT NO.

    DATE :

    DOC. CODE: DIET/EC/SEM5

    REV. NO.: 1.00/JUNE-2015

    void main()

    {

    unsigned char data[]=”GTU IS BEST”;

    unsigned char k;

    lcdcmd(0x38);

    // 2 line 5x7 display

    msdelay(250);

    lcdcmd(0x0E);

    // LCD ON, Cursor not Blinking

    msdelay(250);

    lcdcmd(0x01);

    // Clear LCD

    msdelay(250);

    lcdcmd(0x06);

    // Shift cursor Right

    msdelay(250);

    lcdcmd(0x86);

    // Starting address

    msdelay(250);

    for(k=0;k<11;k++)

    {

    lcddata(data[k]);

    msdelay(250);

    }

    while(1);

    }

    void lcdcmd(unsigned char value) {

    P0=value;

    rs=0;

    // Command register

    rw=0;

    en=1;

    msdelay(1)

    en=0;

    // EN is H to L pulse

    return;

    }

    void lcddata(unsigned char value) {

    P0=value;

    rs=1;

    // Data Register

    rw=0;

    en=1;

    msdelay(1)

    en=0;

    // EN is H to L pulse

    return;

    }

    SUBJECT:

     

    TITLE:

     

    Microprocessor & Microcontroller Architecture & Interfacing (2150907)

    Interfacing of LCD with 8051

    EXPERIMENT NO.

    DATE :

    DOC. CODE: DIET/EC/SEM5

    REV. NO.: 1.00/JUNE-2015

    void msdelay(unsigned char itime) { unsigned char i; unsigned int j;

    for(i=0;i<itime;i++)

    for(j=0;j<1275;j++);

    }

    Output on Simulator:

    SUBJECT: TITLE: Microprocessor & Microcontroller Architecture & Interfacing (2150907) Interfacing of LCD with 8051 EXPERIMENT NO.

    2. Write a Program to send string “GTU IS BEST” to LCD in „C‟ Language. Use LCD in 4-bit mode.

    INTERFACE DIAGRAM:

    As in figure following are connections of LCD with 8051

    DB4 to DB7 is connected with port P0.4 to P0.7

    RS is connected with P0.0

    RW is connected with P0.1

    EN is connected with P0.2

    SUBJECT: TITLE: Microprocessor & Microcontroller Architecture & Interfacing (2150907) Interfacing of LCD with 8051 EXPERIMENT NO.

    SUBJECT:

     

    TITLE:

     

    Microprocessor & Microcontroller Architecture & Interfacing (2150907)

    Interfacing of LCD with 8051

    EXPERIMENT NO.

    DATE :

    DOC. CODE: DIET/EC/SEM5

    REV. NO.: 1.00/JUNE-2015

    #include <reg52.h> sbit rs= P0^0; sbit rw=P0^1; sbit en=P0^2;

    void lcd_cmd_8bit(unsigned char); void lcd_cmd_4bit(unsigned char); void lcd_data_4bit(unsigned char); void msdelay(unsigned char);

    void main()

    {

     

    unsigned char str[]="GTU IS BEST"; unsigned char k;

    msdelay(550);

    lcd_cmd_8bit(0x20); //default on reset is 8bit, so first write in 8 bit then repeat in 4bit

    msdelay(250);

    lcd_cmd_4bit(0x20);

    // 0x20 for 4-bit

    msdelay(250);

    lcd_cmd_4bit(0x28);

    // 2 line 5x7 display

    msdelay(250);

    lcd_cmd_4bit(0x0E);

    // LCD ON, Cursor not Blinking

    msdelay(250);

    lcd_cmd_4bit(0x01);

    // Clear LCD

    msdelay(250);

    lcd_cmd_4bit(0x06);

    // Shift cursor Right

    msdelay(250);

    lcd_cmd_4bit(0x83);

    // Starting address

    msdelay(250);

    for(k=0;k<11;k++)

    {

    lcd_data_4bit(str[k]);

    msdelay(250);

    }

    while(1);

    //wait for infinite time

    }

    void lcd_cmd_8bit(unsigned char value)

     

    {

    unsigned char temp;

    rs=0;

    // Command register

    rw=0;

    temp = value & 0xf0;//data bit are only higer and rs,rw and en are on lower bits

    P0 = P0 & 0x0f;

    //make higher bits of P0 zero maintain lower bits

    SUBJECT:

     

    TITLE:

     

    Microprocessor & Microcontroller Architecture & Interfacing (2150907)

    Interfacing of LCD with 8051

    EXPERIMENT NO.

    DATE :

    DOC. CODE: DIET/EC/SEM5

    REV. NO.: 1.00/JUNE-2015

    P0 = P0 | temp;

    //change only higer bits maintian lower bits

    en=1;

    msdelay(1);

    en=0;

    // EN is H to L pulse

    return;

    }

    void lcd_cmd_4bit(unsigned char value)

    {

    unsigned char temp;

    rs=0;

    rw=0;

    temp=value; temp=temp & 0xf0;

    // Mask Lower 4 Bits

    //make higher bits of P0 zero maintain lower bits

    //change only higer bits maintian lower bits

    P0 = P0 & 0x0f;

    P0 = P0 | temp;

    en=1;

    msdelay(1);

    en=0;

    temp=value<<4;

    //Left Shift Byte Four Times

    //make higher bits of P0 zero maintain lower bits

    //change only higer bits maintian lower bits

    temp=temp & 0xf0; P0 = P0 & 0x0f;

    // Mask Higher 4 Bits

    P0 = P0 | temp;

    en=1;

    msdelay(1);

    en=0;

    }

    void lcd_data_4bit(unsigned char value)

    {

    unsigned char temp;

    rs=1;

    rw=0;

    temp=value; temp=temp & 0xf0;

    // Mask Lower 4 Bits

    //make higher bits of P0 zero maintain lower bits

    //change only higer bits maintian lower bits

    P0 = P0 & 0x0f;

    P0 = P0 | temp;

    en=1;

    msdelay(1);

    en=0;

    temp=value<<4;

    //Left Shift Byte Four Times

    //make higher bits of P0 zero maintain lower bits

    //change only higer bits maintian lower bits

    temp=temp & 0xf0; P0 = P0 & 0x0f;

    // Mask Higher 4 Bits

    P0 = P0 | temp;

    en=1;

    msdelay(1);

    en=0;

    }

    SUBJECT:

     

    TITLE:

     

    Microprocessor & Microcontroller Architecture & Interfacing (2150907)

    Interfacing of LCD with 8051

    EXPERIMENT NO.

    DATE :

    DOC. CODE: DIET/EC/SEM5

    REV. NO.: 1.00/JUNE-2015

    void msdelay(unsigned char itime) {unsigned char i; unsigned int j;

    for(i=0;i<itime;i++)

    for(j=0;j<125;j++);

    //gives approx. delay of 1 msec

    }

    GRADE

    SIGNATURE