Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

pic16f84 and matrix keypad

Status
Not open for further replies.

neazoi

Advanced Member level 6
Advanced Member level 6
Joined
Jan 5, 2008
Messages
4,157
Helped
13
Reputation
26
Reaction score
15
Trophy points
1,318
Location
Greece
www.microwave.gr
Activity points
37,198
Hello,
I am thinking of making a very simple morse encoder with embedded keypad and a pic16f84.
In order to have the minimum components possible, this keypad seems promising.
You basically connect all the rows and columns to the pic port pins. Hopefully the pic16f84 has 13 I/O pins, so a 6x6 matrix can be constructed for all letters and numbers, and the remaining pic pin for the morse code output.

My question is, how should I detect which key was pressed?
Somehow I need to detect if two pins of the pic are short circuited at any time.
 

Attachments

  • proxy.gif
    proxy.gif
    7.7 KB · Views: 117

This is how this scheme works,

All rows will be fed with high, and one by one will be given low. If you press some particular key

The output will be low for the corresponding column when grounding corresponding row.
 

This is how this scheme works,

All rows will be fed with high, and one by one will be given low. If you press some particular key

The output will be low for the corresponding column when grounding corresponding row.

This is a possible solution yes, thank you. However, this requires the use of external pull-up resistors, because the pic16f84 does not have them embedded.

I was thinking of another solution where external resistors are not needed. I was thinking of somehow detect a short circuit between two pins of the micro, and this will represent a closed switch.
All rows and columnts should then be set as inputs I think and all column-row combinations should somehow be scanned.
Is that possible in this simplistic approach?

Oh, I forgot to say that it will be done in assembly.
 

You don have pull up in input pins, you cant connect 4 external resistors in place, You are coding in assembly.

Actually to sens a short circuit between controller pins you have to send a signal of some frequency in the output and you have to check in reception.

May be you can do them with timer in output side and polling in input.

But i don think 4, 0603 resistors on controller pins are going occupy lot of place.
 
  • Like
Reactions: neazoi

    neazoi

    Points: 2
    Helpful Answer Positive Rating
. I was thinking of somehow detect a short circuit between two pins of the micro, .


Hi,

Nooo... a short circuit not a good idea!

There is a good 16 key assembly here but it needs 4 pull up resistors - why is a resistor a problem, if you use smd resistors you hardly know they are their.

http://www.winpicprog.co.uk/pic_tutorial_keypad_board.htm

Also why use the oldest pic chip on the planet when there are hundreds of better ones to choose from with extra features like pulls ups, internal oscillators, adc etc and usually cheaper than an 84A
 

Ok a short circuit will burn the micro pin internals probably....
In the picture I have attached you, I am thinking of doing the next (using resistors as you suggested).

Include a small value (100R) series resistor in each column
Set all columns as outputs
Set all rows as inputs
Set column1 at 5v
scan rows 1 to 4 to detect which key is pressed in that column.
If a key is found then do what I want to do with that key
Then proceed to the next column and repead the process again.

Would that be ok?
 

That will not damage any pin of controller, You will need a pull up for the keyboard operation.

because The input of the controller will be in high impedance state.

I can post my keyboard.c for your understanding.

- - - Updated - - -

The monitor_keypad function has to be called continuously in while.

key press and new key variables will give you a new keypress and the position.
 

Attachments

  • keypad.zip
    1.2 KB · Views: 109

Here is one more approach

Keypad_encode.jpg

Here row line can be set for interrupt and in interrupt routine a column can be tested..
Row does go low close to 0V for around 1 ms..so it can trigger most of micro
 

Here is one more approach
You'll have to wait several ms in the interrupt routine to detect which switch is pressed. Huge waste of processor time compared to the standard method of scanning the keyboard matrix in a timer interrupt, also involving more components.
 

There is another way to do it, the code is simple but it does have some drawbacks, it is difficult to debounce.

1. Drive ALL rows high at once.
2. If ALL columns are low, no key is pressed so go back to step 1.
3. If ANY column is high, note which input it is, call it 'X'.
4. Reverse the TRIS bits to the port and drive 'X' high with other bits low.
5. Read which input is now high, call this 'Y'
6. Repeat the whole process with the pin polarities reversed, if you get the same X and Y you have good confidence they are linked together.
7. You now know X and Y so you can use a look up table to calculate which key they are both connected to.

It relies on the switch being held in the same state (pressed) while four checks are made on it, normally this will be a few hundred uS so not a problem unless you have very fast fingers! By reversing the polarity at step 6 you can avoid pull-up and pull-down resistors although they may still help. It is also immune to some sets of keys being pressed simultaneously without risking damage.

Brian.
 

There is another way to do it, the code is simple but it does have some drawbacks, it is difficult to debounce.

I would consider the method as workaround in case of forgotten pull-ups (and also using an ancient processor that hasn't it internally). In all other cases it involves useless code overhead.

The basic approach for embedded programmers should be: how to implement at simple and effective scan method with built-in debouncing.
 

There is another way to do it

There is an example of this implementation here:
https://www.edaboard.com/blog/1911/

It is particularly interesting if you plan to create multiple functions at a keyboard having limited amount of keys, so that can use some key(s) to switch to alternate mode, or even to hide a servicing mode, accessible by pressing a certain combination of keys.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top