lcd interfacing with 8051 friendly

Upload: jassi7010

Post on 02-Mar-2016

118 views

Category:

Documents


0 download

DESCRIPTION

lcd interfacing with 8051 c coding

TRANSCRIPT

  • 8051 HOW-TO GUIDE

    Interfacing LCD with

    8051

  • Join the Technical Community Today!

    http://www.pantechsolutions.net

    Contents at a Glance

    8051 Friendly Board ......................................................... 3

    LCD (Liquid Crystal Display) .............................................. 3

    Interfacing LCD ................................................................ 4

    Interfacing 4 bit LCD with 8051 ........................................ 5

    Pin Assignment with 8051 ................................................ 5

    Circuit Diagram to Interface 4 bit LCD with 8051 .............. 6

    Source Code .................................................................... 6

    C Program to display a text in 4 bit LCD using 8051 ........... 7

  • Join the Technical Community Today!

    http://www.pantechsolutions.net

    8051 Friendly Board

    The 8051 Friendly board is specifically designed to help

    students to master the required skills in the area of

    embedded systems. The kit is designed in such way that all

    the possible features of the microcontroller will be easily

    used by the students. The kit supports in system

    programming (ISP) which is done through serial port.

    NXPs 8051 (AT89V51RD2), 8051 friendly Kit is

    proposed to smooth the progress of developing and

    debugging of various designs encompassing of speed 8-bit

    Microcontrollers.

    LCD (Liquid Crystal Display)

    Liquid Crystal Display also called as LCD is very helpful

    in providing user interface as well as for debugging purpose.

    A liquid crystal display (LCD) is a flat panel display that uses

    the light modulating properties of liquid crystals (LCs). LCD

    Modules can present textual information to user.

  • Join the Technical Community Today!

    http://www.pantechsolutions.net

    Interfacing LCD

    Fig. 1 shows how to interface the LCD to

    microcontroller. The 2x16 character LCD interface card with

    supports both modes 4-bit and 8-bit interface, and also

    facility to adjust contrast through trim pot. In 4-bit interface

    7 lines needed to create 4-bit interface; 4 data bits (D0

    D3), three control lines, address bit (RS), read/write bit

    (R/W) and control signal (E).

    Fig. 1 Interfacing 4 bit LCD to Microcontroller

  • Join the Technical Community Today!

    http://www.pantechsolutions.net

    2x16 CHAR LCD

    1 3 20 16

    Interfacing 4 bit LCD with 8051

    We now want to display a text in 8051 Friendly Board

    by using 4 bit LCD module.

    The 8051 Friendly board has seven numbers of LCD

    connections are needed to create 4-bit interface; connected

    with 4 data bits (P0.4 P0.7, D4-D7), address bit (RS-P0.0),

    read/write bit (R/W-P0.1) and control signal (E-P0.2) to

    make LCD display.

    Pin Assignment with 8051

    LCD MODULE 8051 LINES 2x16 LCD Selection

    CO

    NTR

    OL

    RS P0.0

    -LCD SELECT RW P0.1

    E P0.2

    DA

    TA L

    INES

    D0-D3 NC

    D4 P0.4

    D5 P0.5

    D6 P0.6

    D7 P0.7

    GN

    D

    VC

    C

    VEE

    RS

    R/W

    E D4

    D5

    D6

    D7

    LED

    +

    LED

    -

    2 3 1

    JP7

  • Join the Technical Community Today!

    http://www.pantechsolutions.net

    Circuit Diagram to Interface 4 bit LCD with 8051

    Source Code

    The Interfacing 4 bit LCD with 8051 program is very

    simple and straight forward, which display a text in 2 X 16

    LCD module using 4 data lines only. Some delay is occurring

    when a single command / data is executed.

  • Join the Technical Community Today!

    http://www.pantechsolutions.net

    C Program to display a text in 4 bit LCD using 8051 ***************************************************************************************

    Title : Program to 4 bit LCD display ***************************************************************************************

    #include //Define 8051 Registers

    #include //Define I/O Functions

    #define DATA P0 //Define DATA to Port2

    sbit RS = P0^0; //Register Select

    sbit RW = P0^1; //LCD Read/Write

    sbit lcd_e = P0^2; //LCD Enable

    code unsigned char msg[] = (" PS.PRIMER-8051 "); //Display

    code unsigned char msg1[] = (" 2x16 LCD DEMO ");

    //----------------------------------

    // LCD Functions

    //----------------------------------

    void lcd_init(void);

    void lcd_cmd(unsigned char);

    void lcd_display(unsigned char);

    void DelayMs(int);

    //----------------------------------

    // LCD command Function

    //----------------------------------

    void lcd_cmd(unsigned char cmnd)

    {

    DATA = 0xf0&cmnd; //Masking lower 4

    Bits

    RS = 0; RW = 0;

    lcd_e = 1;

    DelayMs(35);

    lcd_e = 0;

    DATA = cmnd*16; //Masking lower 4

    RS = 0; RW = 0;

    lcd_e = 1;

  • Join the Technical Community Today!

    http://www.pantechsolutions.net

    DelayMs(35);

    lcd_e = 0;

    }

    //----------------------------------

    // LCD Data Function

    //----------------------------------

    void lcd_display(unsigned char dat)

    {

    DATA = 0xf0&dat; //Masking lower 4

    RS = 1; RW = 0;

    lcd_e = 1;

    DelayMs(35);

    lcd_e = 0;

    DATA = dat*16; //Masking lower 4

    RS = 1; RW = 0;

    lcd_e = 1;

    DelayMs(35);

    lcd_e = 0;

    }

    //----------------------------------

    // LCD Delay Function

    //----------------------------------

    void DelayMs(int k)

    {

    unsigned int a;

    for(a=0;a

  • Join the Technical Community Today!

    http://www.pantechsolutions.net

    lcd_cmd(0x28); //2x16 Character 5x7

    DelayMs(15); //matrix LCD,4-bit format

    lcd_cmd(0x0c);

    DelayMs(15);

    lcd_cmd(0x06); //Shift

    DelayMs(15);

    lcd_cmd(0x01);

    DelayMs(15);

    //-------------------------------------------

    // First Line Message Display

    //-------------------------------------------

    lcd_cmd(0x80);

    DelayMs(35);

    i=0;

    while(msg[i]!='\0')

    {

    lcd_display(msg[i]);

    i++;

    }

    DelayMs(50);

    //-------------------------------------------

    // Second Line Message Display

    //-------------------------------------------

    lcd_cmd(0xc0); //Second

    DelayMs(35);

    i=0;

    while(msg1[i]!='\0')

    {

    lcd_display(msg1[i]);

    i++;

    }

    DelayMs(50);

    }

  • Join the Technical Community Today!

    http://www.pantechsolutions.net

    //----------------------------------

    // LCD Main Program

    //----------------------------------

    void main(void)

    {

    P0 = 0;

    lcd_init(); //LCD Initialization

    DelayMs(1);

    DelayMs(1);

    while(1); //Loop Forever

    }

  • Join the Technical Community Today!

    http://www.pantechsolutions.net

    Pantech solutions creates information packed technical

    documents like this one every month. And our website is a rich

    and trusted resource used by a vibrant online community of

    more than 1, 00,000 members from organization of all shapes

    and sizes.

    Did you enjoy the read?

  • Join the Technical Community Today!

    http://www.pantechsolutions.net

    What do we sell?

    Our products range from Various Microcontroller

    development boards, DSP Boards, FPGA/CPLD boards,

    Communication Kits, Power electronics, Basic electronics,

    Robotics, Sensors, Electronic components and much more . Our

    goal is to make finding the parts and information you need

    easier and affordable so you can create awesome projects and

    training from Basic to Cutting edge technology.