LCD Display Problem on 1st line.

Discussion in 'Embedded Systems and Microcontrollers' started by Terry8345, Oct 27, 2012.

  1. Terry8345

    Thread Starter New Member

    Oct 26, 2012
    3
    0
    This is my first post, so here it goes. I'm an Electrical Engineer and have many years of experience desiginning digital circuits, but these LCD displays are really confusing. I have a 4x20 display that I actually got working. The problem I'm having is that I can't get it to display a character in the 1st position on the 1st line (address 0x80). It allways displays starting with the 2nd character position.

    Some particulars:
    I'm using a FTDI Vinculum VNC2 Microcontroller and programming in C.
    The display is the standard HD44780U controller.
    I have it configured for 8-bit data bus.
    The interface is the standard 16-pin interface.

    I've attached my LCD_Control module source code and header file. The LCD_Init() is called from the main loop in another file. All this program does is initialize the LCD and display a title message.

    Thanks for any help in advance.

    Terry
     
  2. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    4,870
    996
    Not familar with the FTDI Vinculum VNC2 nor have I looked at your code but it sounds like a classic issue of mistaking base 0 with base 1.
     
  3. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    4,870
    996
    Nope that is not it.

    Are you clearing the display before you write to it? Maybe the issue is there?
     
  4. Terry8345

    Thread Starter New Member

    Oct 26, 2012
    3
    0
    I am issuing a clear display in my init routine before I try to display my message. Another thing. I tried to display my message at a different address and it didn't move. Still displayed at character 2 on 1st line. It's like its not take the command to load an address.

    The VNC2 microcontroller is similar to a PIC. It has 8-bit I/O ports and all the standard peripherials (I2C, SPI, UART, PWM, etc.).

    Thanks

    Terry
     
  5. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    4,870
    996
    Wait. You are displaying starting with the second character or are you displaying stating in the second position?
     
  6. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    I don't see a main() so I assume it starts running at LCD_Init(). It sounds like the LCD_Msg(data) function is sending a character instead of a control byte, though the code looks correct. That would make it start at the 2nd char position after an init.

    But just to test this, see if you put:

    LCD_Cmd(TitleMsgAdd);
    LCD_Cmd(TitleMsgAdd);
    LCD_Cmd(TitleMsgAdd);

    (ie, do it 3 times instead of once) and see where the text starts appearing.
     
  7. MrChips

    Moderator

    Oct 2, 2009
    12,436
    3,360
    Remove the

    LCD_Cmd(TitleMsgAdd);

    and see what happens.

    I looked at my code and here is my init sequence:

    0x38
    0x06
    0x0C
    0x10
    0x01

    For moving to the first position, I send 0x02

    Hope this helps.
     
  8. Terry8345

    Thread Starter New Member

    Oct 26, 2012
    3
    0
    Hi ErnieM
    I tried your suggestion and the display did move, but it's always 1 more position to the right than I specify. I don't understand what is going here. I still can't get it to display in the 1st position. Why would I have to write the address 3 times for it to take affect. Is there something possibly wrong with the way I'm checking the busy bit? I did a 2x16 character disaplay a few years ago and I didn't have a problem. In fact I am using the same code except the character addresses are different for the 4x20 display I'm using now.

    Thanks

    Terry
     
  9. THE_RB

    AAC Fanatic!

    Feb 11, 2008
    5,435
    1,305
    That sounds typical of a fence post error as other people have been saying, and you keep using the term "1st position" in conversation which also hints at that type of error.

    The "1st position" is in reality position 0, and it's good to get in the practice of numbering binary locations etc starting correctly at 0.

    If you don't think it's a fence post issue then you could try removing your "busy check" function just for testing, and replace it with a 10mS delay. That will show if the busy check is somehow clocking the LCD forward one character.

    Also your code does not show a function to set the address? It's a good idea to always set the adrress before you write a char or text string to the display.

    I'm also not a big fan of this;
    c = *msg++;
    and would personally prefer to use this;
    c = msg;
    since i is already well controlled in your for() loop.
     
  10. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    4,870
    996


    I could not agree more. The later is so much more readable and you don't need to worry about remembering when your variable is incremented.
     
  11. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    Terry: First off, several people responding have yet to notice you're using the 8 bit mode so don't have it initiate to 4 bit (which is what the sequence they give you means).

    One thing I just noticed is you do not have any initiation delays anywhere. Now I don't think that is a problem since the busy flag should be high while it inits, so your code will block till it is ready.

    I'm wondering if this is somehow a sign error: since the set address commands require the most significant bit to be set then as a signed quantity then C sees this as a negative number. From what I see you correctly define unsigned char when needed, but...

    Does your system have any debugging capability for you to stop the program to see the actual data?

    I'm spitballing here as I don't see anything obvious to cause this.

    As far as the the thread hijackers go, I could not agree with them less. The increment operator will produce smaller & faster code then other constructs. I've seen savings of a few instructions just going from

    A = A + B;

    to

    A += B;

    If I was to touch your LCD_Msg() routine (and I would not until I got the placement issue addressed) I would do it like so:

    Code ( (Unknown Language)):
    1.  
    2. //----------------------------------------------------------------------------//
    3. // Display a message on display.                                              //
    4. //----------------------------------------------------------------------------//
    5. void LCD_Msg(char *msg)
    6. {
    7. //    char i,c;
    8. //    unsigned short len;
    9.    
    10. //    len = strlen(msg);
    11.    
    12. //    for (i=0;i<=len;i++)
    13.     while (*msg)                        // loop till a null char (zero) is found
    14.     {
    15.       // Make sure display isn't busy.
    16.         LCD_Busy();
    17.        
    18.         // Get character from message.
    19. //        c = *msg++;
    20.        
    21.       // Set control pins.
    22.        vos_gpio_set_port_mode(LCD_DATA, OUTPUT);
    23.     vos_gpio_write_pin(LCD_RS, DR);
    24.     vos_gpio_write_pin(LCD_RW, WR);
    25.  
    26.       // Place character in data port.
    27. //      vos_gpio_write_port(LCD_DATA, c);
    28.       vos_gpio_write_port(LCD_DATA, *msg++);    // place char & bump pointer
    29.    
    30.         // Toggle enable pin.
    31.       vos_gpio_write_pin(LCD_EN, ON);
    32.       vos_gpio_write_pin(LCD_EN, OFF);
    33.     }
    34.  
    35. }
    Note the local variables are not needed, no call to strlen() is done as all that does is count where the null is. Quicker here to check it yourself.
     
  12. atferrari

    AAC Fanatic!

    Jan 6, 2004
    2,648
    762
    First time I run across this expresion. :eek: :eek: Had to googlefor it.

    Live and learn.
     
  13. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    4,870
    996
    Maybe you know the term in Spanish. :)

    A sailing friend of mine, from Argentina, while fully capable of being a captain never wanted to be one because in a nerve racking situation she reverts to Spanish and forgets her English sailing terms. :)

    Now back to the topic. :)
     
  14. atferrari

    AAC Fanatic!

    Jan 6, 2004
    2,648
    762
    There is no equivalent that I am aware of.

    Is she in saling boats or merchant vessel? Does she lives there or here?

    Our flag has almost vanished from sea.
     
  15. THE_RB

    AAC Fanatic!

    Feb 11, 2008
    5,435
    1,305
    Who "hijacked" what? I hope you are not referring to my post? You seem very quick to dish out rude jibes lately Ernie, like in your mind you are the "master" of every thread you appear in and can decide who is allowed to say what. :(
     
  16. takao21203

    Distinguished Member

    Apr 28, 2012
    3,577
    463
    You are RCUI maybe. ROM const unsigned int.
    Or RCCCR - ROM const char* const ROM.
     
Loading...