Maker Pro
Maker Pro

What is the best way to tun on and off a pic16f1847 using a microswitch?

Hi I have a pic16f1847 connected to an LCD and stepper driver. I want to turn the pic on and off by holding down a microswitch for a few seconds. Normally i would just use a slider switch on the power but I can't in this case. I have a microswitch connected to a port b pin with weak pull-ups enabled and I get the input correctly. So i know I can use hardware interrupts to count the time the button is pressed and activate/deactivate the lcd/stepper driver but the pic needs to stay on for this. I have looked through the datasheet and I imagine I could do something with MCLR but i'm not sure what exactly.

Thanks in advance for suggestions.
 
Have the PIC sleep and wake upon the button press. Then check that it is still pressed after the desire interval before powering up the rest of the circuit. If you arrange that nothing else is drawing current while in sleep mode, the current draw is miniscule.

Bob
 
Also related to this, is it possible to programatically initiate a reset? I'm thinking that if the device I am making gets into a bad state somehow it would be good to reset without having to take batteries out. Otherwise can MCLR be used in conjunction with the method Bob suggested?
 
Have a look at using the watchdog timer. Your program has to keep 'prodding' the timer within a maximum elapsed time otherwise the PIC will reset itself. So if the program goes wrong, it will miss the timing window and the PIC will reset.
 
Or you can simply jump to the init code, but you must make certain you do not rely on the default values of any of the special function registers, i.e. init all of them that you are using.

Bob
 
Top