Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

scrolling text on LCD using SFbasic

Status
Not open for further replies.

MrDEB

Well-Known Member
not great but it works
// halloween costume scrolling message


DEVICE = 18F2420
CLOCK = 20

// some LCD options...
#option LCD_DATA = PORTB.4
#option LCD_RS = PORTB.2
#option LCD_EN = PORTB.3
DIM x AS BYTE

// import LCD library...
INCLUDE "LCD.bas"
INCLUDE "utils.bas"

// program start...
SetAllDigital
lcd.cls
DELAYMS(200) // warm up LCD

while true
FOR x = 0 TO 20
WriteAt(1,x,"Hello Sue")
DELAYMS(500)
lcd.cls // clear lcd display
NEXT
FOR x = 0 TO 20

WriteAt(2,x,"how are you")
DELAYMS(500)
lcd.cls
NEXT
wend
 
Your code the second next loop mess gets messed up and messes up the first.
You need the words in a array.
you then call X and show it but you need two arrays
 
I will look at adding the arrays.
I went in a different direction as I needed to multitask three different events ,all going at same time and using the scrolling text seemed to really mess this up. Took to long to scroll the text and still be able to read it.
Will clean up my working code and post but want to revisit the scrolling text. One suggestion was put the words in and array but need to do some research on arrays.
 
cleaned up and yes it is pretty basic nothing fancy. after Monday's party I want to tweek the scrolling text. As I have the code written it has just non scrolling text. Easier to read.
// halloween costume 2


DEVICE = 18F4520
CLOCK = 8

// sOME LCD OPTIONS...
#option LCD_DATA = PORTB.4
#option LCD_RS = PORTB.2
#option LCD_EN = PORTB.3

// IMPORT LCD LIBRARY...
INCLUDE "LCD.bas"
INCLUDE "utils.bas"
INCLUDE "InternalOscillator.bas"


DIM LED1 AS PORTA.0 //eyes
DIM LED2 AS PORTA.1 //eyes
DIM mask0 AS PORTC.0
DIM mask1 AS PORTc.1
DIM mask2 AS PORTC.2
DIM hose0 AS PORTD.2
DIM hose1 AS PORTD.3
DIM hose2 AS PORTc.4
DIM hose3 AS PORTc.5
DIM hose4 AS PORTc.6
DIM hose5 AS PORTc.7
DIM hose6 AS PORTd.4
DIM hose7 AS PORTd.5

// subroutine

SUB eyes()
DIM x AS BYTE
FOR x = 0 TO 200
LOW(LED1)
HIGH (LED2)
DELAYMS(30)
TOGGLE (LED1)
TOGGLE (LED2)
DELAYMS(20)
x = x +1
IF x >= 200
THEN END IF
NEXT
END SUB

sub mask_hose ()
mask0 =1
hose0 =0
hose1 =1
hose2 =0
hose3 =1
hose4=0
hose5=1
hose6=0
hose7=1
DELAYMS(50)
TOGGLE (mask0) // I need to use port bits here
TOGGLE (hose1) // in a for next loop
DELAYMS(50) // use a random number
TOGGLE (mask1)
TOGGLE (hose2)
DELAYMS(50)
TOGGLE (mask2)
TOGGLE (hose3)
DELAYMS(50)
TOGGLE (mask0)
TOGGLE (hose4)
DELAYMS(50)
TOGGLE (mask0)
TOGGLE (hose5)
DELAYMS(50)
TOGGLE (mask1)
TOGGLE (hose5)
DELAYMS(50)
TOGGLE (mask2)
TOGGLE (hose6)
DELAYMS(50)
TOGGLE (mask2)
TOGGLE (hose7)
end sub



// PROGRAM START...
SetAllDigital
lcd.cls
DELAYMS(200) // warm up LCD
TrisA=%000000 // set port A as outputs (the eyes)
WHILE true
mask_hose ()
WriteAt(1,1,"GRETTINGS")
WriteAt(2,1," EARTHLING")
eyes()
DELAYMS(80)
lcd.cls // clear lcd display
mask_hose ()
WriteAt(1,1,"I have ")
WriteAt(2,1," landed ")
eyes()
DELAYMS(80)
lcd.cls
mask_hose ()
WriteAt(1,1,"to collect")
eyes()
DELAYMS(90)
lcd.cls
mask_hose () // clear lcd display

WriteAt(1,1,"EARTHLING")
WriteAt(2,1," SPECIMENS")
eyes()
DELAYMS(80)
mask_hose ()
lcd.cls
WriteAt(1,1,"are you a")
WriteAt(2,1,"WILLING")
eyes()
DELAYMS(80)
mask_hose ()
lcd.cls
WriteAt(1,1,"SPECIMEN")
eyes()
DELAYMS(80)

WEND /
 
one small detail I just realized after pondering a solution to how to make text scroll.
I have the text scrolling in my first code from left to right BUT we read left to right so we are viewing the left most letters first where it should be scrolling from right to left. A module would be a nice addition to the swordfish library.
 
You know that

Code:
For X = 20 to 1, step -1

Blah, blah, blah

Next

works, right?
 
yes I realized that I needed to go from right to left.
I also found the comand(cmddisplayyleft) but the simple code I orginally posted with a few minor exceptions works just as good but ??
here is where I started trying different code snippets to see what they do
DEVICE = 18F2420
CLOCK = 20

// LCD optional settings
#option LCD_DATA = PORTB.4 // LCD setup data port (sets it to 4 data lines only)
#option LCD_RS = PORTB.2
#option LCD_EN = PORTB.3

// Modules
INCLUDE "LCD.bas" // include LCD module
INCLUDE "convert.bas"
INCLUDE
DIM x AS BYTE

// LCD Commands to shift LCD screen left and right
PUBLIC CONST
cmdDisplayRight = %00011100,
cmdDisplayLeft = %00011000

lcd.cls
DELAYMS(2000)
command(cmdDisplayLeft)
DELAYMS(390)
WHILE true
FOR x = 16 TO 1 STEP-1
lcd.writeat(1,x,"hello world ")

DELAYMS(300)
NEXT

lcd.cls


WEND


I can eliminate the LCD commands. and the code works pretty good.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top