PDA

View Full Version : GoSub Problem



ghoot
- 7th May 2004, 21:17
Hello again,
Here's another item that doesn't work like it seems it should (to me) ;-). I know I must be missing a simple step somewhere. When this is ran, the LCD just flickers until it passes this part of the code. Shouldn't the gosubs work like this? If I take them out and just use the LCDOUT commands to change cursor position it works fine.


lcdone: LCDOut $fe, 1 : LCDOut $fe, 2 ' Position cursor at home
Return
lcdsec: LCDOut $fe, $C0 ' Move to 2nd line on LCD
Return

GoSub lcdone
LCDOut "1"
GoSub lcdsec
LCDOut "2"
Sleep 2
GoSub lcdone
LCDOut "Warm-Up"
GoSub lcdsec
LCDOut "45 Sec"
Sleep 2
GoSub lcdone
LCDOut "Please"
GoSub lcdsec
LCDOut "Wait..."
Sleep 2

carl_schell
- 8th May 2004, 10:44
GHOOT -

I am assuming you are giving the LCD time to Initialize, and that your Define statements are correct for your setup.

I have used similar routines to save code space...Typically, it is a good idea to place your sub-routines after your END statment to avoid possible problems. I will give you a sample that works fine for me...PIC's take a lot of work to learn, but the learning is my favorite part! I am no expert, but I love working with microcontrollers very very much.

Display: 'Header
GoSub LCDClearHome 'Goto SubRoutine, then return
LCDOut "Good Job GHOOT" 'write to 1st line
LCDOut $FE, $C0 'Prepare to write to second line
LCDOut "GoSubs Work" 'Write to 2nd line
Goto Display 'Loop

END 'Always place subroutines after the end statement

SubRoutines:

LCDClearHome:
LCDOut $FE,1 'Clear LCD
LCDOut $FE, $80 'Move to beginning of first line
Return


Hope this helps you. Keep in mind that you can only nest subroutines 4-levels deep. I try to keep track placing headers such as: Sub Routines: .... Sub-Sub Routines: etc. Keep on learning and remember that we are only limited by our imaginations. Also...you can never comment your code too much!Your friend in the USA,

Carl

Melanie
- 8th May 2004, 12:45
I'd also like to add that (Clear Screen)...

LCDOut $FE,1

automatically moves you to Line 1 Column 1 (address $80) anyway so there's no need to add any further positioning commands if you want to start from that display position.

Also... concatenating muliple LCDOut commands saves on program space, so for example to Clear Screen and move to Start of Line two...

LCDOut $FE,1
LCDOut $FE,$C0

is better written like so...

LCDOut $FE,1,$FE,$C0

Finally, I'll re-enforce Carl's comment about a delay at the start of your program to allow the LCD to initialise before any outputs are made to the LCD... I usually allow 1 second which seems to cover most makes of LCD's (excluding the Serial types which are a law unto themselves depending on who's made it).

Melanie

ghoot
- 11th May 2004, 15:15
Thanks to you both! Placing the sub after the END statement was the problem. Also being able to put two commands into one has saved some more much needed space.
THANKS!