<font color="#ff11e1">
#pragma SRC

unsigned int ScanKey(void)   /* test case to provide */
{                            /* compilability */
	return(0x0002);
}

unsigned char ScanKeySingle(void) 
{ 
	unsigned int key16;
	unsigned char key8 = 16;

	/* get the key scan vector */
	key16 = ScanKey();

	/* exit early if no keys active */
	if(key16 == 0x0000)
	{
		return(0x80);			/* show no key */
	}			

	/* scan the 16 bit key vector with 1's for keys pressed */
	do
	{
		if(key16 & 0x8000)		/* if a key vector bit is set */
		{
			if(key16 & 0x7FFF)	/* if another bit is set */
			{
				/* show multiple key pressed */
				return(0x10);	
			}
			else
			{
				/* singular key found */
				return(--key8);
			}
		}

		key16 <<= 1;			/* shift the key bits left */

	} while(--key8);

	/* default exit for no kwy pressed */
	return(0x80);				/* Note that code never will get here */
} 								/* due to the early exit check at beginning */
</font>