how to program the lcd to show 2 diff message?(basic stamp 2)
tiny
Posts: 3
i jus started using basic stamp 2 and i'm kind of bad at programming it, appreciate it if anyone could help me
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
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
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.
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
(though i need to add the command to clear the screen before the new for loop*just figured out how to clear the screen *)
thanks alot~