4x4 key pad programing - please help

Status
Not open for further replies.

soul11

New Member
Hi all. I'm trying to make each button of a 4x4 keypad display 4 letters. For example when I click once it should display 1. If twice it should display A.... etc., like a mobile keypad. Can anyone help me with how to write a program using 8051, please?
 
mhh

i think you should just count pulses in a time schedule for example:
i=0
Do while time < time + 1second

if button press = true then

if i = 0 then
"1"
i=1
elseif i=1 then
"A"
i=2
elseif i = 2 then
"B"
i=3
elseif i= 3 then
"C"
end if

end if


Loop

after the second or what ever the do while will be exited and the sources given to the next character

untherstand?/

Tks
 
the problem is that im using the assembly language. But i got the idea of what you wrote. i will try write a program with assembly language using your idea.

thank you very much tks.
 
Hiya Soul,
Since your using assembly check out Nigel's tutorials if you haven't yet, 1 section deals with a 4x4 keypad and coupled with all the other tutorials it's one of the best guides to pic programming in assembly on the net.

Cheers Bryan
 
yeah,

i wrote it also with the idea that you should convert it to ASM.

Anyway i think to explain this kind of Tricks the best thing is to do it in basic because else you will see some strange words and maybe you loose the clue.


You could easyly add in this loop for every button the If else structure.

the i you could it been using always, the only thing is that the second counter will be needed to be able to change the cursor,

if you are a god with asm you could make it all with lookup tables, it would make the system short of code.

with that idea in mind you only Lookup the Key number and then you automaticly calculate the i values and the next key value.

Sow with one Loop you could easyly do all the keys!!

Tks
 
yes TKS, i made a program with asm to display one character using one button. so now i will try to apply your idea and see if i can display more character using one button.

thank you TKS
 
First of all the hardware:
You need 1 port to control your keypad
I connect my keypad as follow
Column 0 to pin n.0
Column 1 to pin n.1
Column 2 to pin n.2
Column 3 to pin n.3

Row 0 to pin n.4
Row 1 to pin n.5
Row 2 to pin n.6
Row 3 to pin n.7
Where n is a number between 0 and 3, the ports of a 8051 :wink:

Every row has a pull-up resistir of 100k to Vcc so that these 4 inputs always are high.

The µC drives sequentially the for columns high. After each column it checks if one of the rows is low due to a key-press by the user.
No keys pressed: all rows high (remember the pull-up R).
One Key pressed: One row is low.
The combination of the activated Column and the Row with a low signal is unique for every key.

The assembler software........... later on :lol:
 
And now the software...

See this file as a subroutine.
You don't need to change anything to it.
Define the variables "KP_AsciiTable", "KeyPadAddress" and "KeyctrDebounce" in your main routine.

Call the routine "KP_Start" at regular time interval (use a timer interrupt routine) and check the variables "KeyRead", "KeyCode" and "KeyAscii" in your main code.
If "KP-Start" has detect a key, it will write the appropriate data in these three variables.
Do not forget to clear the "KeyRead" bit when you processed a key in your main code!!

If there's something unclear let me know... :shock:
 
Thank you very much mcs51mc.

im looking forward to it :wink: , because im really stuck at this point :cry:

thank you again
 
thank you mcs51mc.

the assembler is mixed up, but i will try to understand it.

thank you my friend
 
A little bit more code that (maybe) will help U understand the previous one :lol:

At the start you will find the declaration of some constants KeyPadAddress to Key_F. If you have other keys on your keypad change the name but not the data. e.g. If the key in col3 row3 is * instead of F, change the name Key_F to Key_Star but leave the data 000Fh unchanged.

Part 1: contains the endless loop.
If bit KeyRead is not set, there's no key pressed by the user so you can skip all the key stuff and do other things from LBL_001 on.
When the user press a key, the KeyPad module will set bit KeyRead and then you can jump into the key stuff (part 2).

Part 2: do key depending stuff
The KeyPad module writes a number from 0 to F into variable KeyCode depending on the pressed key. By comparing that variable with all the Key_0 to Key_F constants you will know what key is pressed.
Note that you don't need to check all the keys. If at a certain point in your programm you are interrested in keys 0 to 9, C and E, just check these keys only.
But don't forget to clear the KeyRead bit at the end!!!

Last Part:
Has to remain the last part in you program. The KeyPad module place an ascii character from that list into variable KeyAscii. Again, if the key in col3 row3 is * instead of F, replace that string by '0123456789ABCDE*'.
If you have an LCD in your project, you can write that variable directly to your LCD.


In the timer interrupt routine you need only one line of code for the KeyPad module:
Code:
call KP_Start
Because the module use the datapointer you have to push it onto the stack.


Remember, if your compiler understand all the definitions in the KeyPad module, you don't have to change anything in that file. Just use it as a black box in all your future projects.

Have fun ...
 

Attachments

  • mainprog-en.txt
    4 KB · Views: 454
Dear senior Members! My anme is Sajid Hussain.i am first year electrical engineering student.I have to take help for various projects that will be assigned to me so i willl be looking for your help.Thanks
 
actually i am currently working on a project Atmel 8051 I have to connect a 4X4 keypad with it . Problem is first i have to press "#" then enter the passward say "123" then press "*" if my passward is correct green LED should glow other wise red LED should glow.I have to write the C code in Keil so that i may burn it in micro controller.Kindly you all help me out in the project.As i am in first year so i dont know much about the micro controllers and key pad interfacing.thanx
 
hi! myname trantanoai,iam student tech hanoi vietnam .i have to write assemble code for the couter from 1 to 40 by 2 key up and down and interfacing led7 segment not run.u help me write code for it.thanks
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…