GoSub Problem


Closed Thread
Results 1 to 4 of 4

Thread: GoSub Problem

  1. #1
    ghoot's Avatar
    ghoot Guest

    Default GoSub Problem

    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

  2. #2
    carl_schell's Avatar
    carl_schell Guest


    Did you find this post helpful? Yes | No

    Thumbs up GoSub's

    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

  3. #3
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    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

  4. #4
    ghoot's Avatar
    ghoot Guest


    Did you find this post helpful? Yes | No

    Default

    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!

Similar Threads

  1. Graphic LCD with PICbasic pro
    By amindzo in forum mel PIC BASIC Pro
    Replies: 41
    Last Post: - 25th November 2012, 11:45
  2. Making a menu
    By chrisshortys in forum mel PIC BASIC Pro
    Replies: 36
    Last Post: - 12th November 2008, 19:54
  3. shifting problem
    By helmut in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 31st August 2007, 06:11
  4. Output PIC module
    By freelancebee in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 12th September 2005, 20:10
  5. ds1307 from f877 to f452 not work
    By microkam in forum mel PIC BASIC Pro
    Replies: 23
    Last Post: - 7th July 2005, 00:02

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts