Button pressed time control


Closed Thread
Results 1 to 13 of 13
  1. #1
    tanero's Avatar
    tanero Guest

    Unhappy Button pressed time control

    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

  2. #2
    tanero's Avatar
    tanero Guest


    Did you find this post helpful? Yes | No

    Default

    no answer ?

  3. #3
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

  4. #4
    tanero's Avatar
    tanero Guest


    Did you find this post helpful? Yes | No

    Smile

    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
    Last edited by tanero; - 10th August 2005 at 22:12.

  5. #5
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    simply take that example and re-work it, omitting the section dealing with the initial pulse.

  6. #6
    tanero's Avatar
    tanero Guest


    Did you find this post helpful? Yes | No

    Default

    means like?

  7. #7
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    '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.

  8. #8
    tanero's Avatar
    tanero Guest


    Did you find this post helpful? Yes | No

    Default

    i did try , i didn't manage already before i post previos message

  9. #9


    Did you find this post helpful? Yes | No

    Default Help Timer Of 40 Days 12f675 Or 16f628

    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








    Quote Originally Posted by Melanie
    '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.

  10. #10
    Join Date
    Jul 2005
    Posts
    65


    Did you find this post helpful? Yes | No

    Lightbulb

    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.
    Last edited by crematory; - 14th August 2005 at 22:40.

  11. #11
    tanero's Avatar
    tanero Guest


    Did you find this post helpful? Yes | No

    Smile

    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 .

  12. #12
    Join Date
    Jul 2005
    Posts
    65


    Did you find this post helpful? Yes | No

    Default

    Hi

    You can post the code here

  13. #13
    tanero's Avatar
    tanero Guest


    Did you find this post helpful? Yes | No

    Default

    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
    Attached Images Attached Images  

Similar Threads

  1. 8x8 keypad matrix...
    By mbox in forum General
    Replies: 5
    Last Post: - 9th October 2014, 18:43
  2. using a pot to control a time range
    By glkosec in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 17th June 2008, 19:59
  3. Control unlimited servos at the same time
    By mrx23 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 19th September 2006, 14:14
  4. 3 HPWM channels
    By docwisdom in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 4th April 2006, 02:43
  5. Code check -- button not working
    By docwisdom in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 2nd March 2006, 22:43

Members who have read this thread : 2

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts