Interfacing a 12 Button Keypad with Microcontroller

Today we will look at Interfacing a 12 Button Keypad with Microcontroller. Keypad is a set of button connected in rows and columns. One needs to scan all rows and columns to check which particular button was pressed. This is explained with the help of 12 button keypad and a BCD 7 segment display in the following example. Note:

  • 7-Segment will be initialized to F
  • 7- Segment will display A when * will be pressed.
  • 7-Segment will display B when # will be pressed.

The followning code written in VMLAB and tested in Proteus

// ***********************************************************
// Project:
// Author:
// Module description:
// ***********************************************************

#include <avrio.h>              // Most basic include files
#include <avrinterrupt.h>       // Add the necessary ones
#include <avrsignal.h>          // here

// Define here the global static variables
//
int My_global;

// Interrupt handler example for INT0
//
SIGNAL(SIG_INTERRUPT0) {

}

// It is recommended to use this coding style to
// follow better the mixed C-assembly code in the
// Program Memory window
//
void my_function(void) {  // Put the open brace '{' here

   asm("nop");          // Inline assembly example
}

// ***********************************************************
// Main program
//
int main(void) {
	DDRC=0X00;
	PORTC=0XFF;
	DDRD=0XFF;
	PORTD=0XFE;
	DDRA=0XFF;
	PORTA=0X0F;

   while(1) {             // Infinite loop; define here the

          switch(PORTD)
          {
          case 0XFE: PORTD=0XFD;
          break;
          case 0XFD: PORTD=0XFB;
          break;
          case 0XFB: PORTD=0XF7;
          break;
          case 0XF7: PORTD=0XFE;
          break;
          }
          if(PINC!=255)
          {
            switch (PINC)
            {
            case 254:
          	switch(PORTD)
          	{
          		case 0XFE : PORTA = 0X01;
          	   break;
          	   case 0XFD : PORTA = 0X04;
          	   break;
          	   case 0XFB : PORTA = 0X07;
          	   break;
          	   case 0XF7 : PORTA = 0X0A;
          	   break;
           }//switch end
          break;
          case 253:
          switch(PORTD)
          {
           case 0XFE: PORTA=0X02;
           break;
           case 0XFD: PORTA=0X05;
           break;
           case 0XFB: PORTA = 0X08;
           break;
           case 0XF7: PORTA = 0X00;
           break;
           }//switch end
           break;
           case 251:
           switch(PORTD) {
           case  0XFE: PORTA=0X03;
           break;
           case  0XFD: PORTA= 0X06;
           break;
           case  0XFB: PORTA= 0X09;
           break;
           case 0XF7: PORTA = 0X0B;
           break;
           }//switch end
           break;
         }
       }
   }
}

Files included:

  • Code Project Files
  • Proteus Test Bench File

Download

Let's Discuss

  • http://www.quickautoinsurancequoteonline.com/ quick auto insurance quote online

    My favorite past-time is reading informative articles. Your article is one of the most interesting I’ve read. Your insightful, fresh views gave me many things to think about. Thank you.

  • http://www.shopcabledeals.com/time-warner-internet/ Time Warner Internet

    I’ve really enjoyed reading and reviewing the points in your well-written content. Thank you for presenting this useful information in an interesting and understandable format.