What is challenging is doing this without making the rest of the program be suspended waiting on the second click to happen or not.
The way I have been doing this is to set a bit for each of the following events:
Button pressed
Time expired without second press
Second press happened during time count.
The following sample works. It may look complicated, but it works well. It is part of my car lights controller code which has multiple inputs that have similar logic and all are active at once.
While one input is waiting on a possible second press, the rest of the program is still working and responding to inputs.
I've always found that for best reliability a pushbutton almost always need a small capacitor across the contacts to debounce it. Using the following program, the loop is so short the program can respond very fast. Without a capacitor, the bounce can cause it to give false operation. On a longer program, the remainder of the program loop will be enough delay to debounce the button signal.
The complete lights controller code has over 800 lines of code, and a good portion has to execute every program cycle. Each input is checked once per cycle so there is enough delay to keep bounce from being an issue.
Also, read the state of the input into a temp variable, then use the temp variable to do the logic. This will keep bounce from happening during the logic operations, and causing some really funky stuff to happen! Voice of experience!! 
I used the hardware of the lights controller to test this program fragment, so that's why the relays are on it.
Hope this is helpful!
Thanks,
David
Code:
'Double-Click example For PIC16F88
'Header for 16F88 CPU I/O modes and Osc. speed...
CMCON=7 'Analog comparators OFF
ANSEL=0 'ADC inputs OFF
'OSCCON=%00000010 ' 31.25 KHz
'OSCCON=%00010010 ' 125 KHz
'OSCCON=%00100010 ' 250 KHz
'OSCCON=%00110010 ' 500 KHz
'OSCCON=%01000010 ' 1 MHz
'OSCCON=%01010010 ' 2 MHz
'OSCCON=%01100010 ' 4 MHz
OSCCON=%01110010 ' 8 MHz
SetupSwitch VAR PORTA.5 'This is a momentary pushbutton
Relay1 VAR PORTB.2 'These outputs close a relay when they are HIGH
Relay2 VAR PORTB.1
SStime VAR WORD 'this counts down to time the second press
x VAR BIT 'buffer variable to keep switch state changes during logic from causing issues.
SSx VAR BIT 'determines change of switch
SS1 VAR BIT 'Set once when SetupSwitch pressed once
SS2 VAR BIT 'Set once when SetupSwitch pressed twice within timefrave
SStime = 0 'These must be initialized to keep from having one false-trigger when circuit sterts up.
SSx = 0
:loop
'------
X = SetupSwitch
IF X <> SSx Then
PauseUs 1 'This will help de-bounce switch, but if program is long, you will not need!
LET SSx = X
IF X Then
IF SStime > 0 Then 'If the timer is still counting when a press happens
SS2 = 1 'set the "double press" variable and
SStime = 0 'reset the timer
Else
SStime = 10000 'When the first press happens, start counting at 10000.
EndIF
EndIF
Else
SS1 = 0
SS2 = 0
EndIF
IF SStime = 1 Then 'If no second press has occured, when timer reaches 1, set the "single press" bit.
SS1 = 1
SStime = 0
EndIF
'------
IF SStime > 0 Then 'This function to decrement the double-click timer would be done in another
LET SStime = SStime - 1 'part of the program, probably using a hardware timer. This is just an example.
EndIF
IF SS1 Then Toggle Relay1 'Each single-click toggles Relay # 1
IF SS2 Then Toggle Relay2 'Each double-click toggles Relay # 2
GoTo loop
Bookmarks