Shop OBEX P1 Docs P2 Docs Learn Events
Help with lcd — Parallax Forums

Help with lcd

JAMB1234JAMB1234 Posts: 8
edited 2008-10-19 17:36 in BASIC Stamp
I have a 2x16 backlit lcd I purchased from Parallax. I am familiar with the serout command and how to place it in my program to display text but I can't figure out where to place the DEC commands in the software in order to be able to control the lcd functions, Such as turning the display on and off and clearing the screen to make way for new text. Here is the software I am working with.

Thanks

'{$STAMP BS2}
'{$PBASIC 2.5}

timecounterA VAR······· Word·············· ' Time Score of player A
timecounterB VAR······· Word·············· ' Yime Score of Player B
TxPin CON 1
Baud19200 CON 32
DEBUG "Press and hold pushbuttons" , CR

DO
HIGH TxPin ' Set pin high to be a serial port
PAUSE 100 ' Pause for Serial LCD to initialize
SEROUT TxPin, Baud19200,[noparse][[/noparse] "Press and Hold Push Buttons" ]
·DO
·' Nothing
·LOOP UNTIL (IN3 = 1) AND (IN4 = 1)
HIGH 15
PAUSE 2000
HIGH 14
PAUSE 2000
HIGH 13
PAUSE 3000
HIGH 12
PAUSE 1000
LOW 15
LOW 13
LOW 14
LOW 12
HIGH 9
HIGH 10
HIGH 11
PAUSE 400
LOW 9
LOW 10
LOW 8
LOW 7
LOW 11
PAUSE 1

HIGH 8
HIGH 7
timecounterA = 0
timecounterB = 0
DO
PAUSE 1
IF (IN3 = 1) THEN
timecounterA = timecounterA + 1
ENDIF
IF (IN4 =1) THEN
timecounterB = timecounterB + 1
ENDIF
LOOP UNTIL (IN3 = 0) AND (IN4 = 0)
LOW 8
LOW 7
IF (timecounterA =0) THEN
DEBUG " Left Lane FOUL" , CR
DEBUG " Right Lane Wins" , CR, CR
HIGH 6
PAUSE 4000
LOW 6
ELSEIF (timecounterB = 0) THEN
DEBUG "· Right Lane FOUL" , CR
DEBUG·· "Left Land Wins" , CR
HIGH 5
PAUSE 4000
LOW 5
ELSE
DEBUG "Left Lane time: ", DEC timecounterA/265,".",DEC2 timecounterA//1000,CR
DEBUG "Right Lane time: ", DEC timecounterB/265,".",DEC2 timecounterB//1000, CR, CR
IF (timecounterA < timecounterB) THEN
··· DEBUG "Left Lane is the winner!", CR
HIGH 15
PAUSE 2000
LOW 15
ELSEIF (timecounterB < timecounterA) THEN
DEBUG "Right Lane is the winner!", CR
HIGH 14
PAUSE 2000
LOW 14
ELSE
DEBUG "It's a Tie!", CR
ENDIF
DEBUG CR
DEBUG "To play again, Hold the", CR
DEBUG "BUTTONS DOWN AGAIN.",CR, CR
SEROUT TxPin, Baud19200,[noparse][[/noparse] "Buttons Down Again" ]
ENDIF
LOOP

Comments

  • Bruce BatesBruce Bates Posts: 3,045
    edited 2008-10-19 15:54
    JAMB1234 -

    The web page where you purchased the LCD has documentation for it as well as sample programs for the BS-1 and BS-2. Here is a link to that web page:
    http://www.parallax.com/Store/Accessories/Displays/tabid/159/CategoryID/34/List/0/Level/a/ProductID/50/Default.aspx?SortField=ProductName,ProductName

    If that documentation doesn't give you the answers you're seeking, just shout back.

    Regards,

    Bruce Bates

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    When all else fails, try inserting a new battery.
  • FranklinFranklin Posts: 4,747
    edited 2008-10-19 15:55
    Have you looked at the sample code you can download from Parallax?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • RDL2004RDL2004 Posts: 2,554
    edited 2008-10-19 15:59
    The Parallax LCD is pretty simple actually. It displays whatever you send to it using SEROUT.

    It displays it in the order received, automatically wrapping lines and over-writing when it does.

    If this isn't what you want, then it is up to you to specify exactly where to place the text and where to clear text.

    Don't use the DEC formatter, just send the command as the actual number in brackets [noparse][[/noparse]##]

    Here is an old program I dug up that may help.

    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    
    
    DEBUG "PROGRAM RUNNING..."
    DEBUG CR, "Starting LCD Display"
    
    counter VAR Word
    
    TxPin     CON   8            'set transfer pin to LCD as pin 8, change as needed
    Baud19200 CON   32           'set baud rate as 19200 (serout 32)
    
      HIGH TxPin
      PAUSE 100
    
      SEROUT TxPin, Baud19200, [noparse][[/noparse]12] 'formfeed, move to 0,0 and clear display
      PAUSE 500
      SEROUT TxPin, Baud19200, [noparse][[/noparse]17] 'backlight on
      PAUSE 500
      SEROUT TxPin, Baud19200, [noparse][[/noparse]"LCD Display"]
      SEROUT TxPin, Baud19200, [noparse][[/noparse]13] 'carriage return, move to next line, position 0
      SEROUT TxPin, Baud19200, [noparse][[/noparse]"Initialized"]
      PAUSE 800
    
    
      SEROUT TxPin, Baud19200, [noparse][[/noparse]12] 'formfeed, move to 0,0 and clear display
      PAUSE 50
      SEROUT TxPin, Baud19200, [noparse][[/noparse]"Flashing light"]
      SEROUT TxPin, Baud19200, [noparse][[/noparse]13] 'carriage return, move to next line, position 0
      SEROUT TxPin, Baud19200, [noparse][[/noparse]"on LCD display"]
      PAUSE 500
    
    FOR counter = 1 TO 10
      SEROUT TxPin, Baud19200, [noparse][[/noparse]18] 'backlight off
      PAUSE 500
      SEROUT TxPin, Baud19200, [noparse][[/noparse]17] 'backlight on
      PAUSE 500
    
      NEXT
    
      SEROUT TxPin, Baud19200, [noparse][[/noparse]12] 'formfeed, move to 0,0 and clear display
      PAUSE 50
      SEROUT TxPin, Baud19200, [noparse][[/noparse]"Changing"]
      SEROUT TxPin, Baud19200, [noparse][[/noparse]13] 'carriage return, move to next line, position 0
      SEROUT TxPin, Baud19200, [noparse][[/noparse]"flash rate"]
      PAUSE 1000
    
    
      SEROUT TxPin, Baud19200, [noparse][[/noparse]12] 'formfeed, move to 0,0 and clear display
      PAUSE 100
      SEROUT TxPin, Baud19200, [noparse][[/noparse]"Running light"]
      SEROUT TxPin, Baud19200, [noparse][[/noparse]13] 'carriage return, move to next line, position 0
      SEROUT TxPin, Baud19200, [noparse][[/noparse]"flash (loop)"]
      PAUSE 500
    
    
      DO
    
        SEROUT TxPin, Baud19200, [noparse][[/noparse]18] 'backlight off
        PAUSE 500
    
        SEROUT TxPin, Baud19200, [noparse][[/noparse]17] 'backlight on
        PAUSE 8000
    
        SEROUT TxPin, Baud19200, [noparse][[/noparse]18] 'backlight off
        PAUSE 500
    
        SEROUT TxPin, Baud19200, [noparse][[/noparse]17] 'backlight on
        PAUSE 500
      LOOP
    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Rick
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2008-10-19 16:00
    Hi, download the pdf file on the LCD product page at this link http://www.parallax.com/Portals/0/Downloads/docs/prod/audiovis/SerialLCD-v2.0.pdf

    on page 8 is the command set for control of the LCD, if you assign your commands to a constant at the beginning of the program things will be easier to follow as you code.

    For example to turn the LCD on there are 4 options, if you want cursor on and no blink the command is DEC 24 or HEX 18. From the example Parallax code the constant is defined LcdOn3 CON $18 to implement the command then somewhere at the start of your program you would use the instruction SEROUT tx,baud,[noparse][[/noparse]LcdOn3]

    The same for clearing the screen the Parallax constant is LcdCls CON $0C the instruction being SEROUT tx,baud,[noparse][[/noparse]LcdCls].

    One important thing is to be aware of how many characters you are sending to the display and where on the display that places the cursor, it is quite easy to overwrite existing text or go out of bounds if you dont keep track

    Jeff T.
  • RDL2004RDL2004 Posts: 2,554
    edited 2008-10-19 16:35
    Yes, once you understand that the LCD changes nothing until it's overwritten or the power is turned off, it becomes less confusing.
    For example, if you send [noparse][[/noparse]"Initializing"], you see:

    Initializing

    Then put the cursor back to the start of the line and send [noparse][[/noparse]"Okay"], what you will see is:

    Okayializing

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Rick
  • JAMB1234JAMB1234 Posts: 8
    edited 2008-10-19 17:36
    Thanks to you all. I was trying to use the dec formatter. I placed the command in brackets and got the results I wanted. Thank God for this forum.
Sign In or Register to comment.