This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

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!

Parents
  • 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

Reply
  • 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

Children
No data