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.

Matrix keypad - confusion with the keys

Status
Not open for further replies.

lats

Full Member level 4
Joined
Oct 27, 2005
Messages
216
Helped
13
Reputation
26
Reaction score
6
Trophy points
1,298
Activity points
2,945
Matrix keypad

Hi,

I'm always confused with the keys. This time the confusion is on the peaks. I'm interfacing a 4x4 keypad with uC. I have made the code which displays the key number that has been pressed & is working absolutely fine. In this code i'm waiting continously for a key to be pressed .
I have to implement this in my project where this keypad will be used to enter password, certain physical values, etc. Now the problem is i can't wait continously for a key to be pressed, so should i call this function from Timer periodically or should I generate a common Interrupt for these 16 keys.

Second problem, if I have to enter a value lets say "1652" how do i need to read the keypad. I mean how should i alot the value, should I multiply the first key value with 1000 then second with 100 then third with 10 & finally add these all four, like 1*1000 + 6*100 + 5*10 + 2 = 1652


If someone can share a part of his code with me i'll be really thankful.


Thanks a lot all of you.
 

Re: Matrix keypad

for your first problem you can compare the port with default value(say 11110000b) in the timer interrupt occurring periodically
and then if key is pressed call the key find subroutine or function
but this will increase your interrupt latency
so instead you can set a flag and check for that flag if its set then your key is pressed so check it this will reduce the load on the timer interrupt


for the second question please tell which controller and which language
 

    lats

    Points: 2
    Helpful Answer Positive Rating
Re: Matrix keypad

you need to describe what microcontroller you are using and the language you code it. i.e. c or assembly
 

Matrix keypad

Thanks sau for replying, but where & when should i set the flag.
I'm using PIC18F4550 & programming in 'C'


Thanks a lot for replying.
 

Re: Matrix keypad

in your timer interrupt routine when there will be a mismatch in the value (11110000b) i.e if a key is pressed you set a flag

and in your main loop always check for that flag with your other measurements and tasks
if the flag is set then the key if pressed
so then you have to call the keyfind function to find which key is pressed
 

    lats

    Points: 2
    Helpful Answer Positive Rating
Matrix keypad

Thanks again for replying sau. But in case if the main function is busy with some other part, & by that time the user leaves the key pressed how will the controller know which key was pressed. actually this is what that always troubles me.

Added after 1 minutes:

sau you are from india & me too can u please give me your mobile no. i'll call you if you don't mind.
 

Re: Matrix keypad

how much time you required in doing other tasks

because the micro controllers are using microseconds in performing other tasks

what are the other things you are doing in your system
or if the rime is not sufficient for you try increasing the crystal speed (if you are not using UART)

I am from MP India you are from where
 

    lats

    Points: 2
    Helpful Answer Positive Rating
Matrix keypad

Haryana,
 

Re: Matrix keypad

so please tell me about your other tasks used in the system
so we can decide what to do in the interrupt
 

Re: Matrix keypad

On each timer interrupt, scan the next row of your matrix. After scanning all rows set a variable with the value of the key pressed or to zero if none pressed. Your main loop can check this variable to see if it is non zero which means that a key was pressed. If your main loop is too busy for this, then in your interrupt routine you must write the variable into a buffer which can be read later. The size of the buffer depends on how often the keys are pressed vs how often the main loop can read it
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top