PDA

View Full Version : Can button be set to cause interrupt, and then it's functions changed?



CuriousOne
- 2nd November 2016, 19:12
Hello. The title looks a bit rubbish, but I don't know how to explain what I need.

I need the following.

CPU is sleeping, it has button connected. When user press button, cpu wakes up for defined amount of time (say, 60 seconds) and while cpu awake, this button no longer causes interrupt, but is used for other purposes, such as mode selection and so on. After 60 seconds passed, cpu enters sleep mode again.

Is this doable using PBP ?

Heckler
- 3rd November 2016, 02:33
Hey Curious One...

Yes, I think what you want is very do-able.

Just have your code disable the INT on that pin after the PIC wakes up.
Then have your code watch that pin for change to select a given mode.
When your 60 second timer (however you choose to implement the timer or some code in the loop you are running after the PIC is interrupted to increment a counter to keep track of time)
Then re-enable the INT before putting the PIC back to sleep.

I'm not the worlds best programmer by any stretch so my explanation above is very rough.

The real trick is to figure out how to direct your PIC (write the code instructions) to do just what you want it to do. But then that is the challenge of any code :-)

I hope this gives you some ideas.

Art
- 9th November 2016, 16:28
Yep :) Most of it will work the way you want it to on it’s own.
Especially since portb.o interrupt should cause wake up from sleep AND jump to the ISR where you can disable it.

CuriousOne
- 10th November 2016, 06:14
Can built-in timer used to count the time while circuit is on?

Art
- 10th November 2016, 13:17
That’s what DT’s Elapsed Timer does, yes, but if you want to use the portb.0 interrupt for a button as well,
there is a separate DT package. I forget the name of that, but someone will chime in. It allows multiple interrupt sources.