Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
Peter Dannegger
11/06/03 08:19
Read: 2967 times
Berlin
Berlin


 
#57958 - smaller is beatiful
Responding to: Michael Karas's previous message
I use a many times easier solution:

My debouncer sample the inputs four times and only if a pin state was equal for four consecutive times, it was latched in the same bit position of key_state.
Furthermore often detection of a 1-0 transition was useful and thus the key_press collect such events.

The debouncer:
#include "reg51.h"

#define KEY_INPUT       P1

#define uchar unsigned char


uchar key_state;                        // debounced and inverted key state:
                                        // bit = 1: key pressed
uchar key_press;                        // key press detect or repeat


void int_t0( void ) interrupt INT_T0
{
  static char ct0, ct1;
  char i;

  i = key_state ^ ~KEY_INPUT;           // key changed ?
  ct0 = ~( ct0 & i );                   // reset or count ct0
  ct1 = ct0 ^ ct1 & i;                  // reset or count ct1
  i &= ct0 & ct1;                       // count until roll over ?
  key_state ^= i;                       // then toggle debounced state
  key_press |= key_state & i;           // 0->1: key press detect
}



Then to read one, many or all 8 keys, the get_key_press() do this job. Simple give him a mask, which key you want to read.

The key getter:
#include <reg51.h>

#define uchar unsigned char

extern uchar key_press;

uchar get_key_press( uchar key_mask )
{
  EA = 0;
  key_mask &= key_press;                        // read key(s)
  key_press ^= key_mask;                        // clear key(s)
  EA = 1;
  return key_mask;
}



Peter


List of 14 messages in thread
TopicAuthorDate
8052 Puzzler #2      Michael Karas      11/06/03 00:56      
   RE: 8052 Puzzler #2      Jez Smith      11/06/03 02:30      
      RE: 8052 Puzzler #2      Michael Karas      11/06/03 07:42      
   RE: 8052 Puzzler #2      Jez Smith      11/06/03 03:20      
   smaller is beatiful      Peter Dannegger      11/06/03 08:19      
      RE: smaller is beatiful      Michael Karas      11/06/03 08:42      
      RE: smaller is beatiful      Michael Karas      11/06/03 17:08      
         RE: smaller is beatiful      Peter Dannegger      11/07/03 06:39      
   RE: 8052 Puzzler #2      Mahmood Elnasser      11/07/03 04:17      
      Answer      Andy Neil      11/07/03 05:34      
         RE: Answer      Michael Karas      11/07/03 06:05      
            RE: Answer      Mahmood Elnasser      11/07/03 08:08      
               RE: Answer      Erik Malund      11/07/03 08:23      
               RE: Answer      Michael Karas      11/07/03 08:32      

Back to Subject List