This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

PS2 keyboard reader

Anybody can find the problem in this chunk of code ? When I hit 'A' I get 1C as code but when I release I get a 70 instead of an F0. If you can of course. It seams that the first bit
is never read. Thank you.

unsigned char getKey()
{ unsigned char n,dato; n = 0; // Inizializza il contatore dato = 0; // Inizializza il dato while(CLOCK); // Se il clock rimane a 1 aspetta while(!CLOCK); // La prossima discesa e' quella con il primo bit for (n = 0; n < 7; n++) { while(CLOCK); // Aspetta il bit n-esimo if (DATA) dato = dato | 0x80; // Bitwise OR dato = dato >> 1; // Shift a destra while(!CLOCK); // Aspetta la risalita del clock } while(CLOCK); // Aspetta il parity bit parity = DATA; while(!CLOCK); while(CLOCK); // Aspetta lo stop bit while(!CLOCK);

return dato; }