display lcd problem black square

Discussion in 'General Electronics Chat' started by MED_TN, Feb 21, 2013.

Thread Status:
Not open for further replies.
  1. MED_TN

    Thread Starter New Member

    Feb 21, 2013
    my program function well in ISIS proteus but in the real life it dosen't, the problem thats a have in the first line many black square.
    i use a 4 bits configuration and 18f4550 pic.
    thats my program please help me.
    sorry for my bad level of english thats my first time in this forum.

    sbit LCD_RS at LATB0_bit;
    sbit LCD_EN at LATB1_bit;
    sbit LCD_D4 at LATB2_bit;
    sbit LCD_D5 at LATB3_bit;
    sbit LCD_D6 at LATB4_bit;
    sbit LCD_D7 at LATB5_bit;

    // Pin direction
    sbit LCD_RS_Direction at TRISB0_bit;
    sbit LCD_EN_Direction at TRISB1_bit;
    sbit LCD_D4_Direction at TRISB2_bit;
    sbit LCD_D5_Direction at TRISB3_bit;
    sbit LCD_D6_Direction at TRISB4_bit;
    sbit LCD_D7_Direction at TRISB5_bit;

    /****************************Programme Principal*********************/

    void main()


  2. tshuck

    Well-Known Member

    Oct 18, 2012
    1.) use code tags(click the '#' button while editing...) to put your code in a proper format.

    2.). Add a while(1) to you code so the PC doesn't progress past your program memory usage....

    Code ( (Unknown Language)):
    1. sbit LCD_RS at LATB0_bit;
    2. sbit LCD_EN at LATB1_bit;
    3. sbit LCD_D4 at LATB2_bit;
    4. sbit LCD_D5 at LATB3_bit;
    5. sbit LCD_D6 at LATB4_bit;
    6. sbit LCD_D7 at LATB5_bit;
    8. // Pin direction
    9. sbit LCD_RS_Direction at TRISB0_bit;
    10. sbit LCD_EN_Direction at TRISB1_bit;
    11. sbit LCD_D4_Direction at TRISB2_bit;
    12. sbit LCD_D5_Direction at TRISB3_bit;
    13. sbit LCD_D6_Direction at TRISB4_bit;
    14. sbit LCD_D7_Direction at TRISB5_bit;
    17. /****************************Programme Principal*********************/
    19. void main()
    20. {
    22. TRISA=0x00;
    23. TRISB=0x00;
    24. PORTB.f0=0;
    25. PORTA=0xFF;
    26. Lcd_Init();
    27. Lcd_Cmd(_LCD_CLEAR);
    28. Lcd_Cmd(_LCD_CURSOR_OFF);
    30. delay_ms(500);
    31. Lcd_Out(1,1,"bonjour");
    32. delay_ms(500);
    33. LCD_out(2,2,"Salut");
    34. delay_ms(500);
    35. [COLOR="Red"]while(1);[/COLOR]
    36. }
  3. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    We can understand you well enough (and it's better then some native English speakers here).

    Does your circuit do anything? There are things that stop a real PIC that ISIS proteus doesn't see, such as the oscillator or configuration bits. Can you get a pin to change state? Just turn it on high and leave it there, a voltmeter or even a LED can see if that worked.

    Posting your whole schematic would help. Also if you post in the Embedded Systems and Microcontrollers forum here it gets better attention.

    Welcome to the forums!
  4. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    Some will argue that this is always a symptom of an initialization problem which is a good argument but I have seen this issue caused by the contrast pin too.

    So I would check twp things. First I would verify pin by pin that the LCD is wired the way you think it is wired. You can use a scope, logic analyzer, logic probe, voltmeter. Whatever you have. You can make a probe out of an led and resistor.

    Next I would check that voltage on the contrast pin is changing as you change the potentiometer.
  5. MED_TN

    Thread Starter New Member

    Feb 21, 2013
    Thanks to youe answer i dont have the shematic now but i put the third pin (3) of the LCD in the GND i didn't use a pot and (do you think thats not wrong ??) and in my program i did'nt put a delay_ms before lcd_inti() i will changed and i will see what happened.
    I use a led and it function very well so i thnik the pic dont have problem with my code.
    please if you have any other solutions or idea give it to me and monday i will try all the solution in the university.
    thx for all memeber i like this forum it is full with ideas.
  6. MED_TN

    Thread Starter New Member

    Feb 21, 2013
    also i I connected RW pin to Ground because i use the lcd only to write things and i see in others forum that it is wrong and i must connect R/W to a pin of the pic. thats true ????
    and if i must do it what i must change in my program
  7. tshuck

    Well-Known Member

    Oct 18, 2012
    You need a potentiometer to adjust the contrast...otherwise you'll just see either nothing, or a bunch of black rectangles....

    Follow this:

  8. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    "Black squares" is either a contrast pot problem, or a bad initialization.

    The LCD is capable of working just fine with the R/W pin grounded. However, you need to insert a delay to insure the LCD has completed what you just told it to do. I don't know what that delay is offhand but 1 mS may be good.

    You DO need a "delay_ms before lcd_inti()" as you mentioned. In fact, sprinkle in all the delays you can think of, and even make them ridiculously long... 100 mS everywhere. Once it works you can experiment with shorter delays. Do add extra delays until you know your thing works.

    Lastly, most every LCD needs that pot to set the contrast. No pot and the display can go "black squares."

    I say "most" need the pot as I happen to own one that doesn't need the pot, ignores the pot, but works just fine if it is there or not. So once your works you can try removing the pot and see what happens.
    MED_TN likes this.
  9. bertus


    Apr 5, 2008
Thread Status:
Not open for further replies.