BS2 and parallel LCD source code
Jacek
Posts: 2
Hi,
couple days ago I searched for source code which would work with Basic Stamp 2 and (2x16)LCD in parallel mode
I have LCD based on Hitachi HD44780.
Here what I found and might be helpful for you.
nice link which helped me to make it work :
http://www.weethet.nl/english/basicstamp2_lcdcontrol.php
and here is sample of the source code which I wrote to display
TEST - in line 1
LCD - in line 2
' {$STAMP BS2}
' {$PBASIC 2.5}
'· parallel LCD control from BS2
'
'P0-P6 of BS2 corresponds to DB0-DB7 of LCD I/O bus lines
'P8 of BS2 is my RS line from LCD
'P9 of· BS2 is E line from LCD
'R/W line from LCD is grounded
char VAR Byte
index VAR Nib
InitializeSTAMP:
DIRL = %11111111 ' p7,p6,p5... p0· Outputs
DIRH = %00000011 ' p9,p9 Outputs
OUTH = %00000000 'clear ports 8-15
OUTL = %00000000 'clear ports 0-7
MSG1 DATA $54,$45,$53,$54 'TEST
MSG2 DATA $4c,$43,$44···· 'LCD
·LCDinit:········ PAUSE 200····· ' Wait for LCD init
················ char=%00111000 ' Set 8-bit mode (1)
················ GOSUB LCDcmd
················ PAUSE 5
················ char=%00111000 ' Set 8-bit mode (2)
················ GOSUB LCDcmd
················ PAUSE 0
················ char=%00111000 ' Set 8-bit mode (3)
················ GOSUB LCDcmd
················ char=%00111000 ' Set 8-bit mode (3)
················ GOSUB LCDcmd
················· char=%00001000 ' LCD OFF
················ GOSUB LCDcmd
················· char=%0000001 ' LCD CLEAR
················ GOSUB LCDcmd
PAUSE 5
················ char=%00000110 ' NO SHIFT
················ GOSUB LCDcmd
················ char=%00000010 ' CURSOR AT HOME POSITION
················ GOSUB LCDcmd
PAUSE 5
················ char=%00001111 ' Cursor On
················ GOSUB LCDcmd
················ char=%10000000 ' Cursor at LINE 1 , POSITON 1
················ GOSUB LCDcmd
Program:
FOR index = 0 TO 3
·················· READ Msg1 + index, char ' get character from memory
·················· GOSUB LCDwr··········· ' write it to the LCD
················ NEXT
SECOND_LINE:
char=$c0 ' 2,1 pos
GOSUB LCDcmd
FOR index = 0 TO 2
· READ Msg2 + index, char ' get character from memory
· GOSUB LCDwr··········· ' write it to the LCD
················ NEXT
char=%00001100 ' cursor off,blink off,display on
GOSUB LCDcmd
END
LCDcmd:·· LOW 8 ' enter command mode
LCDwr:· ' Write ASCII char to LCD
·· OUTL = char· ' output LOW BYTE P0-P7
·· PULSOUT 9, 1 ' output pulse to PORT9
·· HIGH 8······ ' return to character mode
·· RETURN
couple days ago I searched for source code which would work with Basic Stamp 2 and (2x16)LCD in parallel mode
I have LCD based on Hitachi HD44780.
Here what I found and might be helpful for you.
nice link which helped me to make it work :
http://www.weethet.nl/english/basicstamp2_lcdcontrol.php
and here is sample of the source code which I wrote to display
TEST - in line 1
LCD - in line 2
' {$STAMP BS2}
' {$PBASIC 2.5}
'· parallel LCD control from BS2
'
'P0-P6 of BS2 corresponds to DB0-DB7 of LCD I/O bus lines
'P8 of BS2 is my RS line from LCD
'P9 of· BS2 is E line from LCD
'R/W line from LCD is grounded
char VAR Byte
index VAR Nib
InitializeSTAMP:
DIRL = %11111111 ' p7,p6,p5... p0· Outputs
DIRH = %00000011 ' p9,p9 Outputs
OUTH = %00000000 'clear ports 8-15
OUTL = %00000000 'clear ports 0-7
MSG1 DATA $54,$45,$53,$54 'TEST
MSG2 DATA $4c,$43,$44···· 'LCD
·LCDinit:········ PAUSE 200····· ' Wait for LCD init
················ char=%00111000 ' Set 8-bit mode (1)
················ GOSUB LCDcmd
················ PAUSE 5
················ char=%00111000 ' Set 8-bit mode (2)
················ GOSUB LCDcmd
················ PAUSE 0
················ char=%00111000 ' Set 8-bit mode (3)
················ GOSUB LCDcmd
················ char=%00111000 ' Set 8-bit mode (3)
················ GOSUB LCDcmd
················· char=%00001000 ' LCD OFF
················ GOSUB LCDcmd
················· char=%0000001 ' LCD CLEAR
················ GOSUB LCDcmd
PAUSE 5
················ char=%00000110 ' NO SHIFT
················ GOSUB LCDcmd
················ char=%00000010 ' CURSOR AT HOME POSITION
················ GOSUB LCDcmd
PAUSE 5
················ char=%00001111 ' Cursor On
················ GOSUB LCDcmd
················ char=%10000000 ' Cursor at LINE 1 , POSITON 1
················ GOSUB LCDcmd
Program:
FOR index = 0 TO 3
·················· READ Msg1 + index, char ' get character from memory
·················· GOSUB LCDwr··········· ' write it to the LCD
················ NEXT
SECOND_LINE:
char=$c0 ' 2,1 pos
GOSUB LCDcmd
FOR index = 0 TO 2
· READ Msg2 + index, char ' get character from memory
· GOSUB LCDwr··········· ' write it to the LCD
················ NEXT
char=%00001100 ' cursor off,blink off,display on
GOSUB LCDcmd
END
LCDcmd:·· LOW 8 ' enter command mode
LCDwr:· ' Write ASCII char to LCD
·· OUTL = char· ' output LOW BYTE P0-P7
·· PULSOUT 9, 1 ' output pulse to PORT9
·· HIGH 8······ ' return to character mode
·· RETURN
Comments
·· We also have sample code for the various BASIC Stamp Modules for these displays at the following link, bottom of the page.
http://www.parallax.com/detail.asp?product_id=603-00006
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com