LCD Display Problem on 1st line.

Thread Starter

Terry8345

Joined Oct 26, 2012
3
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
 

Attachments

spinnaker

Joined Oct 29, 2009
7,830
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
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.
 

Thread Starter

Terry8345

Joined Oct 26, 2012
3
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
 

ErnieM

Joined Apr 24, 2011
8,377
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.
 

MrChips

Joined Oct 2, 2009
30,810
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.
 

Thread Starter

Terry8345

Joined Oct 26, 2012
3
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
 

THE_RB

Joined Feb 11, 2008
5,438
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.
...
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.
 

spinnaker

Joined Oct 29, 2009
7,830
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.


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.
 

ErnieM

Joined Apr 24, 2011
8,377
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.
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:

Rich (BB code):
//----------------------------------------------------------------------------//
// Display a message on display.                                              //
//----------------------------------------------------------------------------//
void LCD_Msg(char *msg)
{
//    char i,c;
//    unsigned short len;
    
//    len = strlen(msg);
    
//    for (i=0;i<=len;i++)
    while (*msg)                        // loop till a null char (zero) is found
    {
      // Make sure display isn't busy.
        LCD_Busy();
        
        // Get character from message.
//        c = *msg++;
        
      // Set control pins.
       vos_gpio_set_port_mode(LCD_DATA, OUTPUT);
    vos_gpio_write_pin(LCD_RS, DR);
    vos_gpio_write_pin(LCD_RW, WR);

      // Place character in data port.
//      vos_gpio_write_port(LCD_DATA, c);
      vos_gpio_write_port(LCD_DATA, *msg++);    // place char & bump pointer
    
        // Toggle enable pin.
      vos_gpio_write_pin(LCD_EN, ON);
      vos_gpio_write_pin(LCD_EN, OFF);
    }

}
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.
 

spinnaker

Joined Oct 29, 2009
7,830
First time I run across this expresion. :eek: :eek: Had to googlefor it.

Live and learn.
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. :)
 

atferrari

Joined Jan 6, 2004
4,770
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. :)
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.
 

THE_RB

Joined Feb 11, 2008
5,438
...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. ...
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. :(
 
Top