Spread the love

keypad interfacing with ARM7 ( LPC2148 )

____________________________________________________________________________________________________


  • What is keypad(keyboard) ? – What you probably have in front of you, is a keyboard with more than 100 keys on it… If you are not familiar with the key matrices, then you may think that inside this keyboard, there is a chip that has at least the same number of inputs to read each key separately. Well, this is not true…

keypad interfacing with ARM7 ( LPC2148 )

  • What are the key matrices?–   The matrices are actually an interface technique. According to this technique, the I/O are divided into two sections: the columns and the rows. You can imagine a matrix as an excel sheet. Here is a 4 x 4 matrix. The A,B,C and D are the columns and the 1,2,3 and 4 are the rows. There are 16 knots that the rows and columns intersect. To make a keypad matrix, we will have to connect a switch to each knot. The switch will have a push-to-make contact. When the operator pushes this switch, it will connect the column and the row that it corresponds to.

keypad-schematic

  • How does keypad matrix works? –   To understand the operation principle, i will re-draw the above matrix without colors as you can see on above pic. I will also put connection switch to each row and column wire and show practical hardware pic. For the above 16-button 4×4 matrix, 8 pins of the microcontroller will be used. The first 4 pins will be OUTPUTS (gives logic ‘1’)  and will be connected to the COLUMN wires, while the other 4 pins will be INPUTS (logic ‘0’) and will be connected to the ROW wires. The matrix is controlled by a microcontroller. The OUTPUTS of the microcontroller will NOT all have power at the same time. The outputs will go high one by one in cycle. This happens many times per second.  When operator press switch 11 (highlighted in red color), column C and row 3’s connection established, current pass from column C to row 3, and in actual sense row 3 read logic ‘1’ from column D and microcontroller manipulate this connection and do work as we decided in programming.

1332_MED

  • Applications –  As you can see on above pics keypad is used in ATMs, cell phones and where multi parameter want to input.

1. Circuit Diagram Of LCD and KEYPAD Interfacing With ARM7 ( LPC2148 )

Circuit Diagram Of LCD and KEYPAD Interfacing With ARM7 ( LPC2148 )

___________________________________________________________________________________________________

 

1. Program Of  LCD and KEYPAD Interfacing With ARM7 ( LPC2148 )

/******************************************************
IDE :- Keil
DEVELOPED BY:- FIRMWARE DEVELOPER (www.firmcodes.com)
WHAT PROGRAM DO:- PROGRAM IN WHICH DATA ENTERED FROM KEYPAD 
DISPLAYED ON LCD CONNECTED WITH ARM7(LPC2148)
******************************************************/

#include <lpc21xx.h>

#define LCD (0xff<<8)
#define RS (1<<16)
#define RW (1<<17)
#define EN (1<<18)

#define r1 (1<<16)
#define r2 (1<<17)
#define r3 (1<<18)
#define r4 (1<<19)
#define c1 (1<<20)
#define c2 (1<<21)
#define c3 (1<<22)
#define c4 (1<<23)

void delay(unsigned int time);           // variable delay function

void lcd_ini(void);
void lcd_print(char *str);
void lcd_cmd(unsigned char command);
void lcd_dat(unsigned int data);

unsigned char keypad (void);
void keypad_delay(void);

int main (void)
   {
        PINSEL0 = 0x00000000;
        IODIR0 = 0Xffffffff;
        PINSEL1 = 0x00000000;
        IODIR1 = 0x00f00000;
        
        lcd_ini();
        lcd_print("Press any key");
        lcd_cmd(0xc0);

        while(1)
          {
                lcd_dat(keypad());
          } 
        return 0;
   }

void keypad_delay(void)
   {
        unsigned int t1,t2;
        for(t1=0;t1<300;t1++)                 
                for(t2=0;t2<1275;t2++);
   }



unsigned char keypad (void)
   {
        unsigned char key;
        IOCLR1|=(c1|c2|c3|c4|r1|r2|r3|r4);
        while(1)
           {
                IOCLR1|=c1;
                IOSET1|=(c2|c3|c4);                     // first column = 0
                
                if((IOPIN1&r1)==0)
                   {
                        key='7';
                        keypad_delay();
                        return key;
                   }
                else if((IOPIN1&r2)==0)
                  {
                        key='8';
                        keypad_delay();
                        return key;
                  }
                else if((IOPIN1&r3)==0)
                  {
                        key='9';
                        keypad_delay();
                        return key;
                  }
                else if((IOPIN1&r4)==0)
                  {
                        key='/';
                        keypad_delay();
                        return key;
                  }
                
                IOCLR1|=c2;
                IOSET1|=(c1|c3|c4);                     //second column = 0
                
                if((IOPIN1&r1)==0)
                  {
                        key='4';
                        keypad_delay();
                        return key;
                  }
                else if((IOPIN1&r2)==0)
                  {
                        key='5';
                        keypad_delay();
                        return key;
                  }
                else if((IOPIN1&r3)==0)
                  {
                        key='6';
                        keypad_delay();
                        return key;
                  }
                else if((IOPIN1&r4)==0)
                  {
                        key='*';
                        keypad_delay();
                        return key;
                  }
                
                IOCLR1|=c3;
                IOSET1|=(c1|c2|c4);                     //third column = 0

                if((IOPIN1&r1)==0)
                  {
                        key='1';
                        keypad_delay();
                        return key;
                  }
                else if((IOPIN1&r2)==0)
                  {
                        key='2';
                        keypad_delay();
                        return key;
                  }
                else if((IOPIN1&r3)==0)
                  {
                        key='3';
                        keypad_delay();
                        return key;
                  }
                else if((IOPIN1&r4)==0)
                  {
                        key='-';
                        keypad_delay();
                        return key;
                  }
                
                IOCLR1|=c4;
                IOSET1|=(c1|c2|c3);                     //forth column = 0

                if((IOPIN1&r1)==0)
                  {
                        lcd_cmd(0x01);
                        keypad_delay();
                        
                  }
                else if((IOPIN1&r2)==0)
                  {
                        key='0';
                        keypad_delay();
                        return key;
                  }
                else if((IOPIN1&r3)==0)
                  {
                        key='=';
                        keypad_delay();
                        return key;
                  }
                else if((IOPIN1&r4)==0)
                  {
                        key='+';
                        keypad_delay();
                        return key;
                  }
          }
   }

void lcd_cmd(unsigned char command)
  {
        IO0CLR|=(RS|RW|EN|LCD);
        IO0SET|=(command<<8);
        IO0CLR|=RS;
        IO0CLR|=RW;
        IO0SET|=EN;
        delay(2);
        IO0CLR|=EN;
        delay(3);
  }
  
void lcd_dat(unsigned int data)        
  {
        IO0CLR|=(RS|RW|EN|LCD);
        IO0SET|=(data<<8);
        IO0SET|=RS;
        IO0CLR|=RW;
        IO0SET|=EN;
        delay(2);
        IO0CLR|=EN;
        delay(3);
  }

void lcd_print(char *str)
  {
        while(*str!='\0')
          {
                lcd_dat(*str);
                str++;
          }
  }

void lcd_ini(void)
  {
        delay(5);
        lcd_cmd(0X38);
        lcd_cmd(0X0f);
        lcd_cmd(0X06);
        lcd_cmd(0X01);
        delay(5);
        lcd_cmd(0X80);
  }

void delay(unsigned int time)           // variable delay function 
  {
        unsigned int t1,t2;
        for(t1=0;t1<time;t1++)       
                for(t2=0;t2<1275;t2++);
  }

PROTEUS File for SIMULATION(Password Of RAR file is :-firmcodes.com)

download (1)

______________________________________________________________________________________________________

Content for the tab VIDEO