Keil Logo

Strugling to interface 4x8 keypad with LPC2148

Next Thread | Thread List | Previous Thread Start a Thread | Settings

Details Message
Read-Only
Author
nihal Shaikh
Posted
24-May-2011 09:07 GMT
Toolset
ARM
New! Strugling to interface 4x8 keypad with LPC2148

Hi Friends, I am new to ARM. I have a project where i am trying to interface the keypad with controller. After a try of two days i thought i will try to take help from you guys....if somebody can refer me to any tutorial on this subject ...going to be a great help for me. I have tried to find any application note based on this but in a vain never found any thing after lot of googling.
Guys please help me! Just guide me to some site where they have discussed any matrix keypad interfacing with LPC2148 or any other ARM controller.

Thank you!

Read-Only
Author
Andrew Neil
Posted
24-May-2011 09:21 GMT
Toolset
ARM
New! RE: I am new to ARM

Are you familiar with any other microcontroller?

Do you understand the basic principles of how to scan a switch matrix?
These principles will be independedent of what technology - microcontroller or otherwise - you use.

Have you spent time studying how to use the GPIO on an LPC2148?
eg, blinking a LED (output) and detecting a single switch (input)?
These, again, are fundamental principles - once you have mastered them, you should be able to apply them to the switch matrix problem...

There are plenty of examples of using the LPC2148 on this site, on the NXP site, and on many other websites...

Don't forget to check out the application notes, tutorials, etc, on the NXP site.

http://www.lmgtfy.com?q=LPC2148+switch+matrix
http://www.lmgtfy.com?q=microcontroller+switch+matrix

Read-Only
Author
Per Westermark
Posted
24-May-2011 10:57 GMT
Toolset
ARM
New! RE: I am new to ARM

LOL.

Google have thousands of descriptions of how to scan keypads. Must be hundreds of good descriptions.

And best of all - it doesn't matter what microcontroller, if we ignore microcontrollers that happens to have hardware-controlled keypad scanning.

After having isolated the code that sets pins and reads back states of pins, the code for scanning a keypad on a 8051 is just about identical to the code for an ARM or a MIPS or a PPC or a PIC or an AVR or a Z80.

So:
1) Learn the concept of how keypads are scanned.
2) Learn the relevance of debounce.
3) Learn the difference between handling single-key or multi-key presses.
4) Learn how _your_ processor configures processor pins.
5) Learn how _your_ processor sets processor pins.
6) Learn how _your_ processor reads back processor pins.
7) Learn how _your_ processor measures time (remember debounce?)

Combine, shake a bit and then test and release.

Don't see problems. See possibilities. This is a general exercise all schools have quite early in the microcontroller courses. That should be a hint that it is considered rather basic. I.e. not hard to learn. Not hard to do. And all the students are expected to manage the task on their own. Are you different from all the hundred thousands of students who does this exercise every year?

Read-Only
Author
nihal Shaikh
Posted
24-May-2011 13:12 GMT
Toolset
ARM
New! RE: I am new to ARM

Thanks Per Westermark, I really appreciate your efforts! and thanks for this wonderful motivational speech.......thanks!

Read-Only
Author
nihal Shaikh
Posted
24-May-2011 13:21 GMT
Toolset
ARM
New! RE: I am new to ARM

Thanks Andrew Neil, Thanks for those links it really helped me.....thanks a lot!

Read-Only
Author
Andrew Neil
Posted
24-May-2011 13:58 GMT
Toolset
ARM
New! RE: those links it really helped me

Those links simply showed you how to type key words like "switch matrix" into google, and press the 'Search' button.

Had it really not occurred to you to do that before?!

Read-Only
Author
nihal Shaikh
Posted
24-May-2011 17:45 GMT
Toolset
ARM
New! RE: those links it really helped me

i was using the word like matrix keypad, interfacing keyboard with LPC2148..etc.

Read-Only
Author
Per Westermark
Posted
24-May-2011 22:24 GMT
Toolset
ARM
New! RE: those links it really helped me

"interfacing keyboard with LPC2148"

Haven't you considered using the word "microcontroller" instead of "LPC2148"? As I did write, the concept and the algorithmic part of the source code is very little affected by used processor.

You get further by trying to break down problems into their smallest ports. So both looking about microcontrollers interfacing keyboards, and as a separate issue how to accessing I/O pins of LPC2148 (or maybe LPC21xx) and a third thing to look for good time delays for LPC21xx.

If you do google for "interfacing keyboard with LPC2148" you may get hits. You may get great hits. But you get much, much, much, much fewer hits than if you google for a more generic implementation. This means that if you are looking for code, you may find much more beautiful code. Much better working code. Much better documented code. Much better textual descriptions of the concepts involved.

In the end, the best code is not the first one you find. It's way better to get multiple options and figure out which code is written by the most competent developer. Even if that code requires you to perform minor modifications to port the code to your specific compiler or your specific processor.

Read-Only
Author
naresh babu
Posted
4-Oct-2011 07:59 GMT
Toolset
ARM
New! RE: Strugling to interface 4x8 keypad with LPC2148

iam sending you the code which you need so after getting executed send me reply wish u the best
bye source code
# Project Code : MA-Exp
# # KBD C file
# # Copyright (C) 2007 SPJ Systems Pune,India
# All rights reserved.
# # -------
# History
# -------
# Date |Release|Author| Changes
# DD-MM-YYYY | | |
# -------------------------------------------------------------------------------------
# 08.03.2007 | 0.1 | NSG | Initial Version.
# | | |
# | | |
# | | |
****************************************************************************************/
#include <Philips\LPC2148.h>
#include "KBD.h"
#include "TYPE.h"

#define RET0 0x00010000 // P1.16
#define RET1 0x00020000 // P1.17
#define RET2 0x00040000 // P1.18
#define RET3 0x00080000 // P1.19

#define ALL_RET (RET0|RET1|RET2|RET3)

#define SCAN0 0x00100000 // P1.20
#define SCAN1 0x00200000 // P1.21
#define SCAN2 0x00400000 // P1.22
#define SCAN3 0x00800000 // P1.23

const uint32 KBD_u32scanport1[4]={SCAN0,SCAN1,SCAN2,SCAN3};

const uint32 KBD_u32retport[4]={RET0,RET1,RET2,RET3};

#define CRYSTAL_FREQUENCY_IN_HZ 12000000
#define PLL_MULTIPLIER 1
#define DEL_LOOPS CRYSTAL_FREQUENCY_IN_HZ*PLL_MULTIPLIER/500000

int32 KBD_i32keydown;

void KBD_cdelay(void)
{ int32 i32i; for (i32i=0; i32i<5*DEL_LOOPS; i32i++) {}
}

void KBD_Init(void)
{ //IO1DIR &= (0xFFFFFFFF^(RET0|RET1|RET2|RET3)); //printf("IO1PIN %02bx\n",IO1PIN) ;

KBD_i32keydown=-1;
}

int32 KBD_i32the_sc ;

int32 KBD_kbhit (void)
{ int32 i32sc , i32sc0 ; int32 i32ret, i32ret0 ;

for(i32sc = 0;i32sc < 4 ; i32sc ++) { IO1DIR = KBD_u32scanport1[i32sc] | (0x03000000) ; // For RS and RW of LCD IO1CLR = KBD_u32scanport1[i32sc] ;

KBD_cdelay() ; i32ret = IO1PIN & ALL_RET ;

if (KBD_i32keydown == -1) { switch(i32ret) { case (ALL_RET & (~RET0)) : KBD_i32the_sc = i32sc ; KBD_i32keydown = (i32sc * 4) ; //printf("RET0") ; //printf("%u\n",i32sc) ; return 1 ; case (ALL_RET & (~RET1)) : KBD_i32the_sc = i32sc ; KBD_i32keydown = (i32sc * 4) + 1 ; //printf("RET1") ; //printf("%u\n",i32sc) ; return 1 ; case (ALL_RET & (~RET2)) : KBD_i32the_sc = i32sc ; KBD_i32keydown = (i32sc * 4) + 2 ; //printf("RET2") ; //printf("%u\n",i32sc) ; return 1 ; case (ALL_RET & (~RET3)) : KBD_i32the_sc = i32sc ; KBD_i32keydown = (i32sc * 4) + 3 ; //printf("RET3") ; //printf("%u \n",i32sc) ; return 1 ;

}

} else { // i.e. key is already pressed, wait until it is released if (i32sc == KBD_i32the_sc) { if (i32ret == ALL_RET) { KBD_i32keydown = -1 ; // key has been released } } } } return 0 ;
}

int32 KBD_rdkbd(void)
{ while(!KBD_kbhit()) {} return KBD_i32keydown ;
}

kbd.h file code

#ifndef KBD_H
#define KBD_H

void KBD_Init(void);
int KBD_kbhit(void); // returns true if a key is pending
int KBD_rdkbd(void); // waits until a key is pressed and then returns the keycode

#endif /* KBD_H */

type.h file code

#ifndef TYPE_H
#define TYPE_H
/********************************************************************************************************
# Project Code : P001_sample
# # Common H file
# # Copyright (C) 2007 SPJ Systems Pune,India
# All rights reserved.
# # -------
# History
# -------
# Date |Release|Author| Changes
# DD-MM-YYYY | | |
# ----------------------------------------------------------------------------
# 08.03.2007 | 0.1 | ST | Initial Version.
# | | |
# | | |
# | | |
********************************************************************************************************/
#ifndef NULL
#define NULL (0)
#endif
#ifndef FALSE
#define FALSE (0)
#endif
#ifndef TRUE
#define TRUE (1)
#endif

/* Arm data types */
typedef unsigned char uint8;
typedef unsigned short int uint16;
typedef unsigned int uint32;
typedef char int8;
typedef short int int16;
typedef int int32;
typedef unsigned char BOOL;
/*
Data Type Actual ‘C’data type Bytes allocated.
uint8 unsigned char 1
int8 char 1
uint16 unsigned short 2
int16 short 2
uint32 unsigned long 4
int32 long 4
float32 32 bit float 4
float64 double 8
*/
/*
Data type Short form
int8 i8
uint8 u8
int16 i16
uint16 u16
int32 i32
uint32 u32
float32 fl32
float64 fl64
pointer ptr
bool b
*/
#endif // TYPE_H

Next Thread | Thread List | Previous Thread Start a Thread | Settings

  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.