On_Off


Closed Thread
Results 1 to 10 of 10

Thread: On_Off

  1. #1

    Talking On_Off

    Hello to all,

    I want to make the following thing:

    I have a 16f84 and I want that when pulsing in RB0 on a led in RB1 and if I press the same one again off the led.

    Somebody can help me.

    Greetings

  2. #2
    Join Date
    Apr 2006
    Location
    Michigan
    Posts
    70


    Did you find this post helpful? Yes | No

    Default

    I am very tired and drunk and am just writing this without trying it but here it goes.

    flag var bit
    flag = 0

    start:
    If portb.0 = 1 and flag=0 then
    portb.1 = 1
    flag = 1
    pause 1000
    end if

    if portb.0 = 1 and flag=1 then
    portb.1=0
    flag = 0
    pause 1000
    endif
    goto start

    The flag is a way for the micro to keep track of which state is currently on. The pause allows the user to remove there finger from the button so the LED is constantly flashing. This may neet to be adjusted. This will be 1000 ms.

  3. #3
    Join Date
    Apr 2006
    Location
    Michigan
    Posts
    70


    Did you find this post helpful? Yes | No

    Default

    flag var bit
    flag = 0

    start:
    If portb.0 = 1 and flag=0 then
    portb.1 = 1
    flag = 1
    pause 1000
    endif

    if portb.0 = 1 and flag=1 then
    portb.1=0
    flag = 0
    pause 1000
    endif
    goto start

    The endif should not have had a space in it. I also didn't meand the LED would flash. The pause is so it won't flash.

  4. #4
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    <img src="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=390&d=1122866228">from what i understand...
    Code:
    IF PORTB.0=0 then
        TOGGLE PORTB.1
        WHILE PORTB.0=0 : Wend : pause 50
        ENDIF
    Last edited by mister_e; - 1st July 2006 at 09:41.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  5. #5
    Join Date
    Apr 2006
    Location
    Michigan
    Posts
    70


    Did you find this post helpful? Yes | No

    Default

    That is good and simple, but does it debounce the switch.

  6. #6
    Join Date
    Apr 2006
    Location
    Michigan
    Posts
    70


    Did you find this post helpful? Yes | No

    Default

    I didn't even realize that toggle command was in there. I that case I could change my code to:

    input portb.0

    start:
    If portb.0 = 1 then
    toggle portb.1
    pause 1000
    endif
    goto start

    I still think you need the pause of at least a second. Otherwise the light will pulse when you are holding the button. You need a delay to allow the user to remove there finger.

  7. #7
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    both will work, mine just sit there until the button is release, then it allow a 50mSec of debouncing delay.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  8. #8


    Did you find this post helpful? Yes | No

    Talking on_off

    Hello friends,

    What I want is this:

    If RB0 is 0 RB1 is ON and IF RB0 is 1 RB0 is off , every time that presses the led it should change state.

    Thank you

    Quote Originally Posted by mister_e
    both will work, mine just sit there until the button is release, then it allow a 50mSec of debouncing delay.

  9. #9
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Code:
    PORTB.1=~PORTB.0
    in a loop it have to work.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  10. #10


    Did you find this post helpful? Yes | No

    Talking On_off

    Hello mister and,

    Can give me an example about this please. PORTB.1=~PORTB.0

    Thank you

    Leonard



    Quote Originally Posted by mister_e
    Code:
    PORTB.1=~PORTB.0
    in a loop it have to work.

Members who have read this thread : 1

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