Multiptle Lines on a 1*16 LCD Basic Stamp 2



In this video you can see how to show more than one line of code, however this is not that easy to add, you have to create a set of codes each time you make a line. However I came up with a code that will make the code for you, the only thing you have to do is to write what you want and change the number of line. If you have 5 lines and want 6, type the 6th line and change the line number to 6, Here’s is how!

AT the end of the video, you will see how to connect the lcd to the Basic Stamp2, then download the code from the link or copy from here. The part you see DATA, that is the part you add lines, the letters inside ” ” should not go beyond 16 letters, and each line has it’s own DATA. If you want to add any line, just below the last DATA line add urs, simple as that. Last step is to go down until u see “‘!!!!!!!!!!This part!!!!!!!!!!!!!” in the comment parts, in the Main: and u will see it says IF a = 15, 15 is the number of lines u have in total, so if you have 3 lines, change this number to 3. You dnt have to do anything else! Let the BS2 do the rest! Good luck

BS2 code for download:

http://www.megaupload.com/?d=ZIQP29Y2

BS2 code to copy:

‘ $STAMP BS2
‘ $PBASIC 2.5
‘ File…… Parallel_LCD_1X16.bs2
‘ Purpose… Parallel LCD Display Demo
‘ Author…. Sepehr Zangeneh
‘ —–[ Program Description ]———————————————
‘ This program demonstrates using a Hitachi-compatible Parallel LCD Display
‘ This code works with the BS2, BS2e and BS2sx
‘ —–[ I/O Definitions ]————————————————-
E PIN 0 ‘ Enable Pin For LCD
RW PIN 2 ‘ R/W Pin For LCD
RS PIN 3 ‘ LCD Register Select
‘ 0 = Instruction, 1 = Text
‘ —–[ Variables ]——————————————————-

char VAR BYTE ‘ Character To Send To LCD
inst VAR char ‘ Induction To Send To LCD
index VAR WORD ‘ Character Pointer
temp VAR BYTE ‘ Temp Variable
x VAR BYTE ‘ Line Number
y VAR BYTE
z VAR BYTE
a VAR BYTE

a=0
x=0
y=15
z=8

‘ —–[ EEPROM Data ]—————————————————–

DATA “Hello YouTube! ”
DATA “This video shows”
DATA “How to display ”
DATA “more than one ”
DATA “line on a 1*16 ”
DATA “LCD without the ”
DATA “need of adding ”
DATA “extra codes!!! ”
DATA “You need: ”
DATA “Basic Stamp 2 ”
DATA “LCD (any brand) ”
DATA “A computer (DUH)”
DATA “the program is ”
DATA “Provided below ”
DATA “Enjoy!!!!! ”

‘ Message To Send To LCD
‘ —–[ Initialization ]————————————————–

Initialize:
LOW RW ‘ Set LCD To Write Mode
OUTS = %0000000000000000 ‘ Set All Output Low
DIRS = %0000000011111111 ‘ Set I/O Direction
GOSUB Init_Lcd ‘ Initialize The LCD Display
‘ —–[ Program Code ]—————————————————-
Main:

FOR temp = x TO y ‘ 28 Characters
IF temp = z THEN ‘ Check For End Of Line
GOSUB Next_Line ‘ Jump To Next Line
ENDIF
READ temp, char ‘ Read Next Character from EEProm
GOSUB Send_Text ‘ Send Character To LCD Display
NEXT
x=x+16
y=y+16
z=z+16
a=a+1

IF a = 15 THEN ‘!!!!!!!!!!This part!!!!!!!!!!!!!
STOP
ENDIF
GOTO Initialize

‘ —–[ Subroutines ]—————————————————–
Init_Lcd:
PAUSE 200
OUTS = %00110000 ‘ Reset The LCD
PULSOUT E,1 ‘ Send Command Three Times
PAUSE 10
PULSOUT E,1
PAUSE 10
PULSOUT E,1
PAUSE 10
OUTS = %00100000 ‘ Set To 4-bit Operation
PULSOUT E,1
Inst = %00101000 ‘ Function Set (2-Line Mode)
GOSUB Send_Inst
Inst = %00001110 ‘ Turn On Cursor
GOSUB Send_Inst
Inst = %00000110 ‘ Set Auto-Increment
GOSUB Send_Inst
Inst = %00000001 ‘ Clears LCD
GOSUB Send_Inst
Inst = 14 ‘ Set Cursor To Underline
GOSUB Send_Inst
RETURN

Send_Inst:
LOW RS ‘ Set Instruction Mode
OUTB = Inst.HIGHNIB ‘ Send High Nibble
PULSOUT E,1
OUTB = Inst.LOWNIB ‘ Send Low Nibble
PULSOUT E,1
HIGH RS ‘ Set LCD Back To Text Mode
RETURN

Send_Text:
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 ‘ Move Cursor To Line 2
GOSUB Send_Inst
RETURN

Send your message to us:

INQUIRY NOW
  • * CAPTCHA: Please select the Car


Post time: Jun-26-2017
WhatsApp Online Chat !