Search code examples
cpicmikroc

PIC in C - creating own keypad scan routine using RC0-3


I have been asked to create my own routine which will scan the keypad, but only using PORTC and using RC0-3, I only need to return 4 values, which are 1,2,4,5 which, if im correct, are in a 2x2 arrangement on a 4x4 keypad. The keypad I am using is a 4x4 keypad connected to PORTC, I am just wondering how you would go about doing this? As I have not been taught this, yet it is a big part of a piece of work, It would be nice if I don't receive a solution, but more an explanation pushing me in the right direction so i can do it myself. PIC Microcontrollers: Scan inputs on a 4x4 Keypad, using only Port C RC0-RC3 in C it is basically this question, but the answers on there didnt really help, so I thought I would have a go asking this question myself :) Any help will be appreciated!


Solution

  • In the previous question you linked, the "1,2,4,5" refer to the keypad legends which might be anything and often bear no relation to the bit values you receive back. You write a "1" bit to each output (row) in turn (or a "0" for inverted logic) and look for high (or low if inverted logic) bits on the column inputs. You worry about what is written on the keytops afterwards, by using a lookup table. Whether you have a 2x2 key matrix or a 4x4 is irrelevant, unless you want an in-line solution and not a looped one.

    If the keypad really was 2x2 it would not need to be a matrix, the wiring and coding would both be simpler with 4 bits used as inputs instead of 2 out and 2 in to drive and read a matrix.

    Unless you rewire the 4x4 keyboard, your 2x2 subset of it will probably be using RC0,1 and RC4,5.