hola amigo soy nuevo en este foro y espero aportar en algo...
buano aca ise un codigo para leer un teclado de 4x4 es una libreria (KBD_calc.c) la cual funciona correctamente
para que funciona se debera poner en el programa principal:
kbd_init();
tecla=kbd_getc(); este te debolvera la tecla pulsada en caracter.
una ves pulsada la tecla se esperara a que se suelte y asi evita rebotes...
codigo:
//este es el codigo de lka libreria.
#byte PORTB = 6
char tecla_get(void);
char conprueva(void);
char tecla,key2,tempo1;
int i,key1,tecla1,tecla2=0b01111111;
void kbd_init()
{
set_tris_b(0x0f);
}
char kbd_getc() //devuelve el valor de la tecla
{
tecla=tecla_get();
tecla=conprueva();
i=0;
switch(tecla)
{
case 0xeb: return ('1');
break;
case 0xdb: return ('2');
break;
case 0xbb: return ('3');
break;
case 0xed: return ('4');
break;
case 0xdd: return ('5');
break;
case 0xbd: return ('6');
break;
case 0xee: return ('7');
break;
case 0xde: return ('8');
break;
case 0xbe: return ('9');
break;
case 0xd7: return ('0');
break;
case 0x7d: return ('x');
break;
case 0x7e: return ('/');
break;
case 0x7b: return ('-');
break;
case 0x77: return ('+');
break;
case 0xb7: return ('=');
break;
case 0xe7: return ('@');
break;
case 0x80: return (0x80);
break;
default: return ('E');
break ;
}
}
char tecla_get() //captura elk valor de la tcla pulsada
{
tecla2=0b01111111;
for(i=0;i<4;i++)
{
#asm
movf tecla2,w
movwf PORTB
#endasm
delay_us(3);
#asm
movf PORTB,w
movwf key2
#endasm
tecla1=tecla2-key2;
if(tecla1!=0)
{
delay_ms(20);
#asm
movf tecla2,w
movwf PORTB
#endasm
delay_us(3);
#asm
movf PORTB,w
movwf key2
#endasm
tecla1=tecla2-key2;
if(tecla1!=0)
{
return (key2);
}
}
rotate_right(&tecla2,1);
}
return (0x80);
}
char conprueva() //espera hasta que la teclas se suelte
{
tecla1=tecla-0x80;
if(tecla1!=0)
{
tempo1=tecla;
do
{
tecla=tecla_get();
i=0;
tecla1=tecla-0x80;
if(tecla1==0)
{
return (tempo1);
}
}while(TRUE);
}
return (0x80);
}
//fin de la libreria.