| ??? 11/06/03 15:19 Read: times |
#57958 - smaller is beatiful Responding to: ???'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 |
| Topic | Author | Date |
| 8052 Puzzler #2 | 01/01/70 00:00 | |
| RE: 8052 Puzzler #2 | 01/01/70 00:00 | |
| RE: 8052 Puzzler #2 | 01/01/70 00:00 | |
| RE: 8052 Puzzler #2 | 01/01/70 00:00 | |
| smaller is beatiful | 01/01/70 00:00 | |
| RE: smaller is beatiful | 01/01/70 00:00 | |
| RE: smaller is beatiful | 01/01/70 00:00 | |
| RE: smaller is beatiful | 01/01/70 00:00 | |
| RE: 8052 Puzzler #2 | 01/01/70 00:00 | |
| Answer | 01/01/70 00:00 | |
| RE: Answer | 01/01/70 00:00 | |
| RE: Answer | 01/01/70 00:00 | |
| RE: Answer | 01/01/70 00:00 | |
RE: Answer | 01/01/70 00:00 |



