PDA

View Full Version : Button pressed time control



tanero
- 10th August 2005, 17:30
Hi all ;

First of all this is my first message for this board. I will really wonder if i'll find an answer for my problem.

My problem is that ;

I want to control a one input of pic , with a limited time pressed .

Means,

if i pressed one input ; 1 output will be high , while button pressed , pic will count pressed time for preset time over. (for example 5 sn ) .

After time over , the output will be low .

If button still pressed over 5sn , the output will not be changed . (left low)

i couldn't make an idea about how i can do that . is there a code like that ?

Please help

tanero
- 10th August 2005, 19:49
no answer ?

Melanie
- 10th August 2005, 20:32
http://www.picbasic.co.uk/forum/showthread.php?t=2180

tanero
- 10th August 2005, 21:34
thanks Melanie,

your are wounderfull , just one question is it possible to do same thing with a one button input.


when press a button -> led will be high

while button pressed and time over -> led will be low

when button released --> led will be high

Melanie
- 11th August 2005, 00:58
simply take that example and re-work it, omitting the section dealing with the initial pulse.

tanero
- 11th August 2005, 08:55
means like?

Melanie
- 11th August 2005, 11:16
'means like' you need to see what that code example is doing, understand it, remove the bits you don't want and amend the timeout period for your needs.

tanero
- 11th August 2005, 13:44
i did try , i didn't manage already before i post previos message

Leonardo
- 13th August 2005, 21:10
Hellow Melanie

I am making with 12F675 a timer that ignites PORTB.0 when pressing a pulser in RB.1 and off it to the 40 days but not like doing it, you you can help me please.

************************************************* ***************
'* Name : TIMER 40 DAYS.BAS *
'* Author : [select VIEW...EDITOR OPTIONS] *
'* Notice : Copyright (c) 2005 [select VIEW...EDITOR OPTIONS] *
'* : All Rights Reserved *
'* Date : 13/08/05 *
'* Version : 1.0 *
'* Notes : *
'* : *
'************************************************* ***************
' Turn LED on. Interrupt on PORTB.0 (INTE) turns LED off.

PUSH VAR PORTB.0
LED var PORTB.1


Minutes VAR Word
Hours VAR Word
Days VAR Word


loop:
HIGH LED
GOTO LOOP


OPTION_REG = $7f


Wait40Days:
For Days = 1 to 40
For Hours = 1 to 24
For Minutes = 1 to 60
PAUSE 60000 ; 60 Seconds
Next Minutes
Next Hours
Next Days



Thank you very much

Leonard









'means like' you need to see what that code example is doing, understand it, remove the bits you don't want and amend the timeout period for your needs.

crematory
- 14th August 2005, 21:28
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.

tanero
- 15th August 2005, 09:26
I really , thank you for your working. I tested your code , that is not what i wanted .

But , I already find a diffrent solution for my need .

Example ;

When you press a button , led will be high over a npn transistor. And a counter starting the count for 5 second .

if button still pressed end of 5 sn , another output from a pic will be high over transistor which is connected first one from base - collector.

It will force to down the first transistor .

Otherwise , in 5 sec i release button it goes first statetment.

Thanks everbody who helps .


Not : If some body interset my code i can send to board .

crematory
- 15th August 2005, 11:28
Hi

You can post the code here

tanero
- 15th August 2005, 15:17
My code is that ;


'----------------------------------
@ DEVICE pic16F648A 'Device 16F648A
@ DEVICE pic16F648A, WDT_OFF 'Watch Dog
@ DEVICE pic16F648A, PWRT_ON 'Power on Timer
@ DEVICE pic16F648A, PROTECT_OFF 'Cod Protect Off
@ DEVICE pic16F648A, MCLR_OFF 'MCLR pin is not used
@ DEVICE pic16F648A, INTRC_OSC_NOCLKOUT 'Internal osilator used
DEFINE OSC 4 ' Osilator frekans
CMCON=7

TRISA=255
TRISB=0

PORTB=0

BUTTONINPUT VAR PORTA.0
LED VAR PORTB.0
KILLER VAR PORTB.1

Counter VAR BYTE
Counter=0


Loop:
While BUTTONINPUT=0
High LED
Counter=Counter+1
IF Counter=50 Then High KILLER
Pause 100
Wend
Low LED
Low KILLER
Counter=0
GoTo Loop

End