|
|
View previous topic :: View next topic |
Author |
Message |
Razo
Joined: 02 Jan 2009 Posts: 6
|
Matrix Keypad and Sleep |
Posted: Thu Jul 30, 2009 10:50 am |
|
|
Hi, I'm new and learning CCS.
I've got a project on the go which is giving me a headache. I'm using a PIC16f876A with a 4x4 matrix keypad connected to portb using internal pullup's using this driver http://www.ccsinfo.com/forum/viewtopic.php?t=28022&start=14. What I want to do is be able to send the pic to sleep if no button is pressed after a period of time (just before the sleep() command I will also send a pin low, which will be powering a LCD display) and then wake up if any of the buttons on the keypad is pressed.
I found a promising post which was posted 2 years ago http://www.ccsinfo.com/forum/viewtopic.php?t=29144 but the thread PCM points to is no longer here :(
If anyone could point me in the right direction I would be very grateful.
Thanks Raz |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Jul 30, 2009 1:48 pm |
|
|
You have two problems to solve.
1. How to create (presumably) a delay of several seconds, while not
blocking the keypad from entries during the delay ?
Answer: You could use a hardware timer. Configure it for a reasonably
long delay, that is an integral fraction of a second (to make things easy).
Then have a static counter variable inside the isr. Initialize it to 0 in
the declaration statement. Increment it once every timer interrupt.
Then check if it has counted up to the required number of interrupts
(say, 100 ms per interrupt x 100 interrupts = 10 second delay).
Then set a global flag to indicate this state. Pool the global flag in
a loop in main() that is also polling the keypad. When the flag is set,
disable the timer interrupts, clear the flag, and go to sleep.
2. How to wake-up from sleep upon a keypress ?
Answer: Use #int_rb interrupts.
In this thread, Ttelmah explains how to prepare to wake-up from
an int_rb interrupt, without having an #int_rb interrupt service routine.
In other words, you go to sleep, get a keypress, then wake-up and
resume executing the inline code that you were in, before you went
to sleep.
http://www.ccsinfo.com/forum/viewtopic.php?t=35940 |
|
|
Razo
Joined: 02 Jan 2009 Posts: 6
|
|
Posted: Mon Aug 03, 2009 7:34 pm |
|
|
Thanks PCM programmer.
Had to play with it a bit i.e. settings the row pins of the key pad to low.
Playing with the timer0 right now. but tbh I'm cheating ;). As I'm using a i2c RTC I'm talking to that during my main() loop and if a key isn't pressed for 30 sec's it then sleeps (which then powers down the RTC/LCD) and a push of a button gets it started again.
Going to get timer0 working as its the proper thing. But I'll do that another day
EDIT: Shifted the sleep timer over to timer0, had a few issues, but then again you never learn if it works the first time
Thx again for the pointers |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|