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.

keypad

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);
DDRB=0xF0;
//enable internal pullups for PB0-PB3
PORTB=0x0F;
//Port D for indication only
DDRD=0xFF;
while (1) //loop key check forever
For more detail: 4x4 keypad example using AVR-GCC C language

 


About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:
LinkedinTwitter

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top