Shop OBEX P1 Docs P2 Docs Learn Events
how to program the lcd to show 2 diff message?(basic stamp 2) — Parallax Forums

how to program the lcd to show 2 diff message?(basic stamp 2)

tinytiny Posts: 3
edited 2008-07-08 05:55 in BASIC Stamp
i jus started using basic stamp 2 and i'm kind of bad at programming it, appreciate it if anyone could help me tongue.gif

i found this example code online to program the LCD to show the message, but i want it to show another message after showing the first, does anybody know how to?

'{$STAMP BS2}
'************************************************************************
'* Title: 2X16Parallel_lcd.bs2
'* This code will work for the stamp2, stamp 2e and stamp 2sx
'*************************************************************************
'Setup for program symbols
E CON 0 'Enable pin for LCD
Rs CON 3 'LCD Register select pin, 0 = instruction, 1 = text
Char VAR Byte 'Character to send to LCD
Inst VAR Char 'Induction to send to LCD. (Points to Char)
Index VAR Word 'Character pointer
temp VAR Byte
RW CON 2
'**************************************************************************
'************************Main program**************************************
'**************************************************************************
'Setup stamp pins

Initialize:
LOW rw
OUTS = %0000000000000000
DIRS = %0000000011111111
DATA "Welcome aboard the bus! ^_^"
GOSUB Initlcd

Main:
FOR temp = 0 TO 26
IF temp = 15 THEN next_line
out:
READ temp,char
GOSUB Sendtext
NEXT
STOP
'Initialize the LCD

Initlcd:
PAUSE 200
OUTS = %00110000 'Wakeup for the LCD
PULSOUT E,1 ' Send command three times with required delays
PAUSE 10
PULSOUT E,1
PAUSE 1
PULSOUT E,1
PAUSE 1
OUTS = %00100000 'Set to 4-bit operation
PULSOUT E,1
Inst = %00101000 'setup the LCD for two line display
GOSUB Sendinst
Inst = %00001110 'Turns on cursor
GOSUB Sendinst
Inst = %00000110 'Set to auto-increment cursor and on display shift
GOSUB Sendinst
Inst = %00000001 'Clears LCD
GOSUB Sendinst
Inst = 14 'Turns cursor to underline
GOSUB Sendinst
RETURN
'Send an instruction to LCD

Sendinst:
LOW Rs 'sets instruction mode
OUTB = Inst.HIGHNIB 'Send high nibble
PULSOUT E,1
OUTB = Inst.LOWNIB 'Send low nibble
PULSOUT E,1
HIGH Rs ' Sets LCD back to text mode
RETURN
'Send text to LCD

Sendtext:
OUTB = Char.HIGHNIB 'Send high nibble
PULSOUT E,1
OUTB = char.LOWNIB 'Send low nibble
PULSOUT E,1
PAUSE 100
RETURN

Next_line:
Inst = 128+64 'Send cursor to line 2
GOSUB Sendinst
GOTO out

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-07-07 13:32
    "Does anyone know how to?"

    I can figure it out after looking at this code. You can too.

    The part to concentrate on is the DATA statement and the section between the "Main:" label and the "Initlcd: label.
    The subroutine "Sendtext" takes the value of the variable "char" and sends it to the LCD. "Next_line" isn't really a
    subroutine. It's just an out-of-line part of the main loop that moves the cursor to line 2. The subroutine "Sendinst"
    takes the value of the variable "Inst" and sends it to the LCD as a command rather than a character for display.

    We're now talking about a total of 12 lines of PBasic code to look at, copy them to a piece of paper, sit down with the
    Parallax Stamp Basic Manual and look at the description of all the statements, particularly READ and DATA, then come
    back and make a proposal here (posting your code) for how to display a 2nd message based on these 12 lines of code.
    We'd be happy to give advice and make suggestions.
  • tinytiny Posts: 3
    edited 2008-07-08 00:36
    i know its easy to do it...but my dumb brain just can't get it cry.gif ....i've been trying for a week already, and all i managed was to get it to display 2 things at a time without clearing the screen before displaying the second thing....thanks for your advice i'll try to look at it again...
  • Mike GreenMike Green Posts: 23,101
    edited 2008-07-08 00:54
    Try this.

    1) Take the DATA statement and duplicate it (make two identical copies, one after the other).

    2) Take the FOR loop (everything between the FOR statement and the NEXT statement) in the Main section.
    Duplicate that and place the duplicate after the original NEXT statement.
    Take the piece between Next_line: and GOTO and duplicate that.
    Change the Next_line to Next_line2 and change the GOTO out to GOTO out2
    In the duplicate loop, change the out: to out2:
    In the duplicate loop, change the THEN Next_line to THEN Next_line2

    3) Put a PAUSE 3000 between the original NEXT statement and the duplicate FOR statement.

    4) In the duplicate FOR statement, change the numbers from "0 TO 26" to "27 TO 52"

    5) Try the result.

    6) Change one of the DATA statements.· Don't shorten the number of characters.· Try again.


    Post Edited (Mike Green) : 7/8/2008 1:00:22 AM GMT
  • tinytiny Posts: 3
    edited 2008-07-08 05:55
    ooo...i tried it and it worked
    (though i need to add the command to clear the screen before the new for loop*just figured out how to clear the screentongue.gif *)

    thanks alot~lol.gif
Sign In or Register to comment.