Shop OBEX P1 Docs P2 Docs Learn Events
line adressing for 20x4 LCD — Parallax Forums

line adressing for 20x4 LCD

ArchiverArchiver Posts: 46,084
edited 2002-02-15 12:33 in General Discussion
Tobie-

The character positions on your display may be thought of as
numbered as follows (decimal):

0,1,2...17,18,19
64,65,66...81,82,83
20,21,22...37,38,39
84,85,86...101,102,103

As Jon pointed out, line 3 is a continuation of line 1, and line 4 is
a continuation of line 2.

You can cause the device to act like a 4-line display if you provide
some code to control it in that manner. What your Stamp must do is
keep track (a byte variable) of the current position on the LCD,
then modify the positon address as needed.

For instance, after writing to position 19, you must command the LCD
to reposition to 64 (use the DDRAM address set command) before
writing the next character. Similarly for positions 83, 39 and 103.

Alternatively, you can recover the current DDRAM addres from the LCD
rather than track the number with a Stamp variable. This requires
an extra Stamp pin (can't just hardwire R/W low), but gives you the
added capability to read back the DDRAM contents as well, which in
turn allows more smarts in your display (shift lines up, smart word
wrapping, etc.).

If none of this makes sense to you, you need to get your hands on a
good HD44780 functional description. I like:

http://home.iae.nl/users/pouweha/lcd/lcd.shtml

I'd suggest a single subroutine that's called every time you want to
write a character to the LCD. That subroutine would keep track of
things and tweak the LCD position as needed.

Regards,

Steve

On 14 Feb 02 at 12:10, tobiekerridge wrote:

> I'm starting to tinker with a 20x4 character lcd and have an
> immediate problem with lond strings, which write to lines 1, 3, 2
> and then line 4.

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2002-02-14 12:10
    I'm starting to tinker with a 20x4 character lcd and have an
    immediate problem with lond strings, which write to lines 1, 3, 2
    and then line 4.

    Is there a way I can change this behaviour throughout my
    program without having to create a sub routine everytime I want
    to send a string? Any code suggestions would be greatly
    appreciated.

    Tobie
  • ArchiverArchiver Posts: 46,084
    edited 2002-02-14 17:09
    What you've discovered is that four-line LCDs are actually two, with the
    lines split and interleaved. As you noted, this can lead to problems. With
    a 4x20 display there are no "hidden" character positions. About the only
    thing you can do is plan your program so that a string doesn't overwrite the
    end of the physical display and cause an undesired wrap-around.

    -- Jon Williams
    -- Parallax


    In a message dated 2/14/02 6:10:54 AM Central Standard Time, tobie@m...
    writes:


    > I'm starting to tinker with a 20x4 character lcd and have an
    > immediate problem with lond strings, which write to lines 1, 3, 2
    > and then line 4.
    >
    > Is there a way I can change this behaviour throughout my
    > program without having to create a sub routine everytime I want
    > to send a string? Any code suggestions would be greatly
    >




    [noparse][[/noparse]Non-text portions of this message have been removed]
  • ArchiverArchiver Posts: 46,084
    edited 2002-02-15 06:23
    Tobie-

    If you're working with a BS2p, I'd try something like:

    SERIN serial_pin,baud,[noparse][[/noparse]SPSTR 21] ' get packet into scratchpad
    GET 0,line_num ' retrieve line # from scratchpad
    LCDCMD lcd_pin, 128 + ( line_num & 1 * 64 ) + ( line_num & 2 * 10 )
    FOR i = 1 TO 21 ' send data from scratchpad to LCD
    GET i,temp
    LCDOUT lcd_pin,0,[noparse][[/noparse] temp ]
    NEXT

    The LCDCMD line is designed to set the display position to 0 for line
    0, 64 for line 1, 20 for line 2, 84 for line 3.

    If your Stamp is not a BS2p, then you have no native LCD commands and
    no SPSTR capability and things get more fun. If you're working with
    a BS1 or BS2 you also have no scratchpad and things get much more
    fun (read the manual regarding the use of STR\n to see how to use the
    variable space as a string array in various instructions).



    Regards,

    Steve
  • ArchiverArchiver Posts: 46,084
    edited 2002-02-15 12:33
    thanks to Jon and Steve,

    this all makes sense, in one way it is what I most feared, on the
    other hand it will serve as an exercise to understand the ins and
    outs of stamp programming!

    I'm going to send my strings in 21 charater "packets" and grab
    them with SERIN, the first charater will be an identifier for the line
    number.

    Is there any way to have a string variable return its nth character,
    in fact is there any way to manipulate strings without putting
    each character into an array?

    this is fun though!
Sign In or Register to comment.