CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Matrix Keypad and Sleep

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Razo



Joined: 02 Jan 2009
Posts: 6

View user's profile Send private message

Matrix Keypad and Sleep
PostPosted: Thu Jul 30, 2009 10:50 am     Reply with quote

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 Smile
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jul 30, 2009 1:48 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Aug 03, 2009 7:34 pm     Reply with quote

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 Smile

EDIT: Shifted the sleep timer over to timer0, had a few issues, but then again you never learn if it works the first time Smile

Thx again for the pointers Smile
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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