How to interface 4x4 Keypad with PIC microcontroller

Status
Not open for further replies.

bskumar7080

Member level 2
Joined
Feb 8, 2010
Messages
48
Helped
4
Reputation
8
Reaction score
3
Trophy points
1,288
Location
India
Activity points
1,579
Hi all,

How to interface 4 x 4 Keypad with PIC microcontroller . How to check the 4 x 4 keypad, anyone could provide schematic.
 

Dear firend,

It is easy one. Make 4 pin as input and 4 pin as out put.


1. Make a input as high.
2.scan 4 o/p pins continuously if any of them as high read the particular key.
Just read the MikroC help or manual, It contain layout also.
 

I am using MPLab IDE, did anyone have example keypad interfacing in MPlab
 
Dear friend,

Below program is for 4*1 keypad reading.


list p=pic16f877a
#include"p16f877a.inc"
cblock 0x20
r0,r1
endc
org00
goto main
org 04h
retfie
main
bsf status,5
bcf status,6
movlw 0xf0
movwf trisb
movlw 0x00
movwf trisc
bcf status,5
bsf portb,0

top btfsc portb,4
goto l1
btfsc portb,5
goto l2
btfsc portb,6
goto l3
btfsc portb,7
goto l4
goto top

l1 movlw 0x01
movwf portc
goto top
l2 movlw 0x02
movwf portc
goto top
l3 movlw 0x03
movwf portc
goto top
l4 movlw 0x04
movwf portc
goto top
last nop
end
 

please 4*4 keypad by mplap
 

ok but it is 4*1 & i need 4*4

---------- Post added at 12:45 ---------- Previous post was at 12:42 ----------

can you help me to understand assemply program


thanks

---------- Post added at 12:47 ---------- Previous post was at 12:45 ----------

i don't understand this assemply program
 

Hai,

1. Make four pin as input and four pin as out put. (movlw 0xf0) means 7-4 pins in portb as input and 0-3 are output pins
2. Put a 1 at (bsf portb,0) IF you use 2*4 then set another portb pin like (bsf portb,1)etc...
3. Check all the input pins ( btfsc portb,4 , btfsc portb, 5 btfsc portb, 6 btfsc portb,7)
4. If any of them high print the corresponding value of key.

Actually above program is used to scan only four keys
So rest of them write yourself.
 
Reactions: PA3040

    PA3040

    Points: 2
    Helpful Answer Positive Rating
here is a procedure to read from keypad. in C language.

satA...satD means the rows. and sut1...sut4 means columns.

Code:
#define satA P2_0
#define satB P2_1
#define satC P2_2
#define satD P2_3
#define sut1 P2_4
#define sut2 P2_5
#define sut3 P2_6
#define sut4 P2_7

char tus(void)
{	
	char don = ' ';	
	 for (;;)
	 {
	   sut1=0;//1.sutunu kontrol et
		while(!sut1)
		{
			while (satA==0) {while (satA==0) if(satA==1);don='1';}	   
			while (satB==0) {while (satB==0) if(satB==1);don='4';}
			while (satC==0) {while (satC==0) if(satC==1);don='7';}
			while (satD==0) {while (satD==0) if(satD==1);don='C';}
			sut1=1;  	
		}
	
		sut2=0;//2.sutunu kontrol et
		while(!sut2)
		{
			while (satA==0) {while (satA==0) if(satA==1);don='2';}
			while (satB==0) {while (satB==0) if(satB==1);don='5';}
			while (satC==0) {while (satC==0) if(satC==1);don='8';}
			while (satD==0) {while (satD==0) if(satD==1);don='0';}
			sut2=1;
			
		}
		
		sut3=0;//3.sutunu kontrol et
		while(!sut3)
		{
			while (satA==0) {while (satA==0) if(satA==1);don='3';}
			while (satB==0) {while (satB==0) if(satB==1);don='6';}
			while (satC==0) {while (satC==0) if(satC==1);don='9';}
			while (satD==0) {while (satD==0) if(satD==1);don='=';}
			sut3=1;
			
		}
		
		sut4=0;//4.sutunu kontrol et
		while(!sut4)
		{
			while (satA==0) {while (satA==0) if(satA==1);don='/';}
			while (satB==0) {while (satB==0) if(satB==1);don='*';}
			while (satC==0) {while (satC==0) if(satC==1);don='-';}
			while (satD==0) {while (satD==0) if(satD==1);don='+';}
			sut4=1;
		}
	  if(don != ' ') break;
	  }
	 
 	return don;
}

and here is the circuit for those codes.

**broken link removed**
 

thanks....i have again a question..how the scrolling be done?example i pressed 1 in the keypad and i have 4 seven segment the output would be 0001 and if i pressed 2 the output woould be 0012..
 
thanks....i have again a question..how the scrolling be done?example i pressed 1 in the keypad and i have 4 seven segment the output would be 0001 and if i pressed 2 the output woould be 0012..

u searching for c codes ? i can give some codes but i dont use pic. i use 8051 so they are not same.
 

u told PIC at the head of this threat whatever its easy to scroll that numbers on displays. i explain sketchly. First u must have 4 output for drive 4 seven segment displays. (of course different number of outputs are usefull but easy one is this.) i called the displays as cikis0...cikis3

Code:
char cikis0 = 0x00, cikis1 = 0x00, cikis2 = 0x00, cikis3 = 0x00, giris;
int sayac = 0;

while(1)
{
	giris = tus(); //using the function i gave. it will wait until u press a button.
	sayac++

	if(sayac<5)
	{
	    cikis3 = cikis2;
	    cikis2 = cikis1;
	    cikis1 = cikis0;
	    cikis0 = giris;
	}else 
	    {
		sayac = 0;
		cikis0 = 0x00;
		cikis1 = 0x00;
		cikis2 = 0x00;
		cikis3 = 0x00;
	    }
}

im sure there are many ideas about this. but mine is this
 
This is for Therapist.

What compiler must be used for the c program you provided? since i tried compiling it in Hi-Tech ANSI C compiler and it just gave me a whole lot of errors. I im using the not so preferable compiler could you please refer me o one that you prefer.

Thanks
 
Dear ansarmytheen ,
can I have pseudocode for 4x4 keypad in assembly for pic
thanks in advance
 

Hai dear,

Sorry for late. Yes, you can make code in assembly.
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…