Maker Pro
Maker Pro

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

cc85

Apr 25, 2013
16
Joined
Apr 25, 2013
Messages
16
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.
 

BobK

Jan 5, 2010
7,682
Joined
Jan 5, 2010
Messages
7,682
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
 

cc85

Apr 25, 2013
16
Joined
Apr 25, 2013
Messages
16
Thanks Bob!
That sounds like a good way to do it. I will try that this weekend.

Chris
 

cc85

Apr 25, 2013
16
Joined
Apr 25, 2013
Messages
16
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?
 

shumifan50

Jan 16, 2014
579
Joined
Jan 16, 2014
Messages
579
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.
 

BobK

Jan 5, 2010
7,682
Joined
Jan 5, 2010
Messages
7,682
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