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 5
Joined
Jan 5, 2008
Messages
3,846
Helped
13
Reputation
26
Reaction score
10
Trophy points
1,318
Location
Greece
Activity points
34,872
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: 27

andre_luis

Super Moderator
Staff member
Joined
Nov 7, 2006
Messages
9,308
Helped
1,166
Reputation
2,351
Reaction score
1,152
Trophy points
1,403
Location
Brazil
Activity points
54,233
I suggest you take a look on code posted here and check if the proposed solution fit to your need:
 

Venkadesh_M

Advanced Member level 4
Joined
Jun 26, 2013
Messages
1,375
Helped
258
Reputation
516
Reaction score
254
Trophy points
83
Location
Coimbatore, India
Activity points
6,738
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.
 

neazoi

Advanced Member level 5
Joined
Jan 5, 2008
Messages
3,846
Helped
13
Reputation
26
Reaction score
10
Trophy points
1,318
Location
Greece
Activity points
34,872
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.
 

Venkadesh_M

Advanced Member level 4
Joined
Jun 26, 2013
Messages
1,375
Helped
258
Reputation
516
Reaction score
254
Trophy points
83
Location
Coimbatore, India
Activity points
6,738
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

wp100

Advanced Member level 5
Joined
May 15, 2009
Messages
3,056
Helped
883
Reputation
1,781
Reaction score
736
Trophy points
113
Location
Prime Meridian
Activity points
0
. 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.

https://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
 

neazoi

Advanced Member level 5
Joined
Jan 5, 2008
Messages
3,846
Helped
13
Reputation
26
Reaction score
10
Trophy points
1,318
Location
Greece
Activity points
34,872
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?
 

Venkadesh_M

Advanced Member level 4
Joined
Jun 26, 2013
Messages
1,375
Helped
258
Reputation
516
Reaction score
254
Trophy points
83
Location
Coimbatore, India
Activity points
6,738
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: 5

pm777

Newbie level 1
Joined
Apr 21, 2015
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
5
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
 

FvM

Super Moderator
Staff member
Joined
Jan 22, 2008
Messages
49,148
Helped
14,386
Reputation
29,036
Reaction score
13,140
Trophy points
1,393
Location
Bochum, Germany
Activity points
283,276
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.
 

betwixt

Super Moderator
Staff member
Joined
Jul 4, 2009
Messages
15,210
Helped
4,958
Reputation
9,938
Reaction score
4,781
Trophy points
1,393
Location
Aberdyfi, West Wales, UK
Activity points
129,160
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.
 

FvM

Super Moderator
Staff member
Joined
Jan 22, 2008
Messages
49,148
Helped
14,386
Reputation
29,036
Reaction score
13,140
Trophy points
1,393
Location
Bochum, Germany
Activity points
283,276
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.
 

betwixt

Super Moderator
Staff member
Joined
Jul 4, 2009
Messages
15,210
Helped
4,958
Reputation
9,938
Reaction score
4,781
Trophy points
1,393
Location
Aberdyfi, West Wales, UK
Activity points
129,160
It can be implemented with less code than a conventional scanned matrix but I fully agree it should be used as a last resort, especially as the 16F84 has internal pull-ups to use.

Brian.
 

andre_luis

Super Moderator
Staff member
Joined
Nov 7, 2006
Messages
9,308
Helped
1,166
Reputation
2,351
Reaction score
1,152
Trophy points
1,403
Location
Brazil
Activity points
54,233
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

Top