+ Post New Thread
Results 1 to 9 of 9
  1. #1
    Junior Member level 3
    Points: 480, Level: 4

    Join Date
    Mar 2011
    Location
    United Kingdom
    Posts
    31
    Helped
    0 / 0
    Points
    480
    Level
    4

    Interfacing LCD to PIC Microcontroller (PIC16F877)

    Hello,

    Ive been reading up on how to interface an LCD to a pic for a few days now but am still quite confused.. I read from this link: LCD Tutorial for interfacing with Microcontrollers: Introduction : 8051 Microcontroller Projects AVR PIC Projects Tutorials Ebooks Libraries codes but he is using 8051, whereas I also read from thsi place: Mark Crosbie's Homepage and he is using a PIC.

    i noticed both sources use different ommands, which one to follow?

    also I dont understand how to write the #define commands writte by the 8051 site..

    im using sourceboost btw.

    I know how to interface it, i mean i know how to connect the pins, its the coding thats getting to me..

    suppos i use the initialization commands from here: Initialization: LCD Tutorial for interfacing with Microcontrollers : 8051 Microcontroller Projects AVR PIC Projects Tutorials Ebooks Libraries codes

    will this work in sourceboost and for a PIC?

    I dont have a LCD plugin to test

    ---------- Post added at 18:48 ---------- Previous post was at 18:46 ----------

    I fogot to mention that Im using C language and know only C language, so no assembly please

    ---------- Post added at 18:49 ---------- Previous post was at 18:48 ----------

    I fogot to mention that Im using C language and know only C language, so no assembly please

  2. #2
    Full Member level 4
    Points: 2,538, Level: 11
    qwertyuiop415263's Avatar
    Join Date
    Mar 2010
    Location
    Pakistan
    Posts
    232
    Helped
    51 / 51
    Points
    2,538
    Level
    11

    Re: Interfacing LCD to PIC Microcontroller (PIC16F877)

    which microcontroller you want to use? be specific
    \frac{\sqrt{\iiint } }{ } \displaystyle



    •   AltAdvertisement

        
       

  3. #3
    Junior Member level 3
    Points: 480, Level: 4

    Join Date
    Mar 2011
    Location
    United Kingdom
    Posts
    31
    Helped
    0 / 0
    Points
    480
    Level
    4

    Re: Interfacing LCD to PIC Microcontroller (PIC16F877)

    Quote Originally Posted by qwertyuiop415263 View Post
    which microcontroller you want to use? be specific
    Hi, the microcontroller is in the post title, i.e. PIC16F877



  4. #4
    Full Member level 5
    Points: 2,176, Level: 10
    cubanflyer's Avatar
    Join Date
    Jul 2010
    Location
    UK
    Posts
    255
    Helped
    76 / 76
    Points
    2,176
    Level
    10

    Re: Interfacing LCD to PIC Microcontroller (PIC16F877)

    Check out this link, it explains the sequence of events for controlling the LCD LCD Commands
    There are 10 kinds of people in the world.
    Those who understand binary and those who don't.



    •   AltAdvertisement

        
       

  5. #5
    Junior Member level 3
    Points: 480, Level: 4

    Join Date
    Mar 2011
    Location
    United Kingdom
    Posts
    31
    Helped
    0 / 0
    Points
    480
    Level
    4

    Re: Interfacing LCD to PIC Microcontroller (PIC16F877)

    This is the initialization code from the site i linked above: 8051 projects
    Code:
    #include .
    #define LCD_data P2
    #define LCD_D7   P2_7
    #define LCD_rs   P1_0
    #define LCD_rw   P1_1
    #define LCD_en   P1_2
    
    void LCD_init()
    {
         LCD_data = 0x38;     //Function set: 2 Line, 8-bit, 5x7 dots
         LCD_rs   = 0;        //Selected command register
         LCD_rw   = 0;        //We are writing in data register
         LCD_en   = 1;        //Enable H->L
         LCD_en   = 0;
         LCD_busy();          //Wait for LCD to process the command
         LCD_data = 0x0F;     //Display on, Curson blinking command
         LCD_rs   = 0;        //Selected command register
         LCD_rw   = 0;        //We are writing in data register
         LCD_en   = 1;        //Enable H->L
         LCD_en   = 0;
         LCD_busy();          //Wait for LCD to process the command
         LCD_data = 0x01;     //Clear LCD
         LCD_rs   = 0;        //Selected command register
         LCD_rw   = 0;        //We are writing in data register
         LCD_en   = 1;        //Enable H->L
         LCD_en   = 0;
         LCD_busy();          //Wait for LCD to process the command
         LCD_data = 0x06;     //Entry mode, auto increment with no shift
         LCD_rs   = 0;        //Selected command register
         LCD_rw   = 0;        //We are writing in data register
         LCD_en   = 1;        //Enable H->L
         LCD_busy();
    }
    a few questions:

    can I use the same code as is in sourceboost for my pic? if not what changes need to be made?

    also why is the enable set to high then low? he has done this three times and has set it high then low.

    Thanks



  6. #6
    Member level 5
    Points: 924, Level: 6

    Join Date
    Oct 2010
    Posts
    89
    Helped
    3 / 3
    Points
    924
    Level
    6

    Re: Interfacing LCD to PIC Microcontroller (PIC16F877)

    if you are programing in C why not use hi tech? it has a free version and it already has a Non Rohs lcd working in the samples directory when you install it.

    if you are using a ROHS lcd just tell i will send the proper config code ^^

    If you are not changing compiler sorry but i can´t help you...



  7. #7
    Full Member level 4
    Points: 2,538, Level: 11
    qwertyuiop415263's Avatar
    Join Date
    Mar 2010
    Location
    Pakistan
    Posts
    232
    Helped
    51 / 51
    Points
    2,538
    Level
    11

    Re: Interfacing LCD to PIC Microcontroller (PIC16F877)

    check this code witten in mplab ide using C-18 toolsuite for pic18f452

    #pragma config OSC=HS, OSCS=OFF
    #pragma config PWRT=OFF, BOR=ON, BORV=45
    #pragma config WDT =OFF
    #pragma config DEBUG=OFF,LVP=OFF,STVR=OFF
    #include
    void LcdCommand (unsigned char);
    void LcdData (unsigned char);
    void Delay (int);
    #define LcdByte LATB
    #define RegSelect LATDbits.LATD5
    #define ReadWrite LATDbits.LATD6
    #define Enable LATDbits.LATD7


    void main()
    {
    int count=0;
    char Line1[] = "16x2 LCD DISPLAY";
    char Line2[] = " WITH PIC18F452!";
    LATB=0;
    TRISB=0;
    LATD=0;
    TRISD=0;
    Delay (250);
    LcdCommand (0x38);
    Delay (250);
    LcdCommand (0x0E);
    Delay (250);
    LcdCommand (0x01);
    Delay (250);
    LcdCommand (0x06);
    Delay (250);
    while(Line1[count] != '\0')
    {
    LcdData(Line1[count]);
    count++;
    }
    LcdCommand(0xC0);
    count=0;
    while(Line2[count] != '\0')
    {
    LcdData(Line2[count]);
    count++;
    }
    }

    void LcdCommand (unsigned char value)
    {
    LcdByte=value;
    RegSelect=0;
    ReadWrite=0;
    Enable=1;
    Delay (50);
    Enable=0;
    }


    void LcdData (unsigned char value)
    {
    LcdByte=value;
    RegSelect=1;
    ReadWrite=0;
    Enable=1;
    Delay (50);
    Enable=0;
    }


    void Delay (int a)
    {
    unsigned char y;
    int i;
    for (i=0;i for (y=0;y<180;y++);
    }

    ---------- Post added at 21:29 ---------- Previous post was at 21:14 ----------

    no you cannot use code of 8051 for your pic microcontroller.



    •   AltAdvertisement

        
       

  8. #8
    Full Member level 5
    Points: 3,560, Level: 14
    Achievements:
    7 years registered

    Join Date
    Feb 2007
    Location
    33 N, 73 E
    Posts
    255
    Helped
    37 / 37
    Points
    3,560
    Level
    14

    Re: Interfacing LCD to PIC Microcontroller (PIC16F877)

    If you use hitech c or CCS, drivers for a standard HD44780 compliant LCD are in the install directories of both of them, by drivers I mean sample codes.

    If you search the forum for "interfacing LCD with 16F877A" I think dozens of thread will come up and in many cased there will be working codes.

    I remember posting a working code for the same mcu at edaboard a while ago.



  9. #9
    Full Member level 1
    Points: 1,188, Level: 7

    Join Date
    Mar 2009
    Location
    Colombo
    Posts
    114
    Helped
    17 / 17
    Points
    1,188
    Level
    7

    Re: Interfacing LCD to PIC Microcontroller (PIC16F877)

    If you have mikroC PRO for PIC and open software and see library Manager and click LCD. it has good lesson and example



--[[ ]]--