Hello Tanero
Try this code:
DEFINE OSC 4
INIT :
TRISA = 0
TRISB = %10000000
PORTA = 0
PORTB = 0
OPTION_REG.7 = 0
INTCON = 0
ButtonInput VAR PORTB.7
Counter_A VAR BYTE
LED_A VAR PORTB.0 : LED_A = 0
PAUSE 750
Waiting :
COUNTER_A = 0
PAUSE 250
' When you return form Check routine, following statement ensures that
' MCU doesn't go to debounce routine while you still pressing the button
WHILE ButtonInput == 0 : WEND
PAUSE 250
' Wait for button press
WHILE ButtonInput == 1 : WEND
Debounce :
TOGGLE LED_A
WHILE ButtonInput == 0 AND COUNTER_A =< 50
COUNTER_A = COUNTER_A + 1
PAUSE 100
WEND
' Time over condition tested here, if 5 seconds elapsed, then output will
' change, if not 5 seconds passed, output will not change.
Check :
IF COUNTER_A == 50 THEN
TOGGLE LED_A
ENDIF
GOTO Waiting
END
If 5 seconds don't elapse, output will still high "You didn't mention what will happen if 5 seconds don't pass, so I assumed you don't want to change the output", if 5 seconds pass, this will change the output to low, even if you still pressing the button after those 5 seconds, the output will not change.
I think this shall work for you.
Bookmarks