How to interface keypad with PIC12F675

This post provides a simple method to interface any keypad (e-g 4Γ—4 or 4Γ—3 etc)Β with PIC12F675 microcontroller. The code for PIC12F675 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.

interface keypad with PIC12F675

In this post, it is assumed that you know,

  • How to use ADC of PIC12F675 microcontroller. If you don’t then please readΒ this page.
  • How to interface LCD with PIC12F675 microcontroller. If you don’t then please readΒ this page.

The circuit required to interface keypad with PIC12F675 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 β€˜1’, because this picture was taken after pressing β€˜1’ from the keypad.

In the above circuit, PIC12F675 is running on it’s internalΒ 4MHzΒ oscillator. GP0, GP1 and GP2 pins are used to interface LCD through 4094 IC as explained in the β€œPIC12F675 LCD Interfacing Code + Proteus Simulation” post. LCD is used here just to show the pressed key value. Usually 8 pins are used to interface 4Γ—4 keypad with any microcontroller. 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.

But PIC12F675 doesn’t have 8 pins. By using some diodes we can generate different voltage on each pressed key on a single wire (as shown above in the circuit). And then by using built-in ADC of PIC12F675 we can read this voltage value to determine pressed key easily. In this way by using only one pin of PIC12F675 we can successfully interface keypad with it.Β To interface keypad, only GP4(AN3)Β pinΒ is being used in the circuit shown above.

In the above circuit, rows of the keypad have 1N4007 diode attached with them. If you don’t have 1N4007 diode, then any simple 0.7 volt[1] diode can be used here. RowA has 3 diodes, RowB has 2 diodes, RowC has one diode and RowD has no diode attached with it. These diodes are pulled-up from one side by a 470 ohm resistor. Column1 wire of keypad is attached with the ground. Column2 is attached with a schottky diode[2].Β Column3 is attached with a 2.7v zener diode.Β Column4 is attached with a 3.0v zener diode. Using this circuit you can easily interface keypad with PIC12F675 microcontroller.

interface keypad with PIC12F675 schematic

Code

The code of the main function is shown below.

Downloads

Keypad interfacing code using PIC12F675 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 PIC12F675


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 *

This site uses Akismet to reduce spam. Learn how your comment data is processed.