Log in

View Full Version : Using "END" in a subroutine?



Byte_Butcher
- 13th February 2010, 04:51
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:




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

mackrackit
- 13th February 2010, 05:23
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...

Byte_Butcher
- 13th February 2010, 05:54
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

Acetronics2
- 13th February 2010, 10:02
Hi Steve

Consider the PBP " END " is an assembler




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

Bruce
- 13th February 2010, 15:25
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..

Acetronics2
- 13th February 2010, 16:02
Oops ... forgot the @sleep ...

Thanks Bruce !

Byte_Butcher
- 13th February 2010, 16:32
Thanks Bruce for the insight into the inner workings of STOP and END.

I forgot about @ sleep.

Thanks much!


steve