This is as simple routine how to read 4×4 keypad keys using AVR-GCC language. The keypad is connected to AVR microcontroller 8 bit port. In this example it is B port. You can change ports depending on your needs – this is only an example ant it is not the only way to this.
Howt it works. Well very simply. PORTB is divided into two nibbles PINB0 – PINB3 as inputs (as rows) and PINB4-PINB7 as outputs (columns). The keys are checked in a loop in series. Lets say if we set first row output (PORTB bit 7) to 0 then when checking rows we are looking which bit is set to 0, because of key pressed with function bit_is_set(PINB, bitNo). This function gives non-zero if bit is clear.
10k resistors protect AVR from shortcuts.
//high nibble for output(columns) low for input(rows);
//enable internal pullups for PB0-PB3
//Port D for indication only
while (1) //loop key check forever For more detail: 4x4 keypad example using AVR-GCC C language
This free embedded project also found using: