How to interface keypad with PIC16F877

Interfacing keypad

This PIC microcontroller tutorial provides a simple method to interface any keypad (e-g 4×4 or 4×3 etc) with PIC16F877 microcontroller.

Interfacing keypad

This code is written in C language using MPLAB with HI-TECH C compiler. You can download this code from the ‘Downloads‘ section at the bottom of this page.

In this post, it is assumed that you know, how to interface LCD with PIC16F877 microcontroller, If you don’t then please read this page.
The circuit required to interface keypad with PIC16F877[1] is shown below.

Interfacing keypad schematic

The result of simulating the code in Proteus is shown above in the figure. This code is written in such a way that when you press any key from the keypad, then the value of that key is displayed on the LCD. For example, in the above figure LCD screen is displaying ‘5’, because this picture was taken after pressing ‘5’ from the keypad.

In the above circuit, RD0, RD1 and RD4:7 pins are used to interface LCD with PIC16F877. LCD is used here just to show the pressed key value. 8 pins of PORTB are used to interface 4×4 keypad. 4 pins are used to attach columns and 4 pins are used to attach rows and scanning algorithm code is used to check for any pressed key.

Leave a Comment

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