+ Post New Thread
Results 1 to 6 of 6
  1. #1
    Newbie level 2
    Points: 23, Level: 1

    Join Date
    Sep 2019
    Posts
    2
    Helped
    0 / 0
    Points
    23
    Level
    1

    lcd interfacing with pic 16f877a

    hi dear,

    i am new to pic and ccs compiler. i write a code for lcd interfacing and simulating on the proteus. lcd showes nothing. guide me please what and where is the error? the code is as following;
    Code C - [expand]
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    
    #include "C:\Program Files\PICC\lcd1.h"
     
    #define LCD_RS_PIN PIN_C0
    #define LCD_RW_PIN PIN_C1
    #define LCD_ENABLE_PIN PIN_C2
    #define LCD_D4 PIN_C3
    #define LCD_D5 PIN_C4
    #define LCD_D6 PIN_C5
    #define LCD_D7 PIN_C6
    //End LCD module connections
     
    //#include <16F877A.h>
    #use delay(crystal=20000000)
     
    #include <lcd1.c>
     
    void main(){
    set_trix_c(0x00);
      lcd_init();    // Initialize LCD module
      
      while(TRUE){
        lcd_putc('\f');
        lcd_gotoxy(4, 1);           // Go to column 4 row 1
        lcd_putc("PIC16F877A");
        delay_ms(2000);
        
      
       }
    }

    kind regards
    msanwer

    •   AltAdvertisement

        
       

  2. #2
    Advanced Member level 5
    Points: 12,632, Level: 26
    Achievements:
    7 years registered

    Join Date
    Apr 2010
    Posts
    1,917
    Helped
    411 / 411
    Points
    12,632
    Level
    26

    Re: lcd interfacing with pic 16f877a

    your lcd_init() function should have the 4bit interface and the number of lines in the display related code plus other mode set codes.

    otherwise lcd will not display the characters.


    1 members found this post helpful.

    •   AltAdvertisement

        
       

  3. #3
    Advanced Member level 4
    Points: 8,209, Level: 21
    Achievements:
    7 years registered
    paulfjujo's Avatar
    Join Date
    Jun 2008
    Location
    France 01120
    Posts
    1,324
    Helped
    269 / 269
    Points
    8,209
    Level
    21

    Re: lcd interfacing with pic 16f877a

    hello,

    check if
    lcd_putc(xxxx); is a function to printout a single character (byte) or a string ( serie of byte + zero)



    •   AltAdvertisement

        
       

  4. #4
    Newbie level 2
    Points: 23, Level: 1

    Join Date
    Sep 2019
    Posts
    2
    Helped
    0 / 0
    Points
    23
    Level
    1

    Re: lcd interfacing with pic 16f877a

    hi dear,
    how to check whether lcd_init() is 4 bit or 8 bit interfaced?



  5. #5
    Super Moderator
    Points: 81,321, Level: 69
    Achievements:
    7 years registered
    Awards:
    2nd Helpful Member
    betwixt's Avatar
    Join Date
    Jul 2009
    Location
    Aberdyfi, West Wales, UK
    Posts
    13,334
    Helped
    4454 / 4454
    Points
    81,321
    Level
    69

    Re: lcd interfacing with pic 16f877a

    If the LCD only has 4 data lines connected to the PIC it is a 4-bit interface, if it has 8 data lines connected it is an 8-bit interface.
    Note that the commands and characters are always 8-bit, if you use 4-bit mode it sends the high four bits and low four bits as two transfers instead of one.

    Brian.
    PLEASE - no friends requests or private emails, I simply don't have time to reply to them all.
    It's better to share your questions and answers on Edaboard so we can all benefit from each others experiences.



    •   AltAdvertisement

        
       

  6. #6
    Advanced Member level 4
    Points: 8,209, Level: 21
    Achievements:
    7 years registered
    paulfjujo's Avatar
    Join Date
    Jun 2008
    Location
    France 01120
    Posts
    1,324
    Helped
    269 / 269
    Points
    8,209
    Level
    21

    Re: lcd interfacing with pic 16f877a

    Hello,


    at first, gives answer to whom want to help you !
    lcd_putc(xxx) can't be used for a simple char AND/OR a string
    you need 2 separate functions.

    the only way is to know the detail of the lcd_init() function
    your can analyse the *.asm or *.lst file resulting after compiling the source

    the best way , is to write yourself this Lcd_init function .
    A LCD is in 8 bit mode by default,
    then you change it by 4 bit mode...

    Code:
    void LCD_Cmd(Byte Cde)
    {   Byte D2;
        LCD_RS = 0;
        // envois poid fort
         D2 = Cde >> 4;
         LCD_RS = 0;        
        Transmet (D2);
    // envois poid faible
        D2= Cde & 0x0F;
         LCD_RS = 0;        
        Transmet (D2);
    }
    
    
    void Init_LCD_2X16(void)
    {
        Byte Cde;
    
        LCD_E  = 0;
        LCD_RW = 0;
        LCD_RS = 0;
        Cde= 0x30;             // Mode 8 bit
        LCD_Cmd(Cde);
        DELAY_15MS;
    
        Cde= 0x30;             // Mode 8 bit
        LCD_Cmd(Cde);        // MSB
        Delay_2Ms;
        LCD_Cmd(Cde);        // MSB
        Delay_2Ms;
        LCD_Cmd(Cde);        // MSB
        Delay_2Ms;
    
        Cde= 0x20;            // mode 4 bit sur B4..B7
        LCD_Cmd(Cde);            
    
    
        // 2 lignes , carac 5x7  =0x28
        Cde= 0x20;                        
        LCD_Cmd(Cde);    
        Cde= 0x80;                            
        LCD_Cmd(Cde);                    
        Delay_2Ms;
        // no cursor
        Cde= 0x00;
        LCD_Cmd(Cde);
        Cde = 0x0C;                    
        LCD_Cmd(Cde);
        Delay_2Ms;    // delais de 2ms
    
        //efface display
        Cde = 0x00;
        LCD_Cmd(Cde);
        Cde = 0x01;                        
        LCD_Cmd(Cde);
        Delay_2Ms;    // delais de 2ms
    
    }



--[[ ]]--