Shop OBEX P1 Docs P2 Docs Learn Events
16x2 LCD woes - solved — Parallax Forums

16x2 LCD woes - solved

vampyrevampyre Posts: 146
edited 2008-05-27 16:11 in Propeller 1
Hi all, i'm hoping someone has seen this problem before.

I have a 16x2 hitachi driver based LCD with a nifty white backlight. I had it up and running fine with the basic stamp 2, then i tried hook it up to my prop using the LCD 4bit driver in the object exchange.

at first it didn't work. then i realised i had my RS and E pins backwards. so i changed that. instead of hooking up to pins 0-4 i used 20-23, which i figured wouldn't work right off the bat. i changed the constant pin assignments, and moved the shift commands around. it now seems to kind of sort of work. it appears only the first line is working and the text is garbled ,but not completely.

for instance "hello world" comes out _ello`$w<-dxb.

do u guys think my LCD is fried, or is this more likely a software problem?

Post Edited (vampyre) : 5/27/2008 4:14:22 PM GMT

Comments

  • BTXBTX Posts: 674
    edited 2008-05-27 01:07
    Hi vampyre
    Read this please. Maybe you have the same problem as me, but now is working.

    http://forums.parallax.com/showthread.php?p=724362

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Regards.

    Alberto.
  • BradCBradC Posts: 2,601
    edited 2008-05-27 06:53
    If you are using LCD_16x2_4bit.spin from the object exchange it has a bug when initialising the display in 4 bit mode.
    You need to send an extra nybble after setting 4-bit mode or else it is likely to get confused about byte timing.
    I found it *always* worked after a hard-reset, but then any subsequent reset (like reset the prop but don't power down the display) would cause garbled data or an improper reset.
    See below for my revised INIT routine (which has been heavily tested over 100 cycled prop resets now)

    PRI INIT
      OUTA[noparse][[/noparse]DB7..DB4] := %0000                               ' Output low on all pins
      OUTA[noparse][[/noparse]RS] := 0
    
      OUTA[noparse][[/noparse]E]  := 1
      OUTA[noparse][[/noparse]DB7..DB4] := %0010                               ' Set to DL=4 bits
      OUTA[noparse][[/noparse]E]  := 0
    
      OUTA[noparse][[/noparse]E]  := 1                                         ' This is *required* to even up 'E' cycles!
      OUTA[noparse][[/noparse]E]  := 0
    
      OUT (%0010_1000,0)                                    ' Now that we're in 4 bits, add N=2 lines, F=5x7 fonts
      CLEAR
      OUT (%0000_1100,0)                                    ' Display on, Cursor off, Blink off                                             
      OUT (%0000_0110,0)                                    ' Increment Cursor + No-Display Shift                                             
      DIRA[noparse][[/noparse]BL] := 1
      OUTA[noparse][[/noparse]BL] := 1
    
    
  • vampyrevampyre Posts: 146
    edited 2008-05-27 13:27
    Thank you both for your quick reply.

    @BTX: I had read your post when trying to figure out what was wrong with my LCD. I'm reletivly sure that my RS,RW and E pins are
    correct now. in your post you say that the LCD bus MUST be on pins 0,1,2 and 3 .... why is that? Those pins are already used in my
    design, so i have mine hooked up to 20-23... do you think this could be the problem?

    @BradC: Your post was enlightening. I tried looking at the code i have and modifying it to match yours but my results were semi-successfull.
    what is BL in your code? i couldn't find that variable in the object. I noticed that in your code you strobe the E line after setting the 4bit mode
    , when i do that in my code i get two lines of text instead of just the one... but now all the charachters are garbled instead of just some of them.

    also i've found that the LCD doesn't seem to boot at all from a cold boot, it only seems to work when the prop is programed or reset with the reset button
  • BTXBTX Posts: 674
    edited 2008-05-27 13:44
    Sorry vampyre.
    I mean that the doccumented is bad write, and can confuse and wont work.
    If you want to use anothers pins is fine, just follow the correct "order" for the pins in the code, and rename the "P0, P1, P2, P3" for your needs.

    This is the code that I download and works fine with corrected "comments".
    I've the same problem and was the msb-lsb in the four bits data inverted, look that carrefully.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Regards.

    Alberto.
  • BradCBradC Posts: 2,601
    edited 2008-05-27 15:00
    vampyre said...

    @BradC: Your post was enlightening. I tried looking at the code i have and modifying it to match yours but my results were semi-successfull.
    what is BL in your code? i couldn't find that variable in the object. I noticed that in your code you strobe the E line after setting the 4bit mode
    , when i do that in my code i get two lines of text instead of just the one... but now all the charachters are garbled instead of just some of them.

    also i've found that the LCD doesn't seem to boot at all from a cold boot, it only seems to work when the prop is programed or reset with the reset button

    Whoops.. you can remove the calls for BL. they switch my backlight on.
    If you are now getting 2 lines and everything is garbled it sounds like you may have your data lines backwards..

    For reference, here are mine.
    I've hardwired the R/W pin to GND as I don't intend to read from the display any time soon.

    In fact, I'll just attach the object..

    ' Pin assignment
      RS = 8                   
      E  = 7
      BL = 9                        ' Backlight
    
      DB4 = 3
      DB7 = 6
    
    
  • vampyrevampyre Posts: 146
    edited 2008-05-27 16:11
    Thank you guys so much, its up and running perfectly.
    BradC, your modified object fixed everything. I really appreciate all your help. Perhaps you should consider uploading your modified version of the object to the object exchange?

    Thanks alot for all your help.

    -James
Sign In or Register to comment.