Interfacing Keypad3*4 with PIC16F877A

Discussion about projects that used PIC Microcontroller, Hardware Interface, Programming Algorithm and etc......

Interfacing Keypad3*4 with PIC16F877A

Postby dashboyd » Mon Nov 21, 2011 12:47 am

Hello,i am saw a code to interfacing keypad with PIC16F877A like this.The keypad is interface at port d (RD1,RD2,RD3,RD4,RD5,RD6,RD7)of the microcontroller.
Can you please explain the term (if(input(pin_d6)==0) and so on in this code?Why they were using this term?This is full code for keypad interface.This code may be useful for my project also.
CODE: SELECT_ALL_CODE
void keypad34()
{
   mydata1=0;

   //detect 1st column key press
   portd=0b11011111;
   if(input(pin_d6)==0)
   {
      mydata1='1';
   }
   else if(input(pin_d1)==0)
   {
      mydata1='4';
   }
   else if(input(pin_d2)==0)
   {
      mydata1='7';
   }
   else if(input(pin_d4)==0)
   {
      mydata1='*';
   }

   //detect 2nd column key press
   portd=0b01111111;
   if(input(pin_d6)==0)
   {
      mydata1='2';
   }
   else if(input(pin_d1)==0)
   {
      mydata1='5';
   }
   else if(input(pin_d2)==0)
   {
      mydata1='8';
   }
   else if(input(pin_d4)==0)
   {
      mydata1='0';
   }

   //detect 3rd column key press
   portd=0b11110111;
   if(input(pin_d6)==0)
   {
      mydata1='3';
   }
   else if(input(pin_d1)==0)
   {
      mydata1='6';
   }
   else if(input(pin_d2)==0)
   {
      mydata1='9';
   }
   else if(input(pin_d4)==0)
   {
      mydata1='#';
   }
dashboyd
Freshie
 
Posts: 6
Joined: Fri Aug 19, 2011 2:08 am

Re: Interfacing Keypad3*4 with PIC16F877A

Postby ABSF » Wed Nov 23, 2011 3:44 pm

I can understand why no one bothers to answer you cos this topic had appeared in this forum so many times. :o

Just do a search on the word "keypad" gave 101 matches. Do read them patiently and your answer should be there. :) :)

search.php?keywords=keypad&terms=all&author=&sc=1&sf=all&sr=posts&sk=t&sd=d&st=0&ch=300&t=0&submit=Search

Allen
The next war will determine NOT who is right BUT what is left.
User avatar
ABSF
Professional
 
Posts: 810
Joined: Wed Nov 10, 2010 9:32 am
Location: E Malaysia

Re: Interfacing Keypad3*4 with PIC16F877A

Postby zhenning » Wed Nov 23, 2011 3:57 pm

dashboyd WROTE:Hello,i am saw a code to interfacing keypad with PIC16F877A like this.The keypad is interface at port d (RD1,RD2,RD3,RD4,RD5,RD6,RD7)of the microcontroller.
Can you please explain the term (if(input(pin_d6)==0) and so on in this code?Why they were using this term?This is full code for keypad interface.This code may be useful for my project also.
CODE: SELECT_ALL_CODE
void keypad34()
{
   mydata1=0;

   //detect 1st column key press
   portd=0b11011111;
   if(input(pin_d6)==0)
   {
      mydata1='1';
   }
   else if(input(pin_d1)==0)
   {
      mydata1='4';
   }
   else if(input(pin_d2)==0)
   {
      mydata1='7';
   }
   else if(input(pin_d4)==0)
   {
      mydata1='*';
   }

   //detect 2nd column key press
   portd=0b01111111;
   if(input(pin_d6)==0)
   {
      mydata1='2';
   }
   else if(input(pin_d1)==0)
   {
      mydata1='5';
   }
   else if(input(pin_d2)==0)
   {
      mydata1='8';
   }
   else if(input(pin_d4)==0)
   {
      mydata1='0';
   }

   //detect 3rd column key press
   portd=0b11110111;
   if(input(pin_d6)==0)
   {
      mydata1='3';
   }
   else if(input(pin_d1)==0)
   {
      mydata1='6';
   }
   else if(input(pin_d2)==0)
   {
      mydata1='9';
   }
   else if(input(pin_d4)==0)
   {
      mydata1='#';
   }


the codes is checking whether the button is pressed or not. The keypad is initially pulled to vdd through resistors. any button pressed will cause the line to be pulled low =)
zhenning
Enthusiast
 
Posts: 351
Joined: Thu Dec 30, 2010 12:32 am


Return to PIC Microcontroller

Who is online

Users browsing this forum: No registered users and 5 guests

cron