Need help with 16F676 button press


Closed Thread
Results 1 to 6 of 6

Hybrid View

  1. #1
    Join Date
    Jan 2007
    Posts
    78


    Did you find this post helpful? Yes | No

    Default Re: Need help with 16F676 button press

    I found it!
    I changed

    if PORTA.0 = 1 Then second_pause

    to

    if PORTA.0 == 1 Then second_pause

    Its now working correctly

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,626


    Did you find this post helpful? Yes | No

    Default Re: Need help with 16F676 button press

    I have a hard time believing that was the actual problem. In PBP (unlike, for example, C) = and == are the same thing. And you basically have the proof in your own code sine the WHILE loop works and you have only one = in that comparison.
    Code:
    second_pause:
    While PORTA.0 = 1     ' <--- See, you don't need ==
    wend
    I would try changing it back and see if it really returns to a non working state.

    /Henrik.

  3. #3
    Join Date
    Jan 2007
    Posts
    78


    Did you find this post helpful? Yes | No

    Default Re: Need help with 16F676 button press

    Quote Originally Posted by HenrikOlsson View Post
    I have a hard time believing that was the actual problem. In PBP (unlike, for example, C) = and == are the same thing. And you basically have the proof in your own code sine the WHILE loop works and you have only one = in that comparison.
    Code:
    second_pause:
    While PORTA.0 = 1     ' <--- See, you don't need ==
    wend
    I would try changing it back and see if it really returns to a non working state.

    /Henrik.

    Hi Hentik,
    I added the second = to the While loop when I updated the IF statement.
    I can definitely change the IF statement back to a single = and see if it goes back to not working - just for a validation test.

    Prior to making the change in the IF statement - I also removed the bias resistors and set PortA.0, 1, & 2 with internal pull-ups - and setup the buttons so that they pull to ground.

    I'll change the IF statement and let you know
    Last edited by dw_picbasic; - 2nd January 2021 at 01:37.

  4. #4
    Join Date
    Jan 2007
    Posts
    78


    Did you find this post helpful? Yes | No

    Default Re: Need help with 16F676 button press

    Well - you were right.
    I changed it back to a single = and it still works.
    So I can only guess.
    The only other change I made was to add the internal pull-ups and switch the buttons to press pins to ground.
    And I did that before changing the IF statement and it still didn't work until after I changed the IF statement.
    I added two more buttons - one to manually increment hour and one to manually increment minute.
    But in any case - its working - which is a good thing! :-]

  5. #5
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french speaking)
    Posts
    964


    Did you find this post helpful? Yes | No

    Default Re: Need help with 16F676 button press

    Hi dw_picbasic,

    I'm an electrician and when I need a lamp to light on, I turn on (a kind of "1" level) the button that will provide energy to the lamp.

    In electronic, it is different. As I learned over time, a good practice is to use "inverted-logic" for digital inputs.

    I see, you pull-down your input pin so you wait for a high level (or "1" or "active high") to trigger an event. I might suggest you to "invert" your way of thinking and trigger your event(s) when the button goes to a "low" level (or "0" or "active low").

    Waiting for a "low level" means that you need to keep the input always "high" like in this shema.

    Name:  000569.png
Views: 3236
Size:  37.6 KB

    Your PIC has alread built-in "weak pull-ups" (find this in your datasheet) like R1 so you don't need to add anything to your button. Use them in place of your external resistor(s)

    This way of doing has some advantages and one of them is a good protection against noise.

    Name:  000562.png
Views: 3252
Size:  16.2 KB
    Roger

Similar Threads

  1. Replies: 5
    Last Post: - 26th February 2011, 06:51
  2. Button press or not
    By lerameur in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 24th November 2010, 21:37
  3. 4 Bytes one button press
    By Dennis in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 15th January 2010, 23:36
  4. Sleep until button press?
    By kevj in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 9th October 2007, 04:47
  5. Button press and press & hold how to ?
    By GrandPa in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 22nd August 2007, 04:37

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