• AVR Freaks

Hot!Display in LCD 4 x 40

Page: 123 > Showing page 1 of 3
Author
Sherif89
Starting Member
  • Total Posts : 35
  • Reward points : 0
  • Joined: 2020/02/10 09:24:36
  • Location: 0
  • Status: offline
2020/03/30 09:08:17 (permalink)
0

Display in LCD 4 x 40

Hello, 
Please I am asking you help, I have to display my data in the LCD with 4 lines x 40 characters
• 2 Built-in controllers (ST7066U)


My code and library work good for the first LCD (line 1 and 2), but I have a problem with my second LCD (line 3 and 4 ). This latter does not enabling to display.
I am using I use MPLAB X V5.30, compiler 2.10, PIC18F45K80
 
The LCD contain 2 separated Enabling PIN ( E to enable LCD 1 and E1 for enabling the LCD2)
 
In the attachment my used library 
 
Thanks

Attached Image(s)


Regards
Sherif
#1

42 Replies Related Threads

    jbroadwell81@gmail.com
    Super Member
    • Total Posts : 1449
    • Reward points : 0
    • Joined: 2005/11/02 13:58:11
    • Location: Indianapolis, Indiana
    • Status: offline
    Re: Display in LCD 4 x 40 2020/03/30 12:20:14 (permalink)
    0
    I didn't dig in deep, but it looks like you're only sending DISPLAY_SETUP to one of the 2 displays.  Do you need to follow it with 
    LCDPutCmd2(DISPLAY_SETUP);
    ?

    http://www.serialwombat.com
    When someone asks you "Can't you just...", watch out.
    #2
    Sherif89
    Starting Member
    • Total Posts : 35
    • Reward points : 0
    • Joined: 2020/02/10 09:24:36
    • Location: 0
    • Status: offline
    Re: Display in LCD 4 x 40 2020/03/30 12:31:35 (permalink)
    0
    Thanks for your response!
     
    The DISPLAY_SETUP equal to ''0x0C'' in order display on, cursor off, blink off
    So it is not important to add this Cmd! Optional Cmd
     
    Also, it does not work when  I replace LCD_EN  with LCD_EN2  in LCD.C file!

    Regards
    Sherif
    #3
    ric
    Super Member
    • Total Posts : 26943
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: Display in LCD 4 x 40 2020/03/30 12:36:08 (permalink)
    +1 (1)
    I don't think you have got the concept that you are talking to two SEPERATE display chips.
    You have to change the code to drive LCD_EN to talk to the first chip, and LCD_EN2 to talk to the second chip.
    You cannot hard code it to one or the other.
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #4
    Sherif89
    Starting Member
    • Total Posts : 35
    • Reward points : 0
    • Joined: 2020/02/10 09:24:36
    • Location: 0
    • Status: offline
    Re: Display in LCD 4 x 40 2020/03/30 12:41:41 (permalink)
    0
    I have the concept of the two chips (two controllers) look my LCD.C
    post edited by Sherif89 - 2020/03/30 12:48:27

    Regards
    Sherif
    #5
    Sherif89
    Starting Member
    • Total Posts : 35
    • Reward points : 0
    • Joined: 2020/02/10 09:24:36
    • Location: 0
    • Status: offline
    Re: Display in LCD 4 x 40 2020/03/30 12:49:32 (permalink)
    0
    void LCDWriteNibble(uint8_t ch, uint8_t rs) // for the first LCD
    {

    // always send the upper nibble
    ch = (ch >> 4);

    // mask off the nibble to be transmitted
    ch = (ch & 0x0F);

    // clear the lower half of LCD_PORT
    LCD_PORT = (LCD_PORT & 0xF0);

    // move the nibble onto LCD_PORT
    LCD_PORT = (LCD_PORT | ch);

    // set data/instr bit to 0 = insructions; 1 = data
    LCD_RS = rs;

    // RW - set write mode
    LCD_RW = 0;

    // set up enable before writing nibble
    LCD_EN = 1;

    // turn off enable after write of nibble
    LCD_EN = 0;
    }

     // For the second LCD

    void LCDWriteNibble2(uint8_t ch2, uint8_t rs)
    {

    // always send the upper nibble
    ch2 = (ch2 >> 4);

    // mask off the nibble to be transmitted
    ch2 = (ch2 & 0x0F);

    // clear the lower half of LCD_PORT
    LCD_PORT = (LCD_PORT & 0xF0);

    // move the nibble onto LCD_PORT
    LCD_PORT = (LCD_PORT | ch2);

    // set data/instr bit to 0 = insructions; 1 = data
    LCD_RS = rs;

    // RW - set write mode
    LCD_RW = 0;

    // set up enable before writing nibble
    LCD_EN2 = 1;

    // turn off enable after write of nibble
    LCD_EN2 = 0;

    }

    post edited by Sherif89 - 2020/03/30 12:52:08

    Regards
    Sherif
    #6
    du00000001
    Just Some Member
    • Total Posts : 3665
    • Reward points : 0
    • Joined: 2016/05/03 13:52:42
    • Location: Germany
    • Status: offline
    Re: Display in LCD 4 x 40 2020/03/30 13:20:39 (permalink)
    0
    Best to use an oscilloscope or - even better - a logic analyzer to check the pins of the second module.

    PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
    #7
    Sherif89
    Starting Member
    • Total Posts : 35
    • Reward points : 0
    • Joined: 2020/02/10 09:24:36
    • Location: 0
    • Status: offline
    Re: Display in LCD 4 x 40 2020/03/30 13:24:41 (permalink)
    0
    I have checked with an oscilloscope! I have the same results for E1 and E2!
    In addition, I replaced my LCD! = LCD2 still does not work!!
     

    Regards
    Sherif
    #8
    PStechPaul
    Super Member
    • Total Posts : 2667
    • Reward points : 0
    • Joined: 2006/06/27 16:11:32
    • Location: Cockeysville, MD, USA
    • Status: offline
    Re: Display in LCD 4 x 40 2020/03/30 13:36:29 (permalink)
    0
    Is this correct?
    #define NB_LINES    2                                   // Number of display lines
    #define NB_COL      40                                  // Number of characters per line

    #define NB_LINES2    2                                   // Number of display lines
    #define NB_COL2      40                                  // Number of characters per line
     
    void LCDGoto(uint8_t pos,uint8_t ln)
    {
        // if incorrect line or column
        if ((ln > (NB_LINES-1)) || (pos > (NB_COL-1)))
        {
            // Just do nothing
            return;
        }

        // LCD_Goto command
       // LCDPutCmd((ln == 1) ? (0x03 | pos) : (0x10 | pos));
        LCDPutCmd((ln == 1) ? (0xC0 | pos) : (0x80 | pos)); //before

        // Wait for the LCD to finish
        __delay_ms(LCD_delay);
    }

    void LCDGoto2(uint8_t pos2,uint8_t ln2)
    {
        // if incorrect line or column
        if ((ln2 > (NB_LINES2-1)) || (pos2 > (NB_COL2-1)))
        {
            // Just do nothing
            return;
        }

        // LCD_Goto command
       // LCDPutCmd((ln == 1) ? (0x03 | pos) : (0x10 | pos));
        LCDPutCmd2((ln2 == 1) ? (0xC0 | pos2) : (0x80 | pos2)); //before

        // Wait for the LCD to finish
        __delay_ms(LCD_delay);
       // __delay_us(LCD_delay);
    }

     

     
    #9
    du00000001
    Just Some Member
    • Total Posts : 3665
    • Reward points : 0
    • Joined: 2016/05/03 13:52:42
    • Location: Germany
    • Status: offline
    Re: Display in LCD 4 x 40 2020/03/30 13:39:10 (permalink)
    0
    For testing, you could swap E and E1 between the modules: does the problem swap displays as well?

    PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
    #10
    Sherif89
    Starting Member
    • Total Posts : 35
    • Reward points : 0
    • Joined: 2020/02/10 09:24:36
    • Location: 0
    • Status: offline
    Re: Display in LCD 4 x 40 2020/03/30 13:48:28 (permalink)
    0
    When I swap E and E2! is does not work!
    This is the big problem!!

    Regards
    Sherif
    #11
    du00000001
    Just Some Member
    • Total Posts : 3665
    • Reward points : 0
    • Joined: 2016/05/03 13:52:42
    • Location: Germany
    • Status: offline
    Re: Display in LCD 4 x 40 2020/03/30 13:58:49 (permalink)
    +1 (1)
    Sherif89
    When I swap E and E2! is does not work!



    Meaning none of the displays is working?
    If so, it's time to use the scope again - this time measuring at the displays' pins - not at the controller's pins.
    Looks like some wiring/connection issue.

    PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
    #12
    Sherif89
    Starting Member
    • Total Posts : 35
    • Reward points : 0
    • Joined: 2020/02/10 09:24:36
    • Location: 0
    • Status: offline
    Re: Display in LCD 4 x 40 2020/03/31 04:58:27 (permalink)
    0
    Hi, 
    I have no problem with the hardware! it gives a good signal in E2 using the oscilloscope!
    I have 3 cards with 3 LCD (4x0) so, I tested with other cards, it gives the same results
    I think the problem comes from the initialization of the LCD! (just a guess)...

    Regards
    Sherif
    #13
    Sherif89
    Starting Member
    • Total Posts : 35
    • Reward points : 0
    • Joined: 2020/02/10 09:24:36
    • Location: 0
    • Status: offline
    Re: Display in LCD 4 x 40 2020/03/31 05:33:10 (permalink)
    0
    When I decrease the contrast of the LCD, I can see some characters on the LCD2 (attached picture)
     
     
    My initialisation for the two LCD (E and E2)
     
    void LCD_Initialize()
    {
            // required by display controller to allow power to stabilize
        __delay_ms(30);
        // clear latches before enabling TRIS bits
        LCD_PORT = 0;
        TRISB = 0x00;
        TRISC = 0x00;
        // power up the LCD
        LCD_PWR = 1;

        LCDPutCmd(0x30); // wake up
        __delay_ms(5);
        LCDPutCmd(0x30); // wake up
        __delay_ms(5);
        LCDPutCmd(0x30); // wake up
        __delay_ms(5);
        // set interface size, # of lines and font
        LCDPutCmd(FUNCTION_SET); // 0x28
        LCDPutCmd(0x08); //Turn off display
        DisplayClr(); // 0x01 //Clear display
        __delay_ms(1);
        // set cursor movement direction
        LCDPutCmd(ENTRY_MODE); // 0x06 Entry mode cursor increment
        LCDPutCmd(DISPLAY_SETUP); // 0x0C //Turn on display; no cursor

    }

    void LCD_Initialize2()
    {
            // required by display controller to allow power to stabilize
        __delay_ms(30);
        // clear latches before enabling TRIS bits
        LCD_PORT = 0;
        TRISB = 0x00;
        TRISC = 0x00;
        // power up the LCD
        LCD_PWR = 1;

        LCDPutCmd2(0x30); // wake up
        __delay_ms(5);
        LCDPutCmd2(0x30); // wake up
        __delay_ms(5);
        LCDPutCmd2(0x30); // wake up
        __delay_ms(5);
        // set interface size, # of lines and font
        LCDPutCmd2(FUNCTION_SET); // 0x28
        LCDPutCmd2(0x08); //Turn off display
        DisplayClr2(); // 0x01 //Clear display
        __delay_ms(1);
        // set cursor movement direction
        LCDPutCmd2(ENTRY_MODE); // 0x06 Entry mode cursor increment
        LCDPutCmd2(DISPLAY_SETUP); // 0x0C //Turn on display; no cursor

    }

    post edited by Sherif89 - 2020/03/31 05:34:33

    Attached Image(s)


    Regards
    Sherif
    #14
    Jan Audio
    Senior Member
    • Total Posts : 140
    • Reward points : 0
    • Joined: 2018/09/24 08:12:24
    • Location: 0
    • Status: offline
    Re: Display in LCD 4 x 40 2020/03/31 05:35:31 (permalink)
    0
    Just order another one, oh wait : china dont ships ?
    Made in china, some things might not work good.
    #15
    du00000001
    Just Some Member
    • Total Posts : 3665
    • Reward points : 0
    • Joined: 2016/05/03 13:52:42
    • Location: Germany
    • Status: offline
    Re: Display in LCD 4 x 40 2020/03/31 05:42:02 (permalink)
    +1 (1)
     I could already see in the first image that the 2nd LCD is getting "something" - although not exactly what it is supposed to get.
    Maybe you should refine "... it does notwork".
     
    Basically the code to control either display is the same (minor differences exempt). Thus if one display works, the other should work as well. Might be you should eliminate the last of the differences (E/E2 exempt).
     
    Any difference left might stem from a poor or open connection. So, when measuring make sure notto exert force on the connections as this might temporarily bridge an open circuit - resulting in good measurement values for a bad connection.

    PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
    #16
    du00000001
    Just Some Member
    • Total Posts : 3665
    • Reward points : 0
    • Joined: 2016/05/03 13:52:42
    • Location: Germany
    • Status: offline
    Re: Display in LCD 4 x 40 2020/03/31 05:46:45 (permalink)
    +1 (1)
    @Jan Audio
    Surprise, surprise: more or less all small displays/modules come from China/Taiwan these days - no matter the "brand". You will hardly find a manufacturer not from Asia.

    PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
    #17
    Sherif89
    Starting Member
    • Total Posts : 35
    • Reward points : 0
    • Joined: 2020/02/10 09:24:36
    • Location: 0
    • Status: offline
    Re: Display in LCD 4 x 40 2020/03/31 05:48:34 (permalink)
    0
    I have a lot of LCD ships, I don't need to order :P 

    Regards
    Sherif
    #18
    Sherif89
    Starting Member
    • Total Posts : 35
    • Reward points : 0
    • Joined: 2020/02/10 09:24:36
    • Location: 0
    • Status: offline
    Re: Display in LCD 4 x 40 2020/03/31 05:55:16 (permalink)
    0
    The problem is software, not hardware! I have a multiple ships of LCD. 
    look the attached picture!!

    Attached Image(s)


    Regards
    Sherif
    #19
    pcbbc
    Super Member
    • Total Posts : 1687
    • Reward points : 0
    • Joined: 2014/03/27 07:04:41
    • Location: 0
    • Status: online
    Re: Display in LCD 4 x 40 2020/03/31 06:40:30 (permalink)
    +1 (1)
    I wouldn't have duplicated every single LCD library function.
     
    I'd have kept one set of functions, and set a global variable "lcd_id" which controlled which LCD I was talking to.  Then modify only the routines which toggle LCD_ENx:
    switch (lcd_id)
    {
       case 0:
          LCD_EN = 1;
          LCD_EN = 0;
          break;
       case 1:
          LCD_EN2 = 1;
          LCD_EN2 = 0;
          break;
    }

    If you can arrange for all of the LCD ENABLE pins to be on the same port (yours are not it seems), it is possible to use a bit mask instead of an ID:
    uint8_t lcd_en_mask;
    lcd_en_mask = 0x10; //PORTB.RB4 LCD_EN_1
    lcd_en_mask = 0x20; //PORTB.RB5 LCD_EN_2
    ....
    ....
    LATB |= lcd_en_mask;
    LATB &= ~lcd_en_mask;

     
    Less code =>
    a) more efficient
    b) less chance of making a mistake (or if you do make a mistake, more chance of spotting it)
     
    Also, if you have LATx registers, use them!
    Golden rule: WRITE to LATx, READ from PORTx
    #20
    Page: 123 > Showing page 1 of 3
    Jump to:
    © 2020 APG vNext Commercial Version 4.5