11 years, 5 months ago.

Why is keyboard scan so slow

I rather expected the FRDM-KL25Z to be a bit quicker since it has a 48MHz processor. I have the following code to check a 4x4 keyboard for a keypress:

BYTE check_for_keypress ( void ) { int c, k, r;

wait ( 0.1 ); row1 = row2 = row3 = row4 = 1; k = -1; for ( r = 0; r < 4; r++ ) {

  • row[r] = 0;

for ( c = 0; c < 4; c++ ) { if ( *col[c] == 0 ) { wait ( 0.015 ); while ( *col[c] == 0 ); wait for release k = (r * 4) + c; } }

  • row[r] = 1; } return k; }

It is called with:

while ( check_for_keypress() != 15 ) { cycles++; }

It zips along at an agonising 10 iterations per second! How can I speed it up?

Thanks

1 Answer

11 years, 5 months ago.

I should pay more attention to my code. Sorry for the post.