Ok, am I a little harsh, maybe, but when you have a keyboard that you don't use very much, just think of the wasted CPU cycles scanning the Keyboard! I one minute, in one hour? So what to do? In steps our 8 input to 3-line, Priority Encoder TI SN74x148.

A0A1A3=GS
HHH0H
0014L
Table 1

 

Ok, you ask what is a Priority Encoder? Put it simply it is a device that will generate the proper output for any given key. Without a keypress, the encoder's output is 0.(update #2)  So let's say you pressed 4 to a ground state, its output would be 001 hex or 4 (table 1). Plus the GS pin will go low. Cool. But beware if you doing this method you will be generating a processor interrupt, so you must eliminate switch bounce with a Schmitt Trigger.

 

The picture below is from the TI datasheet mentioned in the link above. Please remember that to pull the TTL device to the ground from a high, one of the switches must be connected to the ground while the other side of the switch is wired to a pin on the priority encoder is high which means that you will need a pull-up resistor.

The Priority Flag Pin must be connected to a Schmitt Trigger for debounce which is connected to your interrupt pin. (update #1)

So the only thing your software has to do when the interrupt is active is to read the 4 BCD data lines and perform a table lookup.

So in recap here is what you need:

  • SN74x148  Priority Encoder
  • SN74x08 or SN74x00
  • SN74x14 Schmitt Trigger
  • Resistor Networks x2 (9 pin 8 10k ohm) for pull-ups
  • RC network for Schmitt Trigger.

OBTW

Your software is now simplified as if you know the value of the nibble, a simple 1-dimensional table would be all you need as you most likely want ASCII output. A quick review of C ints and Chars are the SAME! My keyboard has 0-9, ENT, KBD, CLR, TGT

3031323334353637383910414243
0123456789ENTCLRKBDTGT

 


char keyboardDecoder( int value ) {

    static int decoder[ ] = { 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 10, 41, 42, 43 }

     return ( decoder[ value ] ); }

 

 

 

UPDATES

  1. Added the sentence starting with The Priority Flag Pin 1/18/2020 CAH
  2. Added the sentence with Without a keypress  1/18/2020 CAH
  3. To make decoding without the zero as an input you can start as the array index as 1, not zero so my array would start as 1 outputting 30. 1/18/2020 CAH
  4. PLEASE NOTE: The implied decimal zero condition requires no input condition, as zero is encoded when all nine data lines are at a high logic level. TI DATA BOOK