Searching \ for '[PIC] debouncing in c' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/microchip/languages.htm?key=c
Search entire site for: 'debouncing in c'.

Exact match. Not showing close matches.
PICList Thread
'[PIC] debouncing in c'
2006\04\03@051549 by Tim Losereith

flavicon
face

Hello,

I am looking for an example to debounce several push buttons in c. While
debouncing the micro shouldn´t be blocked by a timer.

--
Mit freundlichen Grüßen/Best regards,    

Tim Losereith






2006\04\03@054707 by Wouter van Ooijen

face picon face

> I am looking for an example to debounce several push buttons
> in c. While
> debouncing the micro shouldn´t be blocked by a timer.

Easy method: check the buttons only each xxx ms. xxx must be longer than the bounce time. When unknown xxx = 50 ms is a good guess.

Wouter van Ooijen

-- -------------------------------------------
Van Ooijen Technische Informatica: http://www.voti.nl
consultancy, development, PICmicro products
docent Hogeschool van Utrecht: http://www.voti.nl/hvu


2006\04\03@062745 by Tom Sefranek

face picon face

Tim Losereith wrote:

>Hello,
>
>I am looking for an example to debounce several push buttons in c. While
>debouncing the micro shouldn´t be blocked by a timer.
>  
>
SO use the HARDWARE timer!
(I do!)

Tom

--
 *
 |  __O    Thomas C. Sefranek   spam_OUTWA1RHPTakeThisOuTspamARRL.net
 |_-\<,_   Amateur Radio Operator: WA1RHP  
 (*)/ (*)  Bicycle mobile on 145.41, 448.625 MHz

hamradio.cmcorp.com/inventory/Inventory.html
http://www.harvardrepeater.org

2006\04\03@073631 by Luis.Moreira

picon face
Hi Tim,
I would probably insert an assembly routine to deal with that. I would check the bouncing of the switch on the scope and get a minimum debouncing time and then create a loop which decrements a register until the time is reached, based on CLK used and number of instructions. So on the program every time a switch is pressed you jump to this routine and initiate count, when you exit the routine (time as been reached), check if switch is still pressed.
This is an easy way to do this but has the drawback that while you are doing this you can not do anything else. The timer method you can go and do something else and generate an interrupt when time as been reached. Using the timer is the more elegant solution and you should definitely move in that direction, but if you need the timer for something else and you are not worried about performance that much at the moment, then the loop solution will work.
Hope it helps
Best regards
            Luis    


{Original Message removed}

2006\04\03@074018 by Luis.Moreira

picon face


Hi Tim,
Something I found while Googling:
http://www.ganssle.com/debouncing.pdf
best regards
               Luis


{Original Message removed}

2006\04\03@074316 by Luis.Moreira

picon face
And another...
http://www.rentron.com/Myke6.htm


Regards
               Luis


-----Original Message-----
From: .....piclist-bouncesKILLspamspam@spam@mit.edu [piclist-bouncesspamKILLspammit.edu] On Behalf Of Tom Sefranek
Sent: 03 April 2006 11:28
To: Microcontroller discussion list - Public.
Subject: Re: [PIC] debouncing in c

Tim Losereith wrote:

>Hello,
>
>I am looking for an example to debounce several push buttons in c. While
>debouncing the micro shouldn´t be blocked by a timer.
>  
>
SO use the HARDWARE timer!
(I do!)

Tom

--
 *
 |  __O    Thomas C. Sefranek   .....WA1RHPKILLspamspam.....ARRL.net
 |_-\<,_   Amateur Radio Operator: WA1RHP  
 (*)/ (*)  Bicycle mobile on 145.41, 448.625 MHz

hamradio.cmcorp.com/inventory/Inventory.html
http://www.harvardrepeater.org

2006\04\03@082953 by Vic Fraenckel

flavicon
face
Could this get the job done for you instead of S/W?

http://www.maxim-ic.com/quick_view2.cfm/qv_pk/1195

Be sure to get App Note 1858 while you are there.

HTH

Vic
________________________________________________________

Victor Fraenckel - The Windman        
victorf ATSIGN windreader DOT com
KC2GUI                                                  

     Home of the WindReader Electronic Theodolite
                              Read the WIND

"Dost thou not know, my son, with how little wisdom the world is governed?"
-Count Oxenstierna (ca 1620) to the young King Gustavus Adolphus

"People sleep peacefully in their beds at night only because rough
men stand ready to do violence on their behalf."
-George Orwell

"When a true genius appears in the world you may know him by this sign: that
all the dunces are in confederacy against him."   -Jonathan Swift

2006\04\03@084947 by Tim Losereith

flavicon
face
Vic Fraenckel schrieb:
{Quote hidden}

Thanks for the answers.
The debouncing has do be done in software!

I won´t use loops because during debouncing the micro has to do other jobs.


--
Mit freundlichen Grüßen/Best regards,    

Tim Losereith





2006\04\03@090203 by Phillip

picon face
Hi Tim

I've done this many times in C and assembler
I use a timer to sample the switches.
It is very easy to implement.
I set the timer to interrupt every so often and in the ISR I read the port
that has the switch[s].
The port input pin has a 10k or so pull up with a .1 ufd across it (this
rids if of the bulk of the higher freq stuff/arcing.
I count the number of times it has been down.
Three (or n depends on the clock speed and how many interrupts you can
handle fewer is better in my mind but you need enough so that a very quick
press ) interrupts or so in a row is a valid down and then I look for an up
to tell me the person has let the go of the switch..
I then push the valid button push into a circular buffer.
In my program when I need to know what/if button s pushed I pull the button
push from the buffer.
If there was no push I get a zero if a button was pushed I get the number
telling which button was pressed for n number of counts and then went up.
I like it because it forces the user to make individual presses of the
button.

I haven't implemented here yet but you could set a global var in the code
that tells the ISR not to look for the up and to go ahead and push the key
pressed on to the buffer for a valid down.
This would allow the user to hold the key down if he were in a scenario
where he needed to scroll through a long list or inc or dec something with
fine granularity.
I'm going to put this feature in my brightness and contrast control handling
routines
Let me get that in there today and I'll send you the code.
I want to make sure the command buffer doesn't over flow o I will probably
need to change the number of counts while in this mode also.







Phillip
Things should be as simple as possible but no simpler



Phillip Coiner
CTO, GPS Source, Inc.


Your source for quality GNSS Networking Solutions and Design Services, Now!

-----Original Message-----
From: EraseMEpiclist-bouncesspam_OUTspamTakeThisOuTmit.edu [piclist-bouncesspamspam_OUTmit.edu] On Behalf Of
Tim Losereith
Sent: Monday, April 03, 2006 3:13 AM
To: @spam@piclistKILLspamspammit.edu
Subject: [PIC] debouncing in c

Hello,

I am looking for an example to debounce several push buttons in c. While
debouncing the micro shouldn´t be blocked by a timer.

--
Mit freundlichen Grüßen/Best regards,    

Tim Losereith






2006\04\03@092658 by Mark Scoville

flavicon
face

> From: KILLspampiclist-bouncesKILLspamspammit.edu [RemoveMEpiclist-bouncesTakeThisOuTspammit.edu]On Behalf
> Of Tim Losereith
> Sent: Monday, April 03, 2006 5:13 AM
> To: spamBeGonepiclistspamBeGonespammit.edu
> Subject: [PIC] debouncing in c
>
> I am looking for an example to debounce several push buttons in c. While
> debouncing the micro shouldn´t be blocked by a timer.
>

See this link on debouncing with a "vertical" counter... http://www.dattalo.com/technical/software/pic/debounce.html  This works very well for debouncing multiple inputs.

-- Mark



2006\04\03@115424 by Scott Dattalo

face
flavicon
face

Mark Scoville wrote:
>>From: TakeThisOuTpiclist-bouncesEraseMEspamspam_OUTmit.edu [RemoveMEpiclist-bouncesspamTakeThisOuTmit.edu]On Behalf
>>Of Tim Losereith
>>Sent: Monday, April 03, 2006 5:13 AM
>>To: piclistEraseMEspam.....mit.edu
>>Subject: [PIC] debouncing in c
>>
>>I am looking for an example to debounce several push buttons in c. While
>>debouncing the micro shouldn´t be blocked by a timer.
>>
>
>
> See this link on debouncing with a "vertical" counter... http://www.dattalo.com/technical/software/pic/debounce.html  This works very well for debouncing multiple inputs.

And in particular, the C-snippet in the comments is what I believe Tim
is seeking:

static unsigned clock_A,clock_B,debounced_state;

unsigned debounce(unsigned new_sample)
{
  unsigned delta;
  unsigned changes;

  delta = new_sample ^ debounced_state;   //Find all of the changes

  clock_A ^= clock_B;                     //Increment the counters
  clock_B  = ~clock_B;

  clock_A &= delta;                       //Reset the counters if no
changes
  clock_B &= delta;                       //were detected.

  changes = ~(~delta | clock_A | clock_B);
  debounced_state ^= changes;

  return changes;
}

The link Mark cites describes the algorithm. But the idea is to do some
thing like this:

 while(doing_stuff)
 {

    if (debounce(PORTA)) {
      // one of the 8 switches connected to PORTA
      // has changed to its new filtered state.
     ...
    }

   // do other stuff ...
 }

The debounce routine has a 4-sample settling time. In other words, it
takes 4 samples before the switch state is considered filtered. So, you
should arrange for the debounce() routine to be called no faster than
perhaps once every 5 or 10 mS.

I wonder if the C-compiler can produce the same 12-instruction sequence?

Scott

2006\04\03@152335 by David P Harris

picon face

Wouter van Ooijen wrote:

>>I am looking for an example to debounce several push buttons
>>in c. While
>>debouncing the micro shouldn´t be blocked by a timer.
>>    
>>
>
>Easy method: check the buttons only each xxx ms. xxx must be longer than the bounce time. When unknown xxx = 50 ms is a good guess.
>
>Wouter van Ooijen
>  
>
You know this is dead simple, and I cannot think of any criticism of
it.  Nobody has commented otherwise, have they?

:-)

David


2006\04\03@155403 by William Chops Westfield

face picon face

On Apr 3, 2006, at 12:23 PM, David P Harris wrote:

>> Easy method: check the buttons only each xxx ms.
>>
> You know this is dead simple, and I cannot think of any criticism of
> it.  Nobody has commented otherwise, have they?

It more-or-less require that you have a timer interrupt available,
along with the associated "complexity" of interrupts.  I think
that's unavoidable if you can't loop, but it may deter some people.

BillW

2006\04\03@160115 by Mark Scoville

flavicon
face

{Quote hidden}

The only thing I would worry about is noise causing a "false" button push. While the "check every 50mS and take what you get" method would probably work most of the time - I wouldn't trust it. I think the vertical counter method or other "gotta have the same value for xx times in a row" methods will be more robust.

-- Mark



2006\04\03@160500 by Wouter van Ooijen

face picon face
> >Easy method: check the buttons only each xxx ms. xxx must be
> longer than the bounce time. When unknown xxx = 50 ms is a good guess.
> >
> You know this is dead simple, and I cannot think of any criticism of
> it.  Nobody has commented otherwise, have they?

nope.

The only drawback is that it won't work when you need realy fast response, for instance for a midi keyboard or maybe a high-end gamepad. But certainly good enough for normal use.

Wouter van Ooijen

-- -------------------------------------------
Van Ooijen Technische Informatica: http://www.voti.nl
consultancy, development, PICmicro products
docent Hogeschool van Utrecht: http://www.voti.nl/hvu



2006\04\03@164122 by Wouter van Ooijen

face picon face
> >> Easy method: check the buttons only each xxx ms.
> >>
> > You know this is dead simple, and I cannot think of any criticism of
> > it.  Nobody has commented otherwise, have they?
>
> It more-or-less require that you have a timer interrupt available,

Absolutely not. I very very seldom use interrrupts at all, and if I use
interrupts it is to simulate some peripheral, like a UART with a FIFO
buffer. User interaction IMHO belongs in the main loop. I often use 10
or 50 ms as the main loop cycle time. I that cycle time is fatsre than
the debounce time, I simply check the buttons once in N loops.

Wouter van Ooijen

-- -------------------------------------------
Van Ooijen Technische Informatica: http://www.voti.nl
consultancy, development, PICmicro products
docent Hogeschool van Utrecht: http://www.voti.nl/hvu


2006\04\03@164122 by Wouter van Ooijen

face picon face
> The only thing I would worry about is noise causing a "false"
> button push.

OK, I had to compensate for that once. But that was because the user input was an "N-resistors shorted by normally-closed-pushbuttons" style input. Hence A/D conversion, with thye risk of intermediate values due to capacitive effects and other analog trouble.

But IMHO if you get false button-closed readings there is something seriously wrong in your hardware design. Using a counter might help for the buttons, but is that the only inputs to your system? Or do you use counters for the UART, I2C, SPI, LCD etc. too? And do the chips at the other end also implement such counters? Better find and solve the real problem than mask it in software!

Now if what you get are flse *open* readings I might have some sympathy. With you, not with the buttons involved.

Wouter van Ooijen

-- -------------------------------------------
Van Ooijen Technische Informatica: http://www.voti.nl
consultancy, development, PICmicro products
docent Hogeschool van Utrecht: http://www.voti.nl/hvu




2006\04\03@173351 by Scott Dattalo

face
flavicon
face

David P Harris wrote:
> Wouter van Ooijen wrote:
>
>
>>>I am looking for an example to debounce several push buttons
>>>in c. While
>>>debouncing the micro shouldn´t be blocked by a timer.
>>>  
>>>
>>
>>Easy method: check the buttons only each xxx ms. xxx must be longer than the bounce time. When unknown xxx = 50 ms is a good guess.
>>
>>Wouter van Ooijen
>>
>>
>
> You know this is dead simple, and I cannot think of any criticism of
> it.  Nobody has commented otherwise, have they?

Well, no one's commented on it because the thread has only been alive
for a day or so. N*6 months ago when we last talked about this thread,
the same group of people chimed in as this time and this same point was
discussed (maybe it was discussed for N being even)! But Wouter's method
is more than sufficient for most cases - if the switch isn't bouncing,
then you can reliably read its state without having to resort to
elaborate filtering. My debouncing routine has its roots in RTU relay
time tagging; a environment far different than a snap dome.

But, there are at least two reasons why you might want a
debouncer/filter: 1) faster response 2) remove "spurious" transitions.
Both of these are probably insufficient reasons for normal switches. If
a switch can be pressed at a rate faster than it bounces, then it will
suffer from usability issues. If there are chances for spurious
transitions then there again usability issues.

2006\04\03@182719 by Phillip

picon face

Hi all
I just finished up my routines for de-bouncing switches.
They use a timer on a low priority interrupt to count the number of switch
presses/closures in the background.
You can use them two ways one is where you have to press the button down and
then release it to get a valid closure.
Or you and call a function and get a closure after a number of counts with
out releasing the switch.
This lets me use the switches to run settings up and down or to single
select items from a menu.
Right now the counts for the closure onetime and the hold it down are the
same but it would be easy enough to make the counts different for each
situation.
If anyone is interested I'd be happy to post the code it but I'm not sure
how exactly to do it I've only been on this forum for a couple of days.
Do I just attach to a message of post the text in my message?
I just gotter done today so no guaranties that it is bug free.


Phillip
Things should be as simple as possible but no simpler



Phillip Coiner
CTO, GPS Source, Inc.


Your source for quality GNSS Networking Solutions and Design Services, Now!
{Original Message removed}

2006\04\03@195654 by David P Harris

picon face

Scott Dattalo wrote:

{Quote hidden}

I was, of course, referring to previous discussions.

{Quote hidden}

I guess we need to define our environments.

1/ For a pushbutton user interface in non-realtime situations, ie most
uses for setting parameters, then a looped 50 ms check is good enough.  
If the button was just pushed and is bouncing and we miss it, then it
will get caught the next time through, after the bouncing has stopped.

2/ In a realtime environment, say spacewars, a faster response system,
such as vertical counters can detect the end of the bouncing and give
the faster response.

3/ An environment with a possibility of spurious transisitons (very
noisy, in a car etc), again more robust methods are needed.

Most of my apps fall into case 1.

Thanks,
David


2006\04\03@213651 by Phillip

picon face
Hi Tim
I have that code working if you need it.





Phillip
Things should be as simple as possible but no simpler



Phillip Coiner
CTO, GPS Source, Inc.


Your source for quality GNSS Networking Solutions and Design Services, Now!

-----Original Message-----
From: RemoveMEpiclist-bouncesspam_OUTspamKILLspammit.edu [RemoveMEpiclist-bouncesTakeThisOuTspamspammit.edu] On Behalf Of
Tim Losereith
Sent: Monday, April 03, 2006 3:13 AM
To: EraseMEpiclistspamspamspamBeGonemit.edu
Subject: [PIC] debouncing in c

Hello,

I am looking for an example to debounce several push buttons in c. While
debouncing the micro shouldn´t be blocked by a timer.

--
Mit freundlichen Grüßen/Best regards,    

Tim Losereith






2006\04\05@165007 by Harshal

picon face

respected one please clerify your idea clearly.
are you looking for solution for deboucing of no of swithches ? how
many?????
does not block timer ?? please clerify that

--
View this message in context: www.nabble.com/-PIC-debouncing-in-c-t1385900.html#a3772643
Sent from the MicroControllers - PIC forum at Nabble.com.

2006\04\06@025854 by Tim Losereith

flavicon
face
Phillip schrieb:
> Hi Tim
> I have that code working if you need it.
>
>  
>  
>  
>  
> Phillip
>  

Thanks for the many answers!
I am interested in the code Phillip. Please post it.

2006\04\06@105230 by Phillip

picon face
Hi Tim
Here is the h file

#ifndef __BUTTON_H                                 //Phillip Coiner GPS
Source
#define __BUTTON_H                                 //4710 Eagleridge Circle
Suite 220 Pueblo Colorado 81008 719-561-9520
#include<vars.h>                                   //Your source for GPS
signals 5 April 2005
#include<p18f6520.h>                               //any comments or
suggestions would be greatly appreciated
                        //I have formally studied quite a few high level
languages but all the bit twiddling knowledge I've picked up thru osmosis
and serendipity.
#define dn  1                                       //so my code mostly
works but no one has ever accused me of writing efficent code
#define up  2                                       //I chose the name
button because the name switch is a reserved word in C
#define enter  3                                    //I use this in my
products for my business but I am sharing this so it should not be sold by
anyone.
#define blink 1                                    
#define temp 2                                      
void toggle_hold_it(const unsigned char);
void init_BUTTON_BUFF(void);
void detect_button_push_ISR(void);
void configure_button_timer(void);
void configure_button_port_bits(void);
unsigned char pull_button_event(void);
void push_button_event(unsigned char);
#endif



Phillip
Things should be as simple as possible but no simpler



Phillip Coiner
CTO, GPS Source, Inc.


Your source for quality GNSS Networking Solutions and Design Services, Now!
-----Original Message-----
From: RemoveMEpiclist-bouncesKILLspamspammit.edu [piclist-bouncesSTOPspamspamspam_OUTmit.edu] On Behalf Of
Tim Losereith
Sent: Thursday, April 06, 2006 12:59 AM
To: Microcontroller discussion list - Public.
Subject: Re: [PIC] debouncing in c

Phillip schrieb:
> Hi Tim
> I have that code working if you need it.
>
>  
>  
>  
>  
> Phillip
>  

Thanks for the many answers!
I am interested in the code Phillip. Please post it.

2006\04\06@105407 by Phillip

picon face
Hi Tim
Here is the c file

#include<button.h>                                            //Phillip
Coiner GPS Source
#include<timers.h>                                            //4710
Eagleridge Circle Suite 220 Pueblo Colorado 81008 719-561-9520
#include<vars.h>                                              //Your source
for GPS signals 5 April 2005
                                                             //any comments
or suggestions would be greatly appreciated
                       //I have formally studied quite a few high level
languages but all the bit twiddling knowledge I've picked up thru osmosis
and serendipity.
                                                             //so my code
mostly works but no one has ever accused me of writing efficent code
                                                             //I chose the
name button because the name switch is a reserved word in C
#define BUTTON_BUFF_LENGTH 100                                //does the
buffer really need to be this long????  
#define number_of_samples 2                                   //this is the
number of times I need to see a switch closure
unsigned char BUTTON_BUFF[BUTTON_BUFF_LENGTH] = {0};           //is this the
way to zero an array????.......when your memory goes forget it
                                                              //I use this
in my products for my business but I am sharing this so it should not be
sold by anyone.  


volatile  unsigned char  UP_cnt, DN_cnt, ENTR_cnt, UP_valid, DN_valid,
ENTR_valid, hold_it = 0;
unsigned char  *button_head;
unsigned char  *button_tail;


void configure_button_port_bits(void)
{
TRISBbits.TRISB3 = 1;               // set port bit as input for button
TRISBbits.TRISB4 = 1;               // set port bit as input for button
TRISBbits.TRISB5 = 1;               // set port bit as input for button
}

void configure_button_timer(void)
{
OpenTimer3 (TIMER_INT_ON & T3_SOURCE_INT & T3_16BIT_RW & T1_OSC1EN_OFF &
T3_SYNC_EXT_OFF & T3_PS_1_1 & T1_SYNC_EXT_OFF & T12_CCP12_T34_CCP345);
WriteTimer1(32768);                  
INTCONbits.GIEH = 1;                  // Enable interrupts global & high
INTCONbits.GIEL = 1;                  // Enable low priority interrupts
only but you need global also
}

void toggle_hold_it(const unsigned char holdit_bit)
//you call this func when you want the hold the switch down and gen
debounced pushes
{
 hold_it = holdit_bit;
}

void detect_button_push_ISR(void)
{  
   PIR2bits.TMR3IF = 0;                              //clear the timer bit
   WriteTimer3(32768);                               //I don't think I need
to do this every time I haven't measured the time betweent itnerrupts
without using the oscope yet I will do it soon

   if (!PORTBbits.RB3)
    {
      UP_cnt++;                                // if this bit is low then
you have a button/switch  closure don't be confused by the UP it is the
button switch name
     }
   else
    {
     UP_cnt =0;                                   //if it did not last for
number_of_samples timeouts then it is noise so reset the counter look for
antoher button/switch press
    }

   if (UP_cnt == number_of_samples)
    {
      UP_valid = 1;                                      // we got
requisite number_of_samples so must be a valid button press

      UP_cnt = 0;                                       // now I'm looking
for a switch open unless of course hold_it is true.
     }

 if ((PORTBbits.RB3) && (UP_valid) && (!(hold_it)))             // need a
button/switch open if hold_it is false  
  {
   UP_valid = 0;
   push_button_event(up);  
  }
 
if   ((UP_valid) && (hold_it))                              
  {    
      UP_valid = 0;                                     //if you have
pushed a command for a valid event then clear it and start over
      push_button_event(up);                            //if the hold_it
bit is set then we push a command without waiting for the switch/button to
be opened
   }

if (!PORTBbits.RB4)
    {
      DN_cnt++;                      // if this bit is low then you have a
button/switch  closure don't be confused by the DN it is the button/switch
name
     }
   else
    {
     DN_cnt =0;                    //if it did not last for
number_of_samples timeouts then it is noise so reset the counter look for
antoher button/switch press
    }

   if (DN_cnt == number_of_samples)
    {
      DN_valid = 1;
      DN_cnt = 0;
     }

 if ((PORTBbits.RB4) && (DN_valid) && (!hold_it))
  {
   DN_valid = 0;
   push_button_event(dn);
  }

 if   ((DN_valid) && (hold_it))                              
  {    
      DN_valid = 0;                                     //if you have
pushed a command for a valid event then clear it and start over
      push_button_event(dn);                            //if the hold_it
bit is not set then we push a command without waiting for the switch/button
to be opened
  }
 
if (!PORTBbits.RB5)
    {
      ENTR_cnt++;                                     // if this bit is low
then you have a button/switch closure don't be confused by the ENTR it is
the button/switch name
     }
   else
    {
     ENTR_cnt =0;                                     //if it did not last
for number_of_samples timeouts then it is noise so reset the counter look
for antoher button/switch press
    }

   if (ENTR_cnt == number_of_samples)
    {
      ENTR_valid = 1;
      ENTR_cnt = 0;
     }

  if ((PORTBbits.RB5) && (ENTR_valid))
  {
   ENTR_valid = 0;
     push_button_event(enter);
  }
}

void init_BUTTON_BUFF(void)
{
unsigned char i;
button_head = (unsigned char*) &BUTTON_BUFF;
button_tail = (unsigned char*)&BUTTON_BUFF;
for (i=0;i<=BUTTON_BUFF_LENGTH;i++)                 //zero out the CMD
buffer I know on sowm compilers this is not necessary the way this works it
is not s=need but habits die hard
BUTTON_BUFF[i] = 0;
}

unsigned char pull_button_event(void)
{
  unsigned char x;

  if (button_head == button_tail)
  {
      return 0;
   }
    x = *button_tail;
//return first command in the buffer
 if (button_tail == &BUTTON_BUFF[BUTTON_BUFF_LENGTH -1])
//if the pointer reaches the end of the buffer reset start of the buffer
   button_tail = (unsigned char*) &BUTTON_BUFF;

 else
   button_tail++;
  return x;    
}

void push_button_event(unsigned char cmd_in)
{

*button_head = cmd_in;

if (button_head == &BUTTON_BUFF[BUTTON_BUFF_LENGTH -1])
//if the pointer reaches the end of the buffer reset to the start of the
buffer to store commands
  button_head = (unsigned char*) &BUTTON_BUFF;
//it is theoretically possible to over write previous commands if but if
you've buffered up BUTTON_BUFF_LENGTH commands        
else
//without processing them then something is likely very wrong
  button_head++;
}





Phillip
Things should be as simple as possible but no simpler



Phillip Coiner
CTO, GPS Source, Inc.


Your source for quality GNSS Networking Solutions and Design Services, Now!

-----Original Message-----
From: spamBeGonepiclist-bouncesSTOPspamspamEraseMEmit.edu [KILLspampiclist-bouncesspamBeGonespammit.edu] On Behalf Of
Tim Losereith
Sent: Thursday, April 06, 2006 12:59 AM
To: Microcontroller discussion list - Public.
Subject: Re: [PIC] debouncing in c

Phillip schrieb:
> Hi Tim
> I have that code working if you need it.
>
>  
>  
>  
>  
> Phillip
>  

Thanks for the many answers!
I am interested in the code Phillip. Please post it.

More... (looser matching)
- Last day of these posts
- In 2006 , 2007 only
- Today
- New search...