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

Avoiding bounce in input

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



Joined: 12 Apr 2010
Posts: 5

View user's profile Send private message

Avoiding bounce in input
PostPosted: Mon Apr 12, 2010 11:31 am     Reply with quote

I'm a newbie and I'm trying to learn to program with C.
What's the best way to avoid getting lots of ones when you push a button or get a signal from a sensor? interruption with RB0? or a delay? (I don't like delays because I need the program to keep running) or is there an edge function?

Thanks for your help


Last edited by danielpepo on Mon Apr 12, 2010 10:30 pm; edited 1 time in total
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Apr 12, 2010 11:38 am     Reply with quote

Here is a simple button debounce program:
http://www.ccsinfo.com/forum/viewtopic.php?t=19874

Here is the "Button Command" code that I wrote for the Code Library:
http://www.ccsinfo.com/forum/viewtopic.php?t=23837

Here's a version of it that polls the buttons during a timer interrupt:
http://www.ccsinfo.com/forum/viewtopic.php?t=31849

This version stores the button presses in a buffer, which can be read:
http://www.ccsinfo.com/forum/viewtopic.php?t=39585&start=1
danielpepo



Joined: 12 Apr 2010
Posts: 5

View user's profile Send private message

PostPosted: Wed Apr 14, 2010 2:43 am     Reply with quote

Thanks for your help.
What if using your button.c code I don't want the delay and the auto-repeat to work?
I want to make a counter which only counts once when the button is pressed, the button could stay pressed indefinitely.
danielpepo



Joined: 12 Apr 2010
Posts: 5

View user's profile Send private message

PostPosted: Wed Apr 14, 2010 3:13 am     Reply with quote

I just found out if I load 255 on delay, it doesn't repeat.
I couldn't understand one thing from your button code, How can you know 50 would be 500ms and so on?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Apr 14, 2010 10:38 am     Reply with quote

Look in the while() loop in the main program. It has a delay_ms(10)
statement at the end. This means the counters will count in 10ms
increments. A count of 50 gives 50 x 10ms = 500 ms.
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