Button help


Closed Thread
Results 1 to 22 of 22

Thread: Button help

Hybrid View

  1. #1
    homebrewer's Avatar
    homebrewer Guest


    Did you find this post helpful? Yes | No

    Default

    Hello Melanie,
    you are very right. I have looked into the datasheet after my reply.
    I was too overhasty - sorry!

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


    Did you find this post helpful? Yes | No

    Default

    Appologies are unnescessary.

    flotulopex reported that his LED blinks when he pushes the button, that's because there's only a 100mS Pause in the loop and you toggle the LED-ON, and with your finger still on the button, 100mS later you toggle it OFF, and with your finger still on the button, the LED toggles again 100mS later... etc etc until the end of time.

    You need to ensure that once the LED toggles, it doesn't do so again until the Button is pressed anew. There are MANY, MANY ways of doing this. The example I posted simply waits for the user to remove his finger from the button before proceeding further.

  3. #3
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french speaking)
    Posts
    946


    Did you find this post helpful? Yes | No

    Default

    Thank you Melanie,

    Actually, it still doesn't work.

    Each time I press the button, the Led lights up and as soon as I release the button, the Led switches off. At least, it doesn't blink anymore while the button is pressed.

    It just doesn't want to toggle!

    To make sure my button is correctly connected, is this schematic okay?
    > Vdd-R10k-PORTB.3 and the button (normally open) is derived from PORTB.3 to Vss.

    Since I can't make it work with this simple program, my last guess would be that my PIC is defect. I tried with other ports but there is no change. I shall receive another PIC tomorrow.

    By the way, is there any utility tool to check the PIC's health?
    Roger

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


    Did you find this post helpful? Yes | No

    Default

    MyButton var PortB.3
    LED var PortB.4

    TRISB = %00001000

    Loop:
    If MyButton=0 then
    Toggle LED
    While MyButton=0:Pause 100:Wend
    endif
    Goto Loop

    End

    Try the above and report back what the result is...

  5. #5
    Join Date
    Mar 2006
    Location
    INDIA
    Posts
    89


    Did you find this post helpful? Yes | No

    Default

    'PIC 16F84A
    DEFINE OSC 4
    TRISA = %000001
    TRISB = %11111100
    I VAR BYTE
    PAUSE 200

    MAIN:
    IF PORTA.0 = 1 then SWITCH_LED
    goto main

    SWITCH_LED: IF PORTA.0 = 0 THEN SWITCH_LED_INSTANT
    FOR I = 0 TO 10
    IF I < 10 AND PORTA.0 = 0 THEN SWITCH_LED_INSTANT
    PAUSE 100
    NEXT I
    IF PORTA.0 = 1 THEN SWITCH_LED_DELAY
    goto main

    SWITCH_LED_DELAY: TOGGLE PORTB.0
    PAUSE 10

    AVOID_LED_BLINK: IF PORTA.0 = 1 THEN AVOID_LED_BLINK
    PAUSE 10
    GOTO MAIN


    SWITCH_LED_INSTANT: TOGGLE PORTB.1
    PAUSE 10
    GOTO MAIN

  6. #6
    JARI NETWORKS's Avatar
    JARI NETWORKS Guest


    Did you find this post helpful? Yes | No

    Default

    I'm also a new one with de pic chips, can I use this also for a 16F628A chip??

    grz Jan

  7. #7
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french speaking)
    Posts
    946


    Did you find this post helpful? Yes | No

    Default Melanie, I tested your piece of code

    Hello Melanie,

    Your piece of code didn't work until I... grounded PORTB.2.

    So I tried my code and it worked well too.

    I didn't expect this component to be so sensible to the electric field around the pins.

    I won't forget this lesson, for sure ;-)
    Roger

  8. #8
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by JARI NETWORKS
    I'm also a new one with de pic chips, can I use this also for a 16F628A chip??

    grz Jan
    If you are meaning "can you use the button command with the 16f628a chip, then the answer is yes

Similar Threads

  1. Sony SIRC IR Issue
    By Ryan7777 in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 8th August 2015, 09:10
  2. 3 HPWM channels
    By docwisdom in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 4th April 2006, 03:43
  3. Code check -- button not working
    By docwisdom in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 2nd March 2006, 23:43
  4. Button Push within 3 second Window
    By Tissy in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 22nd December 2005, 11:06
  5. Button subfunction 16F628
    By Jųan in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 19th August 2005, 17:44

Members who have read this thread : 0

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