Red de conocimiento informático - Computadora portátil - ¿Cómo escribir un código de detección de teclado matricial y liberación de teclas para el microcontrolador 80c51? Gracias.

¿Cómo escribir un código de detección de teclado matricial y liberación de teclas para el microcontrolador 80c51? Gracias.

Nota:); //!!!!! Presta atención a este bucle para determinar si soltar el botón

Más comunicación y entrar a mi espacio

/*----- ---- ---------------------------------------

Función de escaneo de claves, devolver el valor de la clave escaneada

-------------- -------------------- ----- ---------*/

unsigned char KeyScan(void) //Función de escaneo de teclado, utilizando el método de escaneo paso a paso de filas y columnas

{

unsigned char Val;

KeyPort=0xf0;//Los cuatro bits superiores son de nivel alto y los cuatro bits inferiores son de nivel bajo

if(KeyPort!=0xf0)//Indica que se presionó la tecla

{

DelayMs(10); //Jitter

if(KeyPort!=0xf0) )

{ // Indica que la tecla ha sido presionada

KeyPort=0xfe; // Detecta la primera línea

if(KeyPort!=0xfe)

{

Val=KeyPort&0xf0;

Val+=0x0e;

while(KeyPort!=0xfe););//!! !! Preste atención al bucle para determinar si se debe liberar la clave

DelayMs(10); //Debounce

while(KeyPort!=0xfe);

return Val;

}

KeyPort=0xfd //Detecta la segunda línea

if( KeyPort!=0xfd)

{

Val=KeyPort&0xf0;

Val+=0x0d;

while(KeyPort!=0xfd);

Devolver Val;

}

KeyPort=0xfb ; //Detecta la tercera línea

if(KeyPort!=0xfb)

{

Val=KeyPort&0xf0;

Val+=0x0b ;

while(KeyPort!=0xfb);

Devolver Val;

}

KeyPort=0xf7; //Detecta la cuarta línea

if(KeyPort!=0xf7)

{

Val=KeyPort&0xf0;

Val+=0x07;

while(KeyPort!=0xf7 //!!!! Preste atención al bucle para determinar si se debe liberar la clave

> DelayMs(10); //De rebote

while(KeyPort! =0xf7);

return Val;

}

}

}

devuelve 0xff;

p>

}