Spread the love


keypad interfacing with ATmega16

____________________________________________________________________________________________________


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

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

Circuit Diagram Of LCD and KEYPAD Interfacing With ATMEGA16___________________________________________________________________________________________________

 

1. Program of Data Displayed on LCD entered from KEYPAD  interfacing With ATmega16

/******************************************************
www.firmcodes.com
DEVELOPED BY:- FIRMWARE DEVELOPER
WHAT PROGRAM DO:- DATA ENTERED FROM KEYPAD DISPLAYED ON LCD
******************************************************/

#include<avr/io.h>

#include<util/delay.h>

#define lcd PORTA
#define prt PORTC
#define ddr DDRC
#define pin PINC

unsigned char  key[4][4]={'7','8','9','/',
                          '4','5','6','x',
                          '1','2','3','-',
                          0x01,'0','=','+'};
                          
unsigned char coll,ro_loc;
unsigned char z='m';

char keypad1();

void cmd(unsigned char x);

void lcd_display(unsigned char x);

void lcd_ini();

void lcd_str(unsigned char *str);

void main()
  {
     int i=0;
     DDRA=0XFF;
     DDRB=0XFF;
     DDRC=0XF0;
     lcd_ini();
     while(1)
       {
          i++;
          keypad1();
          lcd_display(z);
          _delay_ms(300);
          if(i==16)
             cmd(0xc0);
          else if(i==32)
           {
                i=0;
                cmd(0x01);
           }

      }
  } 


char keypad1()
  {
     prt=0xFF;
     ddr=0xF0;
     while(1)
       {
          prt=0xef; 
          coll=(pin & 0x0f);
          if(coll!=0x0f)
            {
                 ro_loc=0;
                 goto xx;  
            }
          prt=0xdf;
          coll=(pin & 0x0f);
          if(coll!=0x0f)
            {
                ro_loc=1;
                goto xx;  
            } 
          prt=0xbf;
          coll=(pin & 0x0f);
          if(coll!=0x0f)
            { 
                ro_loc=2;
                goto xx;
            } 
          prt=0x7f;
          coll=(pin & 0x0f);
          if(coll!=0x0f)
            {
                ro_loc=3;
                goto xx;
            } 
    
         xx:;
         if(coll==0x0e)
           {
               z=(key[0][ro_loc]);
               return z; 
           }
         else if(coll==0x0d)
           {
               z=(key[1][ro_loc]);
               return z;
           }
         else if(coll==0x0b)
           {
                z=(key[2][ro_loc]);
                return z;
           }
         else if(coll==0x07)
           {
                z=(key[3][ro_loc]);
                return z;
            }
      } 
  }

void cmd(unsigned char x)
   {
       lcd=x;
       PORTB=(0<<0);
       PORTB=(0<<1);
       PORTB=(1<<2);
       _delay_ms(10);
       PORTB=(0<<2);

   }

void lcd_display(unsigned char x)
   {
      lcd=x;
      PORTB=(1<<0);
      PORTB=(0<<1)|(1<<0);
      PORTB=(1<<2)|(0<<1)|(1<<0);
      _delay_ms(20);
      PORTB=(0<<2)|(0<<1)|(1<<0);
   }

void lcd_ini()
   {
      cmd(0x38);
      cmd(0x0e);
      cmd(0x01);
      cmd(0x06);
      cmd(0x80);
   }

void lcd_str(unsigned char *str)
   {
      while(*str!='\0')
        {
            lcd_display(*str);
            str++;
        }
   }

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

download (1)

______________________________________________________________________________________________________

Content for the tab VIDEO