Shop OBEX P1 Docs P2 Docs Learn Events
HELP! first SX project — Parallax Forums

HELP! first SX project

illuzionilluzion Posts: 9
edited 2009-04-11 00:38 in General Discussion
I am new to the SX, plently of PBASIC experience, I'm trying to drive a HD44780 LCD in 4bit mode, can anyone tell me why this doesn't work???· I've tried all kinds of playing with timing, I can't figure out what is wrong, There are two problems in this code, #1 is a LOOKUP function that I am used to in pbasic for convertering an ASCII string that doesn't seem to work right in SX/B.· Normal syntax I would use in pbasic is LOOKUP loopctr,[noparse][[/noparse]"I WANT TO DISLPAY THIS"],char to break up the string, does not work in sx/b.· The next problem is much more serious, even if I hard code ascii values, I cannot get anything to dislplay on the LCD.· I am using an SX48.· I tried example code for the SX28, and could not get that to work either.· From an SX/B standpoint, should the processor make a difference (other than I/O)?

Please help!
thanks

Comments

  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2009-04-09 19:02
    Change your mainloop to

    Main:
      DELAY_MS 25     'Wait for LCD to auto reset
      LCD_CMD LcdCls
      DELAY_MS 25     ' for effect
      LCD_CMD LcdHome
      DELAY_MS 25
    

      idx = 0
      do
        readinc myText + idx, char
        if char = 0 then 
          exit
        endif
        LCD_Out char
        WATCH char
        WATCH idx
        BREAK
      loop
     
    Main2:
      GOTO Main2
    

    myText:
    data "PLEASE HELP ME",0
    

    The do-loop reads the characters until a zero is encountered.

    regards peter
  • illuzionilluzion Posts: 9
    edited 2009-04-09 19:59
    I still have the same problem of no LCD display. Does anyone have a platform they can run this on and see if you get any display?
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2009-04-10 01:56
    I know that·my adaptation of the BS2 LCD demo·[noparse][[/noparse]here] works right.
  • illuzionilluzion Posts: 9
    edited 2009-04-10 02:44
    Okie.· I got the LCD to work finally.· Now one more question.· How do I display an explicit string (not a variable) on the LCD.· In PBASIC, I would use a command like:
    LOOKUP idx,[noparse][[/noparse]"THIS IS THE TEXT FOR LINE 1"],char
    with a for loop corresponding to the length of the character array running around it, but something is SX/B does not like the syntax of a character array constant, any ideas?
    ·
  • ZootZoot Posts: 2,227
    edited 2009-04-10 05:25
    Time to hit the docs -- see the help file for READ and READINC. Note that strings can be data, zero terminated, and then it's easy to read them character by character. You can also do "inline" text strings, but DATA is probably better as it's perhaps more clear what's happening (in the case of inline strings, it's actually just like "READing DATA" except the data address is not explicit; it is the SX flash memory address of the first character of the "embedded" string; in the generated assembly the READs are basically identical).

    P.S. -- I might argue that using DATA and READ on a Stamp is also a better approach than using LOOKUP.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    When the going gets weird, the weird turn pro. -- HST

    1uffakind.com/robots/povBitMapBuilder.php
    1uffakind.com/robots/resistorLadder.php
  • JonnyMacJonnyMac Posts: 9,412
    edited 2009-04-10 14:16
    Time to read the listing! I wrote that code and it has a subroutine called LCD_STR that is designed to print strings.

    All you have to do is move the cursor to the starting position of the string and then:

    LCD_STR "This is a string"

    or

    LCD_STR SomeLabel

    ... where SomeLabel is a z-string in a DATA statement. Had you taken two minutes to study the listing you would have seen all this -- and the demo from which you liberated this code showed the strings in action. Oi....
  • illuzionilluzion Posts: 9
    edited 2009-04-11 00:38
    JonnyMac, you are 100% right, the answer was literally right in front of me.

    Here's the story, I first started with code I wrote based on how I always used to do it on a BS2.· It didn't work, display would not even initalize, no cursor, nothing.· I literally spent a day on this using a logic analyzer and comparing timing against datasheets, I was stumped.· I then started downloading other 'example' code and tried every one I could find, I liked the way the subroutines were written (better than mine) the best in the one that had the LCD_STR, so I started adapting those.· But I still couldn't get the display to work.· It wasn't until after spending almost a full day on this that I figured out the problem, I was using a "special" HD44780 (futaba VFD) display that could be configured to work as serial or parallel, the jumpers on the display were set for serial [noparse]:)[/noparse].· My bad.· After fixing that, all the programs (including mine) worked to some extent.· I am still having a really tough time getting through the differences between PBASIC and SX/B though.

    Thanks for all your help, and thanks for some great sample code.
Sign In or Register to comment.