+ Post New Thread
Results 1 to 14 of 14
  1. #1
    Banned
    Points: 12,436, Level: 26

    Join Date
    Apr 2013
    Posts
    2,528
    Helped
    538 / 538
    Points
    12,436
    Level
    26

    HD44780 40x4 4 bit LCD help

    I have ported this mikroBasic code to mikroC code but the data displayed is not proper. What is the problem with the code ?

    https://www.mikroe.com/forum/viewtopic.php?f=97&t=52891

    The author of the mikroBasic code has shown that the data is displayed properly on hardware LCD. I am testing in Proteus as I have not yet received my 40x4 LCD. Is it a Proteus HD44780 40x4 LCD bug ? Can somebody test my code on hardware and reply if the text is displayed properly or not on the LCD ?

    Click image for larger version. 

Name:	40x4 LCD 4 bit.png 
Views:	13 
Size:	25.0 KB 
ID:	114076

  2. #2
    Super Moderator
    Points: 29,643, Level: 41
    andre_teprom's Avatar
    Join Date
    Nov 2006
    Location
    Brazil
    Posts
    8,863
    Helped
    1115 / 1115
    Points
    29,643
    Level
    41
    Blog Entries
    9

    Re: HD44780 40x4 4 bit LCD help

    As a first attempt, try inserting a delay on routine void LCD_Init().
    --------------------------------------------------------------------------------------------------
    Part of the world that you live in, You are the part that you're giving ( Renaissance )


    1 members found this post helpful.

  3. #3
    Banned
    Points: 12,436, Level: 26

    Join Date
    Apr 2013
    Posts
    2,528
    Helped
    538 / 538
    Points
    12,436
    Level
    26

    Re: HD44780 40x4 4 bit LCD help

    I added 30 ms delay but still doesn't work. First character in first line also doesn't display.

    Here is another mikroBasic code. I will port this to mikroC code soon.

    http://www.mikroe.com/forum/viewtopic.php?t=5602

    Once I get the 4 bit parallel 40x4 LCD code working then I will use PCF8574 and make it 40x4 I2C LCD C code.



    •   AltAdvertisement

        
       

  4. #4
    Super Moderator
    Points: 29,643, Level: 41
    andre_teprom's Avatar
    Join Date
    Nov 2006
    Location
    Brazil
    Posts
    8,863
    Helped
    1115 / 1115
    Points
    29,643
    Level
    41
    Blog Entries
    9

    Re: HD44780 40x4 4 bit LCD help

    Quote Originally Posted by milan.rajik View Post
    I added 30 ms delay but still doesn't work. First character in first line also doesn't display
    According to step1 on this link, it is recomended a minimal 100ms for initialization of HD44780 based LCD´s.
    --------------------------------------------------------------------------------------------------
    Part of the world that you live in, You are the part that you're giving ( Renaissance )


    1 members found this post helpful.

    •   AltAdvertisement

        
       

  5. #5
    Banned
    Points: 12,436, Level: 26

    Join Date
    Apr 2013
    Posts
    2,528
    Helped
    538 / 538
    Points
    12,436
    Level
    26

    Re: HD44780 40x4 4 bit LCD help

    Ok. Changed the delay to 150 ms but still the same problem.



  6. #6
    Advanced Member level 2
    Points: 3,760, Level: 14
    Achievements:
    7 years registered

    Join Date
    May 2012
    Posts
    504
    Helped
    118 / 118
    Points
    3,760
    Level
    14

    Re: HD44780 40x4 4 bit LCD help

    The circuit is not right, Vee should be connected to ground via a pot, and the unused inputs on the LCD should be left floating. The LCD inputs should be left floating as they have pull ups to the supply. This wont make any difference to Proteus, but is important when you come to build it up.


    1 members found this post helpful.

    •   AltAdvertisement

        
       

  7. #7
    Banned
    Points: 12,436, Level: 26

    Join Date
    Apr 2013
    Posts
    2,528
    Helped
    538 / 538
    Points
    12,436
    Level
    26

    Re: HD44780 40x4 4 bit LCD help

    In Proteus pot is not needed. In hardware I have always grounded RW, D0-D4 pins of HD44780 cpmpatible LCDs and they have always worked fine.



  8. #8
    Advanced Member level 1
    Points: 5,308, Level: 17

    Join Date
    Jul 2004
    Location
    Hungary
    Posts
    479
    Helped
    189 / 189
    Points
    5,308
    Level
    17

    Re: HD44780 40x4 4 bit LCD help



    1 members found this post helpful.

  9. #9
    Banned
    Points: 12,436, Level: 26

    Join Date
    Apr 2013
    Posts
    2,528
    Helped
    538 / 538
    Points
    12,436
    Level
    26

    Re: HD44780 40x4 4 bit LCD help

    @zuisti

    I have used the same code. I also tried the code at libstock. Compiled for PIC18F45K22 by changing PORTx to LATx. Still the same problem. Maybe it is a bug of Proteus model.



  10. #10
    Super Moderator
    Points: 29,643, Level: 41
    andre_teprom's Avatar
    Join Date
    Nov 2006
    Location
    Brazil
    Posts
    8,863
    Helped
    1115 / 1115
    Points
    29,643
    Level
    41
    Blog Entries
    9

    Re: HD44780 40x4 4 bit LCD help

    Seems as you are using a code originaly designed to work with a 16x4 LCD.
    --------------------------------------------------------------------------------------------------
    Part of the world that you live in, You are the part that you're giving ( Renaissance )



  11. #11
    Advanced Member level 2
    Points: 3,760, Level: 14
    Achievements:
    7 years registered

    Join Date
    May 2012
    Posts
    504
    Helped
    118 / 118
    Points
    3,760
    Level
    14

    Re: HD44780 40x4 4 bit LCD help

    HTML Code:
    In Proteus pot is not needed. In hardware I have always grounded RW, D0-D4 pins of HD44780 cpmpatible LCDs and they have always worked fine.
    If the R/W is grounded then it does not matter if you ground the D0-D4 pins. However there are pull up resistors on these pins so you will save a bit of current by leaving them floating.


    1 members found this post helpful.

    •   AltAdvertisement

        
       

  12. #12
    Advanced Member level 1
    Points: 5,308, Level: 17

    Join Date
    Jul 2004
    Location
    Hungary
    Posts
    479
    Helped
    189 / 189
    Points
    5,308
    Level
    17

    Re: HD44780 40x4 4 bit LCD help

    I also tried the programs on the mikroE forum, and yes, seems they are wrong in LCD addressing and in E1-E2 handling (and ... very poor and inefficient coding, sorry).

    After some Google-ing I found other solutions also:

    http://www.ccsinfo.com/forum/viewtopic.php?t=32091

    http://www.nerdkits.com/forum/thread/2023/

    Attached the picture which shows the properties of the 40x4 LCD in Proteus 8. We can see the 2-3 line addresses are the same as the 1-2. I think in case of 1-2 have to use E1 (and for 2-3 lines the E2).

    This is an interesting issue, later (when I have time) I used to try to handle the 40x4 LCD in mikroC.

    But ... it is not at all certain that your actual LCD follows this (modifiable) model, the best to try it in reality ...


    3 members found this post helpful.

  13. #13
    Banned
    Points: 12,436, Level: 26

    Join Date
    Apr 2013
    Posts
    2,528
    Helped
    538 / 538
    Points
    12,436
    Level
    26

    Re: HD44780 40x4 4 bit LCD help

    @zuisti

    Below is the code piece from nerdkits code.

    Code C - [expand]
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    
    // lcd_write_nibble(...)
    void lcd_write_nibble(char c) {
     
      // NOTE: only 2 or 3 work in the delays here.
     
      // set data
      PORTD &= ~(0x0f << 2);
      PORTD |= (c&0x0f) << 2;
     
      // Toggle E1 if in 1st two rows
      if(E1){PORTD |= (1<<PD6); delay_us(1); PORTD &= ~(1<<PD6); delay_us(1);}
      // Toggle E2 if in 2nd two rows
      if(E2){PORTB |= (1<<PB1); delay_us(1); PORTB &= ~(1<<PB1); delay_us(1);}
    }

    To toggle E1 or E2 pins how does he know whether data (nibble) is for first two rows or second two rows ?


    1 members found this post helpful.

  14. #14
    Advanced Member level 1
    Points: 5,308, Level: 17

    Join Date
    Jul 2004
    Location
    Hungary
    Posts
    479
    Helped
    189 / 189
    Points
    5,308
    Level
    17

    Re: HD44780 40x4 4 bit LCD help

    As I see the nerdkits code always uses an lcd_goto_position function (or similar, like the lcd_home or the lcd_clear_and_home) to properly set E1 and E2, before EVERY char-out LCD functions, like the lcd_write_string, for example.

    After examining the lcd_goto_position function we can see it uses other LCD addressing than on the above picture.
    In Proteus use the LC4857 module (not the normal 40x4 module!), it works with the expected addressing, and works properly as the above ccsinfo site says at its last line.

    Or ... simply modify the properties of the normal 40x4 LCD module.


    2 members found this post helpful.

--[[ ]]--