I need to use KBI for a matrix keypad

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

I need to use KBI for a matrix keypad

7,082 Views
ganimides
Contributor I
Hi guys!.
 
I just need some circuit explaining how to connect and enable the pull up resistors inside the micro and hot to program this task for a 3x4 matrix keypad.
 
 
I would appreciate some help about this.
 
 
Thank you so much!.
 
 
Have a nice day!.
 
 
 
Ganimides
Labels (1)
0 Kudos
8 Replies

596 Views
ganimides
Contributor I

Thank you very muchs Peg and Rhinocerohead for your always trusted contributions.

I will test what you suggested me and I will tell you later.

 

Have a very nice week!

Gany 

0 Kudos

596 Views
SalsaBogota
Contributor I
Hi, I need your help... Im using  the HC908, its the first time that i use the KBI, and i use the TIM module for the delay...and I don't know if my program it's ok... I'm working with a xtal of 38 KHZ using the PLL for obtain a FBUS of 4.9 Mhz aprox...

This is that i have...

void TIMSet (void) {//tim GP
       T2SC_TSTOP = 1    ;
       T2SC_TRST  = 1    ;
       T2SC_PS    = 6    ; //prescale 64
       T2MOD      = 7812 ;
       T2SC_TOIE  = 1    ;
       T2SC_TSTOP = 0    ;
   
 }

 void KBISet (void){
   INTKBSCR_IMASKK = 1   ;
   INTKBIER        = 0xF0;        //HABILITAR PIN A PIN
   INTKBSCR_ACKK   = 1   ;
   INTKBSCR_IMASKK = 0   ;
 
 }

How i know what button was pressed in the keyboard, if any pin will of the KBI generate the interruption? Thanks by your help:smileyhappy:
0 Kudos

596 Views
peg
Senior Contributor IV
Hi SalsaBogota,
 
The short answer to your specific question is that you determine which pin caused the interrupt by testing all of the relevant pins in the interrupt routine.
Of course you will also need to allow for which row/column is being driven at the time if it is indeed a matrix keypad.
 
0 Kudos

596 Views
joerg
Contributor II
Hi
i am using my EBS08 for the general timing of many of my projects (in fact i hardly did not use it for my over 50 projects)! So i have also written a keyboard decoder for a 4x4 matrix. I has the possibility to recognize if you press 2 keys and with the check of detecting 3 times the same key it is hard to get the wrong information. So if somebody is interested in the file can be downloaded (info's included) here:

http://www.systech-gmbh.ch/indexEBS08.html
       (called tast4x4)

The C version is written now, but i did not find the time to test it (so it is available only on request!)


SalutiJoerg

PS: the module works on every 8 bit port!


0 Kudos

596 Views
peg
Senior Contributor IV

Hi Ganimides,

Still searching huh?

The method I suggested before (and presumably the one you where offered in Yahoo groups) could be modified for KBI.

All of the matrix decode is the same, the KBI simply enables an interrupt to be generated by a keypress (in this case you would turn all of the output side on and wait for the int) then after that the rest is the same.

This just saves you from constantly polling the keypad when nothing is happening.

The wiring and setup is the same, you use KBI pins for the input side of the matrix.

The main difference is to enable the KBI and then do at least the first part in a KBI ISR

Regards David

 

0 Kudos

596 Views
rhinoceroshead
Contributor I
Here is an example.  I'm sure someone will correct me if I'm missing something.
 
Assuming 908GP32:
 
1)  Wire horizontal matrix wires directly to PTA4, PTA5, PTA6, PTA7
2)  Wire vertical matrix wires directly to PTA0/KBD0, PTA1/KBD1, PTA2/KBD2
3)  Set PTA4-7 to output and drive them low
 
DDRA = 0xf0;        // PTA0-3 input, PTA4-7 output
PTA &= ~0xf0;      // PTA4-7 low
 
4)  Enable pullups on PTA0-2
 
PTAPUE = 0x07;        // PTA0-2 pullups enabled
 
5)  Enable keyboard interrupts on PTA0-2
 
INTKBIER = 0x07;      //  PTA0-2 keyboard interrupts enabled
 
6)  Enable interrupts in main()
 
asm cli;
 
That's all you should have to do.  Now in your keyboard ISR, you do the normal polling where you set PTA4-7 low one at a time and read PTA0-2 until you find which key was pressed.
0 Kudos

596 Views
peg
Senior Contributor IV

Yeah, looks good but.......

It would be very slightly more efficient to use 4 x KBI inputs and 3 x outputs. Only 3 outputs to turn on sequentially and you read 4 at once instead of three!

Regards Pedantic Peg

 

0 Kudos

596 Views
rhinoceroshead
Contributor I

I knew someone would get me on that :smileyhappy:

One way you loop 3 times and make 4 branches and the other way you loop 4 times and make 3 branches.  You're already going to have some variance on runtime depending on which key is pressed.  But you're right, it would be statistically faster if you used 3 loops and 4 branches.

0 Kudos