
/******************************************************************************
* NAME          : keyScan
* DESCRIPTION   : This function scans switch matrix and stores it in keyCode
* INPUT         : None
* OUTPUT        : unsigned short integer with each bit indicating a switch
******************************************************************************/
unsigned short int keyScan(void)
{
    unsigned short int keyCode;	 // where all 16 switches are stored
    unsigned char col,
                  colCounter;  
    col = 0x0E;	    // initialise to col 0
    keyCode = 0;
    for(colCounter = 0; colCounter < 4; colCounter++, col++)
    {
        P0 = (P0 & 0x0f0) | (col & 0x0f);	// preserve P0.4 - P0.7 states
        keyCode = keyCode << 4 & 0x0ffff;	// 0ffff to hush lint up
        keyCode |= (0x0f & P1);
        col = col << 1 & 0x0f;
    }
    return(~keyCode);
}
