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

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
05/29/05 03:27
Read: times


 
#94074 - key scan
Responding to: ???'s previous message
I would write like this

_wait_:

while((P0 & 0xF0) == 0xF0) { ; }

key_temp = (P0 & 0xF0) ;

delay(debounce); // debounce delay 50 - 100 mS

if (key_temp == (P0 & 0xF0)) { get_key(); }

while((P0 & 0xF0) != 0xF0) { ; }

if (key_temp) { key_act(); }
key_temp = 0 ;

goto _wait_;

void get_key(void)
{
switch(key_temp)
{
case 0x70:
key_temp = up_key ;
break;
case 0xB0:
key_temp = down_key ;
break;
case 0xD0:
key_temp = left_key;
break;
case 0xE0:
key_temp = right_key;
break;
default :
key_temp = invalid_key;
}
}

Obivously this code and method is not elegant. But ok to start with. This method hoggs the controller.

Alternative is to use say a 50mS timer tick to scan the keys. Note any change of state and look for the changed state in the next loop. If still changed state then a key(s) is pressed so find the key. Else reset the changed state and loop back. The 50mS tick time will provide the debouncing. In this method controller is available for other tasks.

List of 22 messages in thread
TopicAuthorDate
Keil: getting input            01/01/70 00:00      
   If it works in ASM it Works in C            01/01/70 00:00      
      Why C?!            01/01/70 00:00      
         Irrelevant            01/01/70 00:00      
         Of Course            01/01/70 00:00      
   key scan            01/01/70 00:00      
      Delay..            01/01/70 00:00      
         Delay            01/01/70 00:00      
         Software Delay Loops            01/01/70 00:00      
            Software Delay Loops            01/01/70 00:00      
   Learning 'C'            01/01/70 00:00      
   to be precise..            01/01/70 00:00      
      Debounce            01/01/70 00:00      
         completely missed it..            01/01/70 00:00      
      to be precise...            01/01/70 00:00      
         Sorry Leo !            01/01/70 00:00      
         Inferences            01/01/70 00:00      
            Right answer, wrong reason            01/01/70 00:00      
               and therefore            01/01/70 00:00      
            Congratulations            01/01/70 00:00      
               to: Raghu Sir            01/01/70 00:00      
      BIts!            01/01/70 00:00      

Back to Subject List