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

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
07/01/06 14:05
Modified:
  07/01/06 14:09

Read: times


 
#119511 - keypad scanner in C
Responding to: ???'s previous message
I did this code ages ago to scan a keypad.
If you can C then have a look
the logic is you output a zero to each column and check the rows. At the end of 4th column you have the switch states in keycode.
I debounce all the switches together as follows:
debounce(keyScan());
/******************************************************************************
* 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);
}


List of 36 messages in thread
TopicAuthorDate
4x3 keypad interfacing with At89c51            01/01/70 00:00      
   5 errors            01/01/70 00:00      
      Nice attitude!            01/01/70 00:00      
         If the approach is that anyone can get h            01/01/70 00:00      
            Do we know him?            01/01/70 00:00      
               Switch Depressed?            01/01/70 00:00      
                  continous and continous            01/01/70 00:00      
                     Thanks Erik!            01/01/70 00:00      
                  Taking samples            01/01/70 00:00      
                     debounce scheme.            01/01/70 00:00      
                        How to debounce without jumps and branch            01/01/70 00:00      
                           Thank you Kai...            01/01/70 00:00      
                           Having gone through your detailed descri            01/01/70 00:00      
                              Yes, I think so            01/01/70 00:00      
                                 Could you assist me to know that            01/01/70 00:00      
                                    Vertically incrementing            01/01/70 00:00      
                                       Thanks            01/01/70 00:00      
               Homework it is            01/01/70 00:00      
                  "Guilty"...            01/01/70 00:00      
   Post your code            01/01/70 00:00      
      2            01/01/70 00:00      
         There have been several threads            01/01/70 00:00      
         How to post code            01/01/70 00:00      
         why so complex            01/01/70 00:00      
         What Compiler ?            01/01/70 00:00      
            Compiler.KEIL            01/01/70 00:00      
         general idea            01/01/70 00:00      
            Diodes to prevent ghosting            01/01/70 00:00      
    Algorithm for Scanning 4*4 Keypad            01/01/70 00:00      
      thanks            01/01/70 00:00      
         If you'd searched, you'd have had this            01/01/70 00:00      
            Search term "4x4 keypad"            01/01/70 00:00      
   check this code.            01/01/70 00:00      
      Answers            01/01/70 00:00      
   Sorry kai.            01/01/70 00:00      
      keypad scanner in C            01/01/70 00:00      

Back to Subject List