having problem in Interfacing lcd hardware to 8051 kit

Discussion in 'Embedded Systems and Microcontrollers' started by bobparihar, Aug 5, 2014.

  1. bobparihar

    Thread Starter Member

    Jul 31, 2014
    93
    0
    i have a 8051 developing kit from robosoft labs which have different interfacing units like led's, 7seg, lcd,motor etc..
    when i connect lcd (16*2) to the kit it dosent getting on.. lcd shows no light
    here is the code

    Code ( (Unknown Language)):
    1.  
    2. #include<reg51.h>
    3. sbit rs=P1^0;  
    4. sbit rw=P1^1;
    5. sbit en=P1^2;
    6. unsigned int i,j;
    7. void dat(unsigned char);     //data fxn
    8. void cmd(unsigned char);   // command fxn
    9. void main()
    10. {
    11.     cmd(0x38);  // display on cursor on
    12.     cmd(0x0E);    // display on cursor blinking
    13.     cmd(0x06);   // increment cursor to right
    14.     cmd(0x01);  // clear display screen
    15.     cmd(0x80);  //  force cursor to start from first line first position
    16.     dat('h');    // data to data pins from p3
    17.    
    18.      while(1);   //hold
    19. }
    20.  
    21. void cmd(unsigned char x)
    22. {
    23.   P3=x;
    24.     rs=0;     //indicating  command
    25.     rw=0;
    26.     en=1;
    27.     for(i=0;i<5000;i++);   //delay
    28.     en=0;
    29. }
    30. void dat(unsigned char y)
    31. {
    32.     P3=y;
    33.     rs=1;   // indicating data
    34.     rw=0;
    35.     en=1;
    36.     for(i=0;i<5000;i++);
    37.     en=0;
    38. }  
    39.  

    i have connected all data pins and control pins(rs, rw,en) to their correct position.. but still im not gettiong the lcd aty on position.. so i connected vcc and gnd to the lcd pins externally.. still not getting lcd on.. and i dont think that lcd is not working because i did replace 5 lcd with same procedure

    plz help
     
    Last edited by a moderator: Aug 5, 2014
  2. shteii01

    AAC Fanatic!

    Feb 19, 2010
    3,379
    494
    A couple of problems:
    * no delays between the cmd()
    * no returns in user defined functions
     
  3. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    First off, there needs to be a long delay (10mS) on power up before using the device.

    Next, each command needs 37 uS delay beofer the next, with a few exceptions (like clear or home) that need 1.52 mS.

    The best way to work out a new coding scheme is to insert huge delays (up to 1/2 a second) between everything. Once you see the "h" you can start working these down to "whatever works faster."

    I don't see any need for an explicit return in your void C functions.
     
    bobparihar likes this.
  4. joeyd999

    AAC Fanatic!

    Jun 6, 2011
    2,674
    2,717
    Ummm....that's not exactly the way an engineer would approach the problem...
     
  5. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    Hey, I *AM* an engineer...:D

    If I had the data sheet for the exact model display used by bobparihar I could give a better answer, but I have seen wildly different specs on these necessary delays depending on I don't know what, but probably different revs or manufactures of the drive IC.

    As "much longer" will work 100% it is one place to start. I've hinted at the target delays (that in my project I would toss in some extra "just in any case".
     
  6. THE_RB

    AAC Fanatic!

    Feb 11, 2008
    5,435
    1,305
    If the compiler is optimising, it might simply ignore this line;
    for(i=0;i<5000;i++); //delay
    because it doesn't do anything.

    You should use the compilers delay() functions, check the compiler help file.

    Also, if using delays you need one to set the E high period, then another delay afterward to allow the LCD to execute the command. You are not doing the second delay which is the most important one!

    The LCD datasheet (Hitachi 44780) shows the necessary minimum delays.
     
  7. takao21203

    Distinguished Member

    Apr 28, 2012
    3,577
    463
    I dont use these Hitachi LCDs anymore- takes too long to wire them, 3.3v is difficult even if I have one's with charge pump, adapting delays is too messy as well.

    Recently I tried a Nokia5110 and got it working very quick, also serial TFTs, very easy. I should offer my remaining character LCDs on the fleamarket but...they are cheap new, its probably not worth it. They all have been soldered to.
     
  8. THE_RB

    AAC Fanatic!

    Feb 11, 2008
    5,435
    1,305
    It's not so bad connecting 6 signal wires, 2 power wires and a 10k trimpot.

    But I get your point. I designed a small PCB for a 28pin PIC and LCD header, and had a heap made in a batch. Worked out about a dollar a PCB after postage and setup etc.

    Now I can whip up a 28pin PIC + text LCD project very quickly. :)
     
  9. bobparihar

    Thread Starter Member

    Jul 31, 2014
    93
    0
    Is this is correct Erniem?
    Code ( (Unknown Language)):
    1.  
    #include<reg51.h>
    sbit rs=P3^0;
    sbit rw=P3^1;
    sbit en=P3^2;
    unsigned int i,j;
    void dat(unsigned char); // data fxn
    void cmd(unsigned char); // command fxn
    void delay(unsigned int); //delay fxn for 1ms
    void main()
    {
    delay(10);
    cmd(0x38);
    delay(1);
    cmd(0x0E);
    delay(1);
    cmd(0x06);
    delay(1);
    cmd(0x01);
    delay(1);
    cmd(0x80);
    delay(1);
    dat('h');
    delay(1);

    while(1);

    }

    void cmd(unsigned char x)
    {
    P2=x;
    rs=0;
    rw=0;
    en=1;
    for(i=0;i<500;i++);
    en=0;
    }
    void dat(unsigned char y)
    {
    P2=y;
    rs=1;
    rw=0;
    en=1;
    for(i=0;i<500;i++);
    en=0;
    }
    void delay(unsigned int z)
    {
    for(i=0;i<z;i++)
    {
    for(i=0;i<1275;i++);

    }
    }



    this works correct on simulation( proteus) but i cant even get thye cursor blinking on hardware
     
  10. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    So try making all the delays 10x longer.
     
    bobparihar likes this.
  11. klangst

    Member

    Jul 5, 2013
    56
    0
    I am very new to all of this and this in theory should not be a problem with a development board, but all unused data pins from the lcd should go to ground in my understanding. I have seen issues where the lcd would not work and it was due to unused data pins being left unconnected.
     
  12. shteii01

    AAC Fanatic!

    Feb 19, 2010
    3,379
    494
    Can you tell us which LCD data pins/lines are not being used?
     
  13. klangst

    Member

    Jul 5, 2013
    56
    0
    In 4-bit mode, D0, D1, D2 and D3 are connected to ground. I was not clear if this is being used in 4-bit or 8-bit mode. I say I am very new to this and am learning by reading and posting.
     
  14. shteii01

    AAC Fanatic!

    Feb 19, 2010
    3,379
    494
    Is OP using 4 bit mode?
     
  15. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    His posted code has no indication of driving a 4 bit display.

    Aside: when using displays in 4 bit mode I will leave the unused data pins just float. They do have internal (pull up I believe) resistors to keep them from truly floating if unconnected.
     
    Last edited: Aug 8, 2014
  16. bobparihar

    Thread Starter Member

    Jul 31, 2014
    93
    0
    thanks everyone here..i had fixed the error.. now my lcd showing correct output


    iam using the following code for shifting the string given to lcd
    Code ( (Unknown Language)):
    1.  
    2. while(1)
    3. {
    4. cmd(0x1c);  // shift entire output to the right
    5. delay(20);   // delay for 20ms
    6. }
    7.  
    i did acheive the shifting, but the shifting is not smooth.. means the animation is not smooth...i did changed the delay sevral time but im not getting what i want..
    anyone? plz help
     
    Last edited by a moderator: Aug 8, 2014
  17. shteii01

    AAC Fanatic!

    Feb 19, 2010
    3,379
    494
    You could try reading busy flag instead of using delay.

    However, it is possible that your lcd is too slow no matter what you do, in this case the only thing you can do to get faster/better animation is to use a faster lcd.
     
Loading...