Using "END" in a subroutine?


Closed Thread
Results 1 to 7 of 7
  1. #1
    Join Date
    Jan 2009
    Location
    California, USA
    Posts
    323

    Default Using "END" in a subroutine?

    gracefully shutting down...


    I'd like to "END" a program when a subroutine is called.. I don't care much about minimal power consumption, I just want it all to come to a stop until power is removed from the circuit and not restart again unitl power is restored.
    Like this:

    Code:
    BeDoneNow:: 'subroutine to kill it all
    	(do some stuff to gracefully shut down external circuitry)
    	END
    I assume I don't need a "return" from my subroutine.

    Any caveats or weird things to expect from just using "END" in a subroutine to kill the whole program?
    Is ther a smarter way to make it all stop until a "power up reset"?

    Thanks much!

    steve

  2. #2
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    If the sub is reached from a GOSUB then I guess it would depend on the rest of your program. If the program is not expecting data from the sub or data from an interrupt then it would be ok.

    You could also send the code to an endless loop. That way if there is any unfinished task they could be completed.

    STOP also works.

    Could get fancy and have MCLR pulled low...
    Dave
    Always wear safety glasses while programming.

  3. #3
    Join Date
    Jan 2009
    Location
    California, USA
    Posts
    323


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mackrackit View Post
    If the sub is reached from a GOSUB then I guess it would depend on the rest of your program. If the program is not expecting data from the sub or data from an interrupt then it would be ok.
    I'm watching for a pushbutton to pull a port low. When the button is pressed, a subroutine is called that shuts down some external circuitry, finishes all the PIC chores, and then I want all PIC activity to END. Not looking for any more data or anything. No more activity until the power is removed and restored, then the program starts "fresh" again.

    It looks like "END" works fine for what I want. Just wanted to make sure there's no "creepy" side effects or anything.

    thanks!
    Steve

  4. #4
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,615


    Did you find this post helpful? Yes | No

    Talking

    Hi Steve

    Consider the PBP " END " is an assembler

    Code:
    label
    ' here page select if needed
    GOTO label ...
    obviously taking care of page issues ...

    functionnaly exactly the same as the STOP command ( that you should use ) ! - may be same asm ( ! ) code I didn't verify -

    Alain
    Last edited by Acetronics2; - 13th February 2010 at 10:05.
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  5. #5
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    STOP creates an endless loop with a CLRWDT instruction + GOTO back to the label at
    the CLRWDT instruction.

    END creates a loop with a SLEEP instruction + GOTO back to the label at the SLEEP
    instruction.

    Either will work, but END saves power. If you need it to goto sleep and never wake up
    just insert an @ SLEEP at your label, and disable WDT, interrupts, etc..
    Last edited by Bruce; - 13th February 2010 at 15:33.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  6. #6
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,615


    Did you find this post helpful? Yes | No

    Talking

    Oops ... forgot the @sleep ...

    Thanks Bruce !
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  7. #7
    Join Date
    Jan 2009
    Location
    California, USA
    Posts
    323


    Did you find this post helpful? Yes | No

    Default

    Thanks Bruce for the insight into the inner workings of STOP and END.

    I forgot about @ sleep.

    Thanks much!


    steve

Similar Threads

  1. Multiple RETURNS within a single subroutine
    By BrianT in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 21st June 2009, 16:43
  2. Pulsin within subroutine
    By Wesley in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 10th January 2009, 23:05
  3. subroutine with hserin
    By volcane in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 19th December 2007, 02:56
  4. subroutine for picbasic
    By jojokatada in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 19th February 2005, 18:58
  5. Replies: 0
    Last Post: - 28th May 2004, 17:25

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