Archive: Keypad to PIC Help

Thread Starter

Hurdy

Joined Feb 27, 2006
137
Hi everyone,

I need some help understanding how to connect up a keypad I purchased.
The keypad I am using has 8 pins that are to be interfaced with a PIC. I always assumed that I would supply the keypad with 5VDC and then via its matrix it would supply me with a digital code output dependant on what key is pressed that would be read by the PIC.

If you look on page 2 of the attached PDF I have supplied for the keypad and look at the 12 key configuration. Now I understand how the matrix works but it doesn't tell me what pin I supply 5V to.

Can anyone explain to me how the keypad works if I have got it wrong and which pin I connect the supply to please.

Thank you for your time,

Rob
 

Attachments

beenthere

Joined Apr 20, 2004
15,819
Hi,

You only get a code out if you also use the keypad decoder accessory. Otherwise, you have a 4 X 3 matrix which will need external logic and a few resistors to determine which key has been pressed. Connecting a pin to five volts won't be useful at this stage.
 

pebe

Joined Oct 11, 2004
626
If you are reading the keypad output with a PIC you won't need a decoder - you do the decoding in software.

Connect pins 1 to 4 on the keyboard to four pins of the PIC configured as outputs, and pins A to D to four pins configured as inputs with pulldowns. Then write your program so pin 1 is set high and look for a high on pins A to D, in turn. If you find a high on pin C then you know that the button of column 1 row 3 has been pressed. Repeat with outputs on pins 2, 3, and 4 in turn, looking for a high input on A to D. Then repeat the scanning process.
 

hgmjr

Joined Jan 28, 2005
9,027
I agree with the other responders.

You have a couple of choices as they have remarked. You can either surround the keypad with the appropriate hardware and preprocess the information before feeding it to the PIC or you can connect the keypad to your PIC and the decoding with software.

There are keypad encoders such as the 74C923 that you can use if you decide to do the encoding externally before you connect to the PIC. Digikey has these parts in stock.

hgmjr (900)
 

Thread Starter

Hurdy

Joined Feb 27, 2006
137
Ok guys thank you for the advice.

I have decided to purchase a 74C922 to with my Storm keypad.

Datasheets can be found here:
http://www.storm-interface.com/dyncat.cfm?catid=19030
http://www.fairchildsemi.com/ds/MM/MM74C922.pdf

The decoder talks about needing some kind of oscillator. I cant seem to find any info on what value oscillator to use in the datasheet for the encoder.
Anyone know what I should use?

I understand how the Inputs Row Y's and column X's work, but I dont understand what I connect to Keybounce mask, Output Enable, oscillator and Data Available.

There are some circuits shown within the datasheet for the encoder, anyone able to advise me on what one will suit my needs?

Basically all I want to do is read in from the keypad what key is pressed (only one at a time should be pressed) and then send the 4bit data output to a PIC which will execute a certain routine dependant on the encoders output data.

Thank you for your time,

Rob
 

Thread Starter

Hurdy

Joined Feb 27, 2006
137
I made the same post on Microchips forum and I was told do something along the lines of the following datasheet. Take a look at page 2.

http://ww1.microchip.com/downloads/en/AppNotes/00557d.pdf

I was told to put in some resistors and make 4 pins of the PIC LOW and 4 pins HIGH then read in the value from the pins set LOW.

The thread can be found here: http://forum.microchip.com/tm.aspx?m=198408&mpage=1&key=&#199841

Could someone draw me a quick sketch of how exactly to implement this circuit just for the keypad please. I dont need the 7 Segment multiplexing part of the circuit. Just need a method of connecting a Keypad to my PIC.

Thank you for your time.
 

pebe

Joined Oct 11, 2004
626
Paulbergsman told you on the Microchip forum of the same method I outlined to you in my post above. That is, you take 4 output lines from the PIC to scan columns and 4 input lines from the PIC to detect the row of the key pressed. It requires 8 lines in all, a very short bit of programming, and no extra cost.

The method using the separate decoder chip you show does the same function and presumably outputs to the PIC the chosen key as a 4 bit binary number on 4 lines.

So you have the option. Use 8 lines of the PIC and the software shown by paulbergsman, or use 4 lines of the PIC and the extra cost of the decoder and oscillator. The choice is yours.
 

Thread Starter

Hurdy

Joined Feb 27, 2006
137
I have decided to use a Key Encoder 74C922 for ease of programming.

My keypad datasheet says the maximum debounce time for my keypad is 5ms. For the encoder I need a keybounce mask oscillator but it doesn't specify a capactor value to use with it for its RC oscillator.
The datasheet gives me this formula:


T1 =​
T2 = RC, T3 = 0.7 RC, where R = 10k and C is external capacitor at KBM input.

So, because my keypad has a max debounce time of 5ms I need a capactor that will allow me to mask out the first 5ms so I know for certain I have a proper key press.

Would you say I am right so far?

My calculation works out like this: 0.7 * 0.000001 * 10,000 = 0.007 = 7ms.

If I use a 1uF capacitor in my RC oscillator then I will have a pretty good debounce mask, correct?

Thank you for your time.
 

Thread Starter

Hurdy

Joined Feb 27, 2006
137
T1 = T2 = RC

T/R = C

0.005/10,000 = 0.0000005 F

I may have this completly wrong. Can someone please take a look at the datasheet for me and see how to calculate the debounce oscillator C for me please?

Thank you.
 

hgmjr

Joined Jan 28, 2005
9,027
Hurdy,

My approach would be to decide what scan rate you would prefer to use and then choose the C needed from looking at the graph on page 7. I would then select a value for the debounce capacitor as 10 times that value.

Keep in mind that it would be better to scan slowly since your PIC needs to reserve some of its horsepower for doing something with the key that was pressed.

hgmjr
 

Thread Starter

Hurdy

Joined Feb 27, 2006
137
oh I didn't see those graphs. I have to shoot out now and go to class, but when I get back I will take a better look.

Thank you hgmjr, I will get back to what you said shortly.
 

Thread Starter

Hurdy

Joined Feb 27, 2006
137
hgmjr,

What would you suggest as an appropriate oscillator speed?
I have never used a keypad before, so I would have just taken a middle ground on the graph and gone for a 0.2uF capacitor to give a scan frequency of around 300Hz.

Should I go slightly faster do you think?

I am using a 20MHz Crystal with my PIC.
 

hgmjr

Joined Jan 28, 2005
9,027
hurdy,

I would increase the frequency to 1Khz. Keep in mind that the debounce cap will decrease the responsiveness somewhat so it might be better to start with a little higher scan frequency.

hgmjr
 

Thread Starter

Hurdy

Joined Feb 27, 2006
137
Ok excellent.

I will set scan freq to 1Khz and have a debounce capacitor value 10 times as large.

Thank you hgmjr. I am sorry about having so many questions. I am just a bit of a newbie wanting to make sure I get my circuit right before I spend money ordering parts, being a poor student and that.

Your help is much appreciated.
 

Nomad

Joined Oct 21, 2007
43
I know this thread is quite old but, the folks over at picbasic.co.uk forums have some slick for interfacing buttons and keypads to pics. six buttons on one pin, 4x4 matrix on 2 pins. these using some resistors and either an ADC input or the POT command.
 
Top