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 CCS Technical Support

What's the best way to write this code?

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



Joined: 25 Feb 2006
Posts: 23

View user's profile Send private message

What's the best way to write this code?
PostPosted: Tue Nov 25, 2008 1:57 am     Reply with quote

I'm using PIC16F676 so I have limited resources.

What I'm trying to make is a digital lock that has 4 buttons. 3 buttons are used to enter the code and the last button is used as an "unlock" button.

One of the features that I want to do is when you hold the "unlock" button for 5 sec, the circuit will go into code change mode where you can change your unlock code.

What's the best way to detect when a user holds down the unlock button for 5 sec or more? I can't dedicate a timer to this feature.
RLScott



Joined: 10 Jul 2007
Posts: 465

View user's profile Send private message

Re: What's the best way to write this code?
PostPosted: Tue Nov 25, 2008 7:39 am     Reply with quote

david90 wrote:
I'm using PIC16F676 so I have limited resources.

What I'm trying to make is a digital lock that has 4 buttons. 3 buttons are used to enter the code and the last button is used as an "unlock" button.

One of the features that I want to do is when you hold the "unlock" button for 5 sec, the circuit will go into code change mode where you can change your unlock code.

What's the best way to detect when a user holds down the unlock button for 5 sec or more? I can't dedicate a timer to this feature.

First you must consider debouncing. If the code has nothing else to do when buttons are pushed, then you can poll for buttons and busy-wait whenever a button is pressed. During the busy-wait, you can use instruction timing or a hardware timer to determine how low a button is held down. Integrate debouncing into that busy-wait so that when a button is first detected as pressed or released, the press or release recognition should be delayed until the press or release has continued for a certain minimum period. A good way to do this is to increment a variable with a ceiling limit whenever the button is detected as pressed and decrement that variable with a floor limit whenever the button is detected as released. When the variable hits the ceiling or the floor you can take whatever recognition action is required.
_________________
Robert Scott
Real-Time Specialties
Embedded Systems Consulting
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