Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

keyboard matrix and how to decode next ?

Status
Not open for further replies.

smiles

Advanced Member level 4
Joined
Jul 27, 2007
Messages
110
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,296
Activity points
2,096
keyboard matrix

here is the keyboard matrix that I found, could you tell me the idea to encode output signals (PIO) and encoded signals can via microcontroller appears on 4 digits-7segment LCD display .
Thanks !!!
 

how to decode a matrix keyboard

Hi,smiles
here are my ASM code wrote in Batronix Pro studio to decode keyboar matrix interface with 89C51 uC. hope it helpfull to U
Code:
INCLUDE 89c51.mc

			ORG 0000H
MAIN:		
			MOV A,#00H
			MOV TMOD,#01H
			MOV P2,#00H
	LOOP:		MOV R6,A
			ACALL READ_KEY
			JNC SKIP
			MOV A,R6		
	SKIP:		ACALL OUTLED 
			JMP LOOP
;****************************************************************
;KEYBoard matrix 4x4: initial value  P1 = 11111110
;			1      1      1      1
;            	P1.4   P1.5   P1.6   P1.7 
;               -----------------------------        
;	1   P1.3 |   f1    f2     f3     f4
;     1   P1.2 |   f5	 f6	  f7	   f8	 		
;     1   P1.1 |	 f9    f10    f11    f12 
;     0   P1.0 |   f13   f14    f15    f16 
        




GETKEY:		
			PUSH 02H;R2 BANK1
			PUSH 06H;R6 BANK1
			PUSH 07H;R7 BANK1
			MOV A,#0FEH
			MOV R6,#4 ;control 4 row
	TEST:	
			MOV P1,A   ;initial value PO 111111110    		
			MOV R7,A
			MOV A,P1 ;get value after buttuon pushed from P1
			ANL A,#0F0H ;clear 4 low BIT (row PO- > P3)
			CJNE A,#0F0H,HINT_KEY ;normally if the button don't push,clear 4 low bit=>A=0F0H
			MOV A,R7
			RL A
			DJNZ R6,TEST
			CLR C ; C = 0 alarm none of button is pushed
			LJMP EXIT
	HINT_KEY:	
			MOV R7,A
			MOV A,#4
			CLR C 
			DEC R6
			MOV A,R6
			ADD A,R6
			ADD A,R6
			ADD A,R6
			;R6x4
			MOV R6,A
			MOV A,R7
			CLR C 
			SWAP A;swap to test 4 high bit (detect column)
			MOV R2,#4 ; alternative test 4 columns(test 4 high bit)
	AGAIN:	
			RRC A	;swap to find the location of bit whose value =0
			JNC DONE ;If C = 0 find out the location of bit ,the value of which is 0 	
			INC R6
;if u don't find bit 0,check another column and increase localtion (R6) 1
;in one column ,the local of 2 button in succession is different 4
		     	DJNZ R2,AGAIN
	DONE:		
			MOV A,R6 ;Value of R6 is the local of button pushed (ex: button f16 is pushed then R6 = 15)
			SETB C;    C = 1 there is button pushed
				;    C = 0 none of button is pushed

	EXIT: 	NOP
			POP 07H;Tra lai gia tri cua R7 truoc ham Getkey
			POP 06H;			    R6
			POP 02H;			    R2
			;cac gia tri tra lai cho R7,R6,R2 nam trong ngan xep da luu giu boi POP	
			RET

;****************************************************************
READ_KEY: 
			PUSH 03H ;LUU NOI DUNG CUA R3 TRONG NGAN XEP DE SAU DO DUNG LAI
	NHOK:		MOV R3,#50
	BACK:		; protect button shaking
			ACALL GETKEY
			JNC NHOK 
			DJNZ R3,BACK
			PUSH ACC
		BACK2:	
			MOV R3,#50
	BACK3:
			ACALL GETKEY
			JC BACK2 
			DJNZ R3,BACK3
			POP ACC
			POP 03H
			RET
;********************************************			
			
OUTLED:
			MOV DPTR,#BANGLED
			MOVC A,@A+DPTR
			MOV P3,A
			RET
	BANGLED:
; the oder of buttons  1  2  3  4  5  6  7  8   9  10  11  12   13   14    15   16
	;       A =   0 1  2  3  4  5  6  7   8   9   10  11   12   13    14   15  
		  
      	DB 09H , 0BDH,  13H,   91H, 0A5H,   0C1H, 41H, 9DH,  01H,  81H , 09H , 0BDH,  13H,   91H, 0A5H,   0C1H
	
			END
 

decoding a matrix keyboard

one for PIC in CCS...
PORTB[7..4] columns
PORTA[3..0] lines

Code:
#use fast_io(A)
#use fast_io(B)

const char dakeys[4][4]={	{ 7 , 8 , 9 ,'/'},
							{ 4 , 5 , 6 ,'*'},
							{ 1 , 2 , 3 ,'-'},
							{'c', 0 ,'=','+'}};
char Read_Keyb()
{	int h=0xE0;
	int i,j,k;

  for (i=0;i<4;i++)
  {
  output_b(h);
  delay_ms(1);
  k=input_a();
  if ((k & 0xf) != 0xf)
     {
        for(j=0;j<4;j++)
        {if(bit_test(k,0)==0) return dakeys[j][i];
         k=k>>1;}
     }
  h = (h<<1) | 0x10;
  }
  return 0xff;
}
 

how to decode a keyboard

smiles

Is its better if you would know the principle behind decoding matrix switches, by this manner you can device your own program.

Its like "teaching you to catch fish rather than giving one."

by this way, even in any application you'll know how to do it on your own.

blastronics

pm me and i will glady to tell you how.
:D
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top