Keypad scan for HCS12 microprocessor

I need to read the button pressed on a 4x4 keypad, connected to Port E on the MCU.  This is for user to enter frequency, so several "presses" need to be stored in an array.  My confusion is how I actually get this number.  Apparently if PortE is pressed, it is a logic 0.  I've done some reading an understand the idea of making a table of rows and columns associated with keys, just don't know how to load the ascii code pressed into a variable.  Don't think I can just do  newnumber=PTE;

Any advice would be great.  
rem2722Asked:
Who is Participating?
 
Anthony2000Connect With a Mentor Commented:
I am assuming that PortE will contain a different pattern of values, each will represent which key on the keypad was pressed. With 4x4 keypad you can have 16 patterns which can represent the 16 values that PortE can have.

So, if you create a table of values which can hold the ASCII representation of the keypad. You can do something like this:

char key_2_ascii[16] = {
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};


if(PortE < sizeof(key_2_ascii)
{
    x = PortE;
    ascii char pressed = key_2_ascii[ x ];
}

Are you starting to understand?

Other things to consider are polling PortE and debouncing a keypress.
0
All Courses

From novice to tech pro — start learning today.