I'm trying to test a simple 4x4 keypad matrix on a TS-7250, and am seeing
some very strange behavior. Is there something I'm missing here?
I have a 16-key keypad wired as a 4x4 matrix; an ohm meter verifies that
all keys connect their respective row and column together. The columns are
wired to bits 0-3 on the DIO port (pins 1, 3, 5, and 7), and the rows are
wired to bits 4-7 (pins 9, 11, 13, and 15).
I've looked at the example keypad.c code from this list, and I understand
what it's doing. Right now, I'm ignoring the debounce stuff, because I just
want to see the keys respond.
The problem is, the code is not reliably detecting the depressed keys. Here
is the test code from my getKeys() function, which is called by main()
about once every second, so I can see the output. (I'm setting only one
column pin at a time to an output because several keys might be depressed
at once, and without series diodes, the output pins would be shorted
together. So all column pins are set to inputs except when scanning that
column.)
-----------------------------------------
(In the main function)
PBDR = (unsigned int *)(start + 0x04);
PBDDR = (unsigned int *)(start + 0x14);
unsigned int *dataPort = PBDR; // Use Port B for keypad data
unsigned int *dataDirReg = PBDDR; // Direction register for keypad data port
*dataDirReg = 0x00; // Start with all bits inputs (changed when reading
keypad)
// Loop to call getKey, then delay.
-----------------------------------------
(In the getKey function)
int col;
col = 0;
*dataDirReg = (1 << col); // Set one column to output and pull it low
*dataPort = ~(1 << col);
printf("col = %d, *dataPort = %04X\n", col, (*dataPort & 0xff));
col = 1;
*dataDirReg = (1 << col); // Set one column to output and pull it low
*dataPort = ~(1 << col);
printf("col = %d, *dataPort = %04X\n", col, (*dataPort & 0xff));
col = 2;
*dataDirReg = (1 << col); // Set one column to output and pull it low
*dataPort = ~(1 << col);
printf("col = %d, *dataPort = %04X\n", col, (*dataPort & 0xff));
col = 3;
*dataDirReg = (1 << col); // Set one column to output and pull it low
*dataPort = ~(1 << col);
printf("col = %d, *dataPort = %04X\n", col, (*dataPort & 0xff));
*dataDirReg = 0; // Set all columns back to input
-----------------------------------------
If I comment-out all but one of these sections, everything works as
expected. I can press any key or combination of keys and see the expected
result. It doesn't matter which column I un-comment, it works correctly.
But if I have any two columns un-commented, the first one works perfectly,
but the second one returns unpredictable results. That is, sometimes I see
zeros for the depressed keys, but other times all the bits are 1.
I'm thinking there is a delay between outputting the 0 and when the
hardware actually responds. Is this the case? I've put a 'usleep(100000);'
statement after each section, and that seems to help a little, but it's
still only 25%-50% correct.
Thanks for any insight into this issue.
Mike
------
Mike Dodd - Montpelier, VA
http://www.mdodd.com
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/ts-7000/
<*> To unsubscribe from this group, send an email to:
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/
|