Shop OBEX P1 Docs P2 Docs Learn Events
4-bit Parallel LCD drive — Parallax Forums

4-bit Parallel LCD drive

gregfoxgregfox Posts: 68
edited 2014-02-06 13:42 in Propeller 1
Hi, I’m using Chris Gadd 4-bit Parallel LCD driver, and I was wondering if anyone knows of a 4-bit Parallel LCD driver (2 or 4 rows HD44780 ) written in C for the propeller? I would like to write one in C, but I need a bit more experience. I could learn a lot by just reading the code.
I know a bit of spin (enough to be dangerous), but spin is native to propeller, and I don’t want to be tied to any one micro. C is mostly transportable to other chips; therefore I want to stick to C. The propeller is mostly superior to any other chip in its price range. I wish they went right to C, instead of spin.
Thanks!
«1

Comments

  • MagIO2MagIO2 Posts: 2,243
    edited 2014-01-21 01:10
    Are you sure that C is not tied to a micro? Then you could simply use any C implementation for a 4-bit parallel LCD and run it on the propeller!

    I doubt that.

    If you have a free COG you could use my PASM LCD driver. Just some small wrapper C functions and it should be usable - did that for basic a while ago. ( http://obex.parallax.com/object/270 )
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2014-01-21 02:23
    If you want to write your own in C, it is not a big task and Parallax a couple of version of C -- Catalina and GCC.

    The main thing is that you need to insert time delays to allow the LCD time to properly respond. Most of the time delays (the longest ones are in the initialization portion of the code). The rest is rather easy.

    By looking at the documentation for the LCD and an example for the BasicStamp2, I am pretty sure you can come up with good code in C.
  • gregfoxgregfox Posts: 68
    edited 2014-01-21 10:26
    Thanks, I'll take a look at you PASM LCD Driver! On another note, you're right, a program written in C for one chip, would need some changes to run on another. C can run on almost any micro, while spin only runs on Propeller. Don't get me wrong, I like spin, but it's tied to Propeller, and Propeller only. I may produce a commercial product (with a little help), and for sure I'll use Propeller. I love the chip. Having said that, a good designer should use the correct micro for the job, for instance, you wouldn't use a Propeller to simply interface a rotary encoder, you would use the cheapest smallest micro you could find... get my drift. In any case thank you for your PASM LCD driver, I appreciate it.

    I do have a question, I set my base pin to 12 (DB4=12/DB5=13/DB6=14/DB7=15),and BLC set to 8. the back-light comes on but no text. (not the contrast as I ran this with other drivers. What could I check?
  • JonnyMacJonnyMac Posts: 9,107
    edited 2014-01-21 11:23
    MagIO2s PASM driver is quite nice, but it may be simpler to port a Spin driver to C. I do a lot of work with LCDs (in commercial products using Spin) -- here's my four-bit code that includes the use of the busy flag to expedite output to the display.

    -- http://obex.parallax.com/object/313
  • gregfoxgregfox Posts: 68
    edited 2014-01-21 13:54
    Many thanks, I'll give it a go!
  • gregfoxgregfox Posts: 68
    edited 2014-01-21 15:23
    Well works really well, I couldn't see the characters and could not get the back-light to glow, so I added "dira[8]~~ outa[8]~~ ", and it lite OK, but I'm sure that's not the correct way to light it. How do I light it without hacking the code?
  • JonnyMacJonnyMac Posts: 9,107
    edited 2014-01-21 22:44
    I'm not sure what's going on but I did notice the version on my system is newer than what is in ObEx (I'll correct that later). See if the updated version works for you. As long as you're defining a backlight pin you should have control over it.
  • gregfoxgregfox Posts: 68
    edited 2014-01-22 11:39
    Hmmmm. still the same, I have to add dira[8] := outa[8] := 1 to get the back-light to go on...
  • JonnyMacJonnyMac Posts: 9,107
    edited 2014-01-22 11:43
    I think something is amiss on your end, though I can't point it out without seeing your hardware and implementation. I am using this code in a commercial project that includes back-light control and it works just fine.
  • gregfoxgregfox Posts: 68
    edited 2014-01-22 13:28
    You mean, the nut behind the wheel,,, me? Can't be. Well maybe... I have the LCD a 1602A connected to a propeller board.
    BLC - pin 8
    E - 9
    RW - 10
    RS - 11
    DB4 -12
    DB6 - 13 etc.
    I have the Anode of the lcd connected to +5V and the Cathode to the collector of a 2N3904 with a grounded emitter.
    If I send dira[8] := outa[8] := 1 with nothing else in the program, pin 8 goes high, and the back-light goes on.
    I know it must be me, but I'm stuck.
  • JonnyMacJonnyMac Posts: 9,107
    edited 2014-01-22 14:08
    Let me ask... how were you trying to control it with the driver that DIDN'T work?

    In the startx() method paramater blpin is copied to object variable bl.

    The backlight method makes the pin output and high if a non-zero (true) value is passed in state. If you pass 0 (false) the pin driver is released. I do this so you can PWM the backlight with another cog if desired.

    New version -- see attached.
    pub backlight(state)
    
    '' Turn backlight control pin on
    '' -- forces bl pin to output state when on or off
    
      if (bl => 0)                                                  ' if used
        case state
          1:
            high(bl)                                                ' on
    
          0:
            low(bl)                                                 ' off
    
          other:                                                    ' float for external control
            input(bl)
    


    I just tried it on a PPDB and the blacklight() method is working -- without any extra hacks.

    As I'm working on a project with an LCD at the moment I went through and reconciled a couple method calls and the x/y addressing with another driver. The attached demo toggles the backlight on and off.
  • Cluso99Cluso99 Posts: 18,069
    edited 2014-01-22 15:18
    gregfox wrote: »
    Thanks, I'll take a look at you PASM LCD Driver! On another note, you're right, a program written in C for one chip, would need some changes to run on another. C can run on almost any micro, while spin only runs on Propeller. Don't get me wrong, I like spin, but it's tied to Propeller, and Propeller only. I may produce a commercial product (with a little help), and for sure I'll use Propeller. I love the chip. Having said that, a good designer should use the correct micro for the job, for instance, you wouldn't use a Propeller to simply interface a rotary encoder, you would use the cheapest smallest micro you could find... get my drift....

    Actually, I use a 3 prop chip solution in a commercial product. I could have used other cheaper micros in all 3 places, but they would all be different micros. Now I have a common set of parts. Although more expensive, the software is simpler, and my inventory is lower. It all depends on what you are after ;)
  • gregfoxgregfox Posts: 68
    edited 2014-01-23 08:52
    Well how strange, When I run your jm_lcd4_ez_demo.spin the backlight blinks on and off for about 6 seconds, but no characters are displayed. All I did was download you code, plugged in my LCD_D4 = 12, LCD_RS = 11, LCD_RW = 10, LCD_E = 9, LCD_BL = 8 and ran it from Simple IDE. Are there parameters I should set?
    Thank you for your time, I really appreciate your efforts!
  • gregfoxgregfox Posts: 68
    edited 2014-01-23 08:52
    Well how strange, When I run your jm_lcd4_ez_demo.spin the backlight blinks on and off for about 6 seconds, but no characters are displayed. All I did was download you code, plugged in my LCD_D4 = 12, LCD_RS = 11, LCD_RW = 10, LCD_E = 9, LCD_BL = 8 and ran it from Simple IDE. Are there parameters I should set?
    Thank you for your time, I really appreciate your efforts!
  • gregfoxgregfox Posts: 68
    edited 2014-01-23 08:58
    The prop is a great chip, without question, but surely if you were designing something simple, and say, you needed a micro to JUST do something simple, like light a LED or work an encoder, you would choose some like a tiny for $1.50, and not an $8.00 Propeller. That would be like shooting an ant with a cruse missile.:-)
  • JonnyMacJonnyMac Posts: 9,107
    edited 2014-01-23 12:13
    gregfox wrote: »
    Well how strange, When I run your jm_lcd4_ez_demo.spin the backlight blinks on and off for about 6 seconds, but no characters are displayed. All I did was download you code, plugged in my LCD_D4 = 12, LCD_RS = 11, LCD_RW = 10, LCD_E = 9, LCD_BL = 8 and ran it from Simple IDE. Are there parameters I should set?
    Thank you for your time, I really appreciate your efforts!

    I'm working on a project on a PDB right this second and all is well. I like to pull-down the E pin to ground via 10K. Make sure that you haven't swapped the RS and RW lines in your setup.
  • gregfoxgregfox Posts: 68
    edited 2014-01-24 18:35
    Checked all my connections, and they are all correct. I don't know if I was clear as to what happens, but when I run the demo, I could barley make out the characters, but they are there. If I hack it, the back-light comes on and all is well. I looked at the code and don't see why the bl is not turning on.
    Confused.
  • JonnyMacJonnyMac Posts: 9,107
    edited 2014-01-24 19:56
    I am too; that code is running on my desk (PPDB), and in this product:

    -- http://www.cameraturret.com/genesis.htm

    If you can barely see the characters then you have a problem with the contrast input. Check the LCD -- you want to make sure you don't have one that requires a negative contrast voltage. You normally connect the tap of a 10K pot to the contrast input; the ends of the pot connect between 5v and ground. Adjust for best contrast.
  • gregfoxgregfox Posts: 68
    edited 2014-01-25 11:28
    Hi, the LED I'm using is a "Blue Transflective" type of LCD, If I replace it with a Reflective LCD I can see it clearly without a back-light. This Transflective LCD can be seen if there is enough light but is super with a back-light.
    Even using a different LCD (Reflective) the back-light doesn't come on without a hack.
    It's hard to understand because looking at you code if anything above a "0" is inserted for bl it should turn on. ARGGGG.
  • JonnyMacJonnyMac Posts: 9,107
    edited 2014-01-25 11:46
    My latest post changes the backlight() method to accept 1 (on), 0 (off), -1 (float control line). I added the last bit so that I can use an external PWM signal to control th backlight brightness.

    Just for giggles, try a different pin (if the hardware allows), or connect a simple LED circuit to see if you do in fact have control.
  • gregfoxgregfox Posts: 68
    edited 2014-01-25 12:50
    As II'm really a hardware guy, I tested the pin(s) with a scope, and all is well, I even changed out the LCD...same. Where can I download your latest? OBEX?
  • JonnyMacJonnyMac Posts: 9,107
    edited 2014-01-25 14:28
    Here's another object you might try; this is what I use in my projects. It's the same essential LCD code with these differences:

    1) It's write-only; the RW line the LCD is not controlled (tie it to ground)
    2) The LCD data buss (4 pins) and 2 other pins may be used as inputs

    For projects that need a four-bit LCD and up to four buttons, you only need six IO pins. In the image is an LCD on a PDB running this object (Laser-tag controller). The controller requires three buttons which means that with this object I don't have to define separate IO pins. The read_btns() method sets the buss pins to inputs, the (private) write() method restores them to outputs. There is documentation in the file that shows how to share the LCD buss pins with buttons and not have any problems (old trick from Scott Edwards).

    If you want to check just one of the shared buss lines, please use code like this:
    pub input(pin)
    
    '' Makes pin input and returns current state
    
      dira[pin] := 0
    
      return ina[pin]
    


    Again, you can do this because the next time you write to the LCD the buss dira bits will be restored.
    800 x 533 - 638K
  • gregfoxgregfox Posts: 68
    edited 2014-01-26 06:09
    Really great code, you sure know your LCDs! Alas, Still no back-light. I'm going to rip down my rig and start from the bottom with a new board, and LCD I just ordered. I'll check back in a week when I receive them.
    Question I used you old jm_lcd4_ez_demo.spin as the top object correct?
    STOP THE PRESS----I forgot to change lcd : "jm_lcd_hmi_ez" to lcd : "jm_lcd_hmi. in jm_lcd4_ez_demo
    When I made the change it error-ed out with:

    Project Directory: C:/GREG/Parallax/High-performance 4-bit LCD driver/JM_LCD_HMI/

    openspin.exe -I C:/Program Files (x86)/SimpleIDE/bin/../propeller-gcc/spin/ jm_lcd4_ez_demo.spin
    Propeller Spin/PASM Compiler 'OpenSpin' (c)2012-2013 Parallax Inc. DBA Parallax Semiconductor.
    Compiled on Nov 7 2013
    Compiling...
    jm_lcd4_ez_demo.spin
    |-jm_lcd_hmi.spin
    jm_lcd4_ez_demo.spin(54:31) : error : Expected ")"
    Line:
    lcd.start(1, LCD_E, LCD_COLS, LCD_ROWS) ' bl on P16, 16x2 LCD

    Again, thank you for your time.
  • Toby SeckshundToby Seckshund Posts: 2,027
    edited 2014-01-26 08:31
    Just a guess / question -

    Is the LCD module a 3.3 Volt friendly ? ie not a 5 Volt one.

    Alan
  • JonnyMacJonnyMac Posts: 9,107
    edited 2014-01-26 09:25
    Question I used you old jm_lcd4_ez_demo.spin as the top object correct?

    Yes -- I tend to provide demos for my objects with a "_demo.spin" ending

    The others (without _demo) are child objects. For example, in my laser tag program I have an object called hmi defined like this:
    obj
    
      hmi    : "jm_lcd_hmi"
    


    Then I instatiate it like this:
    pub setup
    
    '' Configure objects and IO
    
      hmi.startx(LCD_BL, LCD_E, LCD_RS, LCD_D4, -1, -1, %000111)
    


    In this case you can see that I'm only using three of the six possible buttons supported by the object code.

    Once you get re-connected start with a very simple demo.
  • gregfoxgregfox Posts: 68
    edited 2014-01-26 11:20
    Attached is the data sheet for the LCD. I have it connected to 5VDC and am using it through a Gadget Gangster LCD UI also attached. The LCD is not the best but looks great with the back-light.
    Thanks.
  • JonnyMacJonnyMac Posts: 9,107
    edited 2014-01-26 13:04
    As it happens, I designed the Gadget Gangster LCD UI. Yes, I am the artist formerly known as Jon Williams (I now prefer to use my professional name in all aspects of my life).

    Double-check the LCD -- note that the extended temperature range models require a different bias setup.
  • gregfoxgregfox Posts: 68
    edited 2014-01-26 14:06
    Well how do you like that, very nice board Jonny Mac! So what ever happened to Gadget Gangster, they used to have pretty nice stuff. I liked the Propeller Platform so much; I designed a board for myself. The PC board only cost $1.50 (see Elecrow)
    The LCD is not an extended temperature unit. I plugged in the 16x2 in place of the 8x2, and checked all the connections twice. As I mentioned everything works great except the BL (even on the 8x2).
    On another note I’ll be out of town for 5 days, and hope to take up where we left off.
    Cheers!
  • JonnyMacJonnyMac Posts: 9,107
    edited 2014-01-26 14:52
    Double-check the components in the transistor circuit that controls the backlight.
  • gregfoxgregfox Posts: 68
    edited 2014-01-26 17:46
    Jonny, remember if I set pin 8 high, the backlight comes on, so the NPN is working correctly.
    Gone for 5.
    G.
Sign In or Register to comment.