This PIC microcontroller tutorial provides a simple method to interface any keypad (e-g 4Γ4 or 4Γ3 etc)Β with PIC16F877 microcontroller.
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.
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.
Code
The main function code is shown below.
Downloads
Keypad interfacing code using PIC16F877 was compiled inΒ MPLAB v8.85 with HI-TECH C v9.83 compiler and simulation was made in Proteus v7.10.Β To download code andΒ ProteusΒ simulationΒ click here.
For more detail: How to interface keypad with PIC16F877