i
thing you should send a 1 to one row, scan the columns, and then send another 1
to the next row, not just send all the 4 1s to all the row at the same
time
Here
goes the code for a working 4*7 matrix keyboard
/*------------------------------------------------------------------------------------
RUTINAS DE UTILIZACION DEL
TECLADO
Teclado matricial de 7 columnas x 4
filas. Las columnas se manejan con un decoder
74hc138 como salida y se leen
los valores de las filas.
Para la conversion se utiliza un matriz.
El
decoder esta conectado a la parte alta del puerto D y las filas a la parte
baja del
puerto B.
COLUMNAS ---------> PUERTO DE LAS
COLUMNAS
FILAS-------------> PUERTO DE LAS FILAS
-----------------------------------
| A |
B | C | D | 1 | 2 | 3 |
-----------------------------------
| E | F |
G | H | 4 | 5 | 6 |
-----------------------------------
| I | J |
K | L | 7 | 8 | 9 |
-----------------------------------
| M | N |
Ñ | O | P | 0 | Q |
-----------------------------------
;
/*-----------------------------------------------------------------------------------*/
#include "Keypad.h"
#include
flash
char
teclas[4][7]={{'A','B','C','D','1','2','3'},
{'E','F','G','H','4','5','6'},
{'I','J','K','L','7','8','9'},
;
{'M','N','O','P','Q','0','R'}
};
/*------------------------------------------------------------------------------------
char Readkey(void)
Escanea la matriz de teclado, devuelve
el valor de la tecla o nulo si no se
presiono
-------------------------------------------------------------------------------------*/
char
Readkey(void)
{ unsigned char i,col,fila,j;
for(i=0;i<7;i++)
{
col=COLUMNAS;
col&=0x1F; // limpio los bits del
decoder
col|=
((i<<5)&0xE0);
COLUMNAS=col; // Escribo el puerto
fila=(~FILAS)&0x0F;
if(fila!=0x00) // Hay
alguna tecla presionada??
{
for(j=0;j<4;j++)
{
if((fila>>j)&(0x01))
{
do
{fila=(~FILAS)&0x0F;}
while((fila>>j)&(0x01)); // Para q no se
mantenga apretada
return(teclas[j][i]) ;
}
}
}
}
return('\0') ;
}
Hi what a failure the project
is.
I was planning to put a 4*4 keyboard on portA of a ATmega32, sending
F0 to the data direction register &
the data port.
this is the
"test" plan, to put 1's on all the rows, the loop will look for a 1 on the
columns, when it
finds a 1 the beeper will beep, then I will continue
to write the code so to put information on the LCD
from the keyboard after
strobbing the rows one by one.
I got it to work alright on the studio
program, it loops round looking for a 1 on the columns, but it
fails
when I download it to the micro,
I have got the port lines going direct to
the keyboard, should I put say 10K resistors on the input
ports? or use
some other hardware ideas?
From
Eric
Visita www.tutopia.com
y comienza a navegar más rápido en Internet. Tutopia es Internet
para todos.