4; if(row_scan ! = 0) // Any key pressed? { row = 0; //Find which bit in row while((row_scan % 2) == 0) // test least significant bit { row++; row_scan >>= 1; } return(key_code[column * 4 + row]); // return key code } // end if column_scan >>= 1; //ready for next column } // end for return 0; // No key pressed }"> 4; if(row_scan ! = 0) // Any key pressed? { row = 0; //Find which bit in row while((row_scan % 2) == 0) // test least significant bit { row++; row_scan >>= 1; } return(key_code[column * 4 + row]); // return key code } // end if column_scan >>= 1; //ready for next column } // end for return 0; // No key pressed }">
Download presentation
Presentation is loading. Please wait.
1
7-1 Keypad Scanning interface Used for interfacing push-button(momentary) switches Used for large number(>8) push-buttons Relies on matrix arrangement of push-buttons 1 1 2 3 F 4 7 5 6E 0 89D AB C ROWS Inputs COLUMNS Outputs PORT
2
7-2 Port 8 1 2 3 F 4 7 5 6E 0 89D AB C bit 4 bit 7 bit 5 bit 3 bit 6 bit 2 bit 1 bit 0 Infineon 167 Target board connections BASIC APPROACH TO SCANNING Set port direction bits 4-7 I/p, bits 0-3 o/p. Initial column_scan = 00001000 = 0x08 next column_scan value =00000100 then 00000010 and finally 00000001 Use 'C' >> operator which shift bits of an integer to the right At each stage read in all rows and if rows are non zero then find which of the four bits is a '1'
3
7-3 static char keypad_scan(void) { const char key_code[] = "FEDC369B2580147A"; // keypad layout unsigned char row, row_scan, column, column_scan; column_scan = 0x08; for(column = 0; column > 4; if(row_scan ! = 0) // Any key pressed? { row = 0; //Find which bit in row while((row_scan % 2) == 0) // test least significant bit { row++; row_scan >>= 1; } return(key_code[column * 4 + row]); // return key code } // end if column_scan >>= 1; //ready for next column } // end for return 0; // No key pressed }
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.