Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
07/04/03 18:47
Read: times


 
#50084 - 16-bit keyscan to 4-bit
I have a standard 4x4 keypad in which my function scans the keys into a 16-bit result. An example scan in which no keys are pressed:

Row1 - Row2 - Row3 - Row4
1111 1111 1111 1111

However, I only want to know 3 condition:
1) No key is pressed
2) More than one key pressed
3) Key pressed in 4-bit value (0x00-0x0F)

With these conditions, I should be able to produce 8 bit value..correct? My program is in Keil C and I can easily check for condition #1. However, I have trouble making efficient C code for checking condition #2 and "encoding" 4-bit value. Any recommendations?

// Return value:
// 80h = No key (noise)
// 10h = More than one key
// 0Xh = Valid key pressed
char ScanKeySingle(void)
{
unsigned int key16;
char key8 = 0;

// scan and produce 16-bit key
key16 = ScanKey();

// if it was zero then noise
if(key16 == 0)
return 0x80;

// here is where I would check
// for multi-key press and return
// 0x10

// here is where I would encode the
// single keypress into 4-bits

return key8;
}


Any help appreciated! Don't need code necessarily but some logical assistance would help me see efficient way to accomplish the task.

thank you
Javi


List of 6 messages in thread
TopicAuthorDate
16-bit keyscan to 4-bit            01/01/70 00:00      
   RE: 16-bit keyscan to 4-bit            01/01/70 00:00      
   RE: 16-bit keyscan to 4-bit            01/01/70 00:00      
   RE: 16-bit keyscan to 4-bit            01/01/70 00:00      
   RE: 16-bit keyscan to 4-bit            01/01/70 00:00      
      RE: 16-bit keyscan to 4-bit            01/01/70 00:00      

Back to Subject List