CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Detecting long (and short) presses in a keypad

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Christophe



Joined: 10 May 2005
Posts: 323
Location: Belgium

View user's profile Send private message

Detecting long (and short) presses in a keypad
PostPosted: Mon Mar 30, 2009 7:37 am     Reply with quote

Hi guys,

I'm interfacing a 9 button keyboard to a PIC16F886. Every button is on an input and is pull-up to 5V. Now I'm able to detect simultaneous keypresses. That's good. But now I want to add detection for long and short presses. How can I do that?

This is my code for now:

Code:
//******************************* KEYPAD SCAN ********************************//
//B9,B8,B7,B6,B5,B4,B3,B2,B1
   if ( ENABLE_KEYPAD_SCAN )
   {

   Key = Key + (1 * !input (BUTTON_1) );  // Button 1 = 0 + 1 * 1
   delay_us (75);
   
   Key = Key + (2 * !input (BUTTON_2) );  // Button 2
   delay_us (75);
     
   Key = Key + (4 * !input (BUTTON_3) );  // Button 3
   delay_us (75);
   
   Key = Key + (8 * !input (BUTTON_4) );  // Button 4
   delay_us (75);
     
   Key = Key + (16 * !input (BUTTON_5) );  // Button 5
   delay_us (75);
   
   Key = Key + (32 * !input (BUTTON_6) ); // Button 6
   delay_us (75);
   
   temp_button = !input (BUTTON_7);     // Button 7
   Key = Key + (64 * temp_button);
   delay_us (75);
   
   temp_button = !input (BUTTON_8);     // Button 8
   Key = Key + (128 * temp_button);
   delay_us (75);
   
   temp_button = !input (BUTTON_9);     // Button 9
   Key = Key + (256 * temp_button);
   delay_us (75);
     
   if ( Key != 0 &&                     // Alles losgelaten
       input (BUTTON_1) && input (BUTTON_2) && input (BUTTON_3) && input (BUTTON_4) &&
       input (BUTTON_5) && input (BUTTON_6) && input (BUTTON_7) && input (BUTTON_8) &&
       input (BUTTON_9))
   { 
      Key = 0;                           // Reset Keycode
      Send_Command_String_RS232 ( Key , 2 , make8 (key,1) , make8 (key,0) , 0 );
      Keypad_Debounce_Counter_2 = 2;                                       // Start 2 * 20ms = 40 mS debouncing
      ENABLE_KEYPAD_SCAN = FALSE;                                          // Niet meer matrix lezen
   }
   
   }


grts
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group