You Are Here: Home » AVR ATmega Projects » 4×4 keypad example using AVR-GCC C language

4×4 keypad example using AVR-GCC C language

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.

4x4 keypad

#include <avr/io.h>
int main()
//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


Leave a Comment

You must be logged in to post a comment.

Read previous post:
How Pendulum Clocks Work
How Pendulum Clocks Work

Pendulum Parts Pendulum clocks have been used to keep time since 1656, and they have not changed dramatically since then....

Scroll to top