button pullup/down resistor?


Closed Thread
Results 1 to 11 of 11
  1. #1
    Join Date
    Dec 2007
    Posts
    60

    Default button pullup/down resistor?

    I have been working for days on an RF project, and I suspect I'm going crazy.

    I have put a button on my 16F877a just so I can tell it to do something.
    The problem is, that when I press the button it activates, but when I let go of it, it stays activated.

    I have gone as low as a 560ohm pullup/down resistor. Tried pulling to ground, and to +5V.

    I am currently using pin D.0

    Code:
    TRISD = %10000000
    but  VAR PORTD.0
    ....
    
    Start:
    
    lcdout $fe,$80,"Rec  ",dec counter
    lcdout $fe,$c0,bin result,"   "
    lcdout $fe,$d4,bin stats,"   "
    
    if but = 1 then
      lcdout $fe,$8A,"B"
      gosub chkstatus
    else
      lcdout $fe,$8A," "
    endif
    
    if nIRQ = 0 then
      lcdout $fe,$94,"Receiving!"
      gosub receive
    else
      lcdout $fe,$94,"Waiting..."
    endif
    
    pause 50
    counter = counter + 1
    
    goto start

    With a 560ohm to +5v, and the button to ground. After it has been pressed, and depressed - I am still measuring 185mV on pin D.0. Even after I remove the jump wire to the button entirely, I am still reading 185mV on the pic with only the resistor connected to +5v.


    HOWEVER... If I take the jump wire from pin D.0 and connect it straight to +5v, and then to ground. The display and functions work as expected.

    How could I have done this? I have tried 2 different (new) 877a's, and several port pins.

    Running on 10MHz, 5V regulated, smoothing caps, on a breadboard.
    Last edited by davewanna; - 15th June 2008 at 00:41.

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by davewanna View Post
    Running on 10MHz, 5V regulated, smoothing caps, on a breadboard.
    That would be my first suspect right there.

    Other than that, forget about everything else that you may/may not have going on in your program.
    Write a small routine to display the button input status on the LCD and NOTHING ELSE!
    And use pull ups.

    Code:
    but var portd.0 : input but
    Start:
    lcdout $fe , $80 , "Button="
    if but = 1 then
    lcdout $fe , $87 , "On "
    else
    lcdout $fe , $87 , "Off"
    endif
    goto start
    That should hook you up with all the info you need.

  3. #3
    Join Date
    Dec 2007
    Posts
    60


    Did you find this post helpful? Yes | No

    Default

    Simplified, and still not working.

    Code:
    DEFINE OSC 4
    
    ' Define LCD registers and bits
    DEFINE  LCD_DREG        PORTC            'LCD addressing
    DEFINE  LCD_DBIT        4                'L1 = $80         
    DEFINE  LCD_RSREG       PORTD            'L2 = $C0 
    DEFINE  LCD_RSBIT       2                'L3 = $94
    DEFINE  LCD_EREG        PORTD            'L4 = $D4
    DEFINE  LCD_EBIT        3
    
    TRISD = %10000000
    but	var portd.0
    
    lcdout $fe,1
    Start:
    
    if but = 0 then
      lcdout $fe,$8A,"On "
    else
      lcdout $fe,$8A,"Off"
    endif
    
    goto start
    Shows "off" on the screen until I press the button - then says "on" and stays that way, even after button released

    I went back to a 4Mhz clock, and have measured voltages and resistances to ground and +5v on d.0 (pin 19)

  4. #4
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by davewanna View Post
    Code:
    TRISD = %10000000
    Take a good hard look at that line.

  5. #5
    Join Date
    Dec 2007
    Posts
    60


    Did you find this post helpful? Yes | No

    Default Hmmmm

    I'm a dickhead...

    I'm trying to make RF work, and I don't even know how to set a TRIS.....

    So after reading the datasheet again, and doing some tests... It seems I've been setting the TRIS as LSB first, when it should be MSB first... Correct?

    Must just be pure luck that my previous projects have worked.

    Thanks Skimask.. You've been a big help on most all of my queries so far.

  6. #6
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by davewanna View Post
    I'm a dickhead...
    I wouldn't go that far!

    So after reading the datasheet again, and doing some tests... It seems I've been setting the TRIS as LSB first, when it should be MSB first... Correct?
    It was either that or you had your ins and outs mixed up.
    1 = input = because it looks like the letter I for input
    0 = output = because it looks like the letter O for output
    MSB is on the left, just like in a regular written number (unless it's in Arabic...or are those read left to right also? Not sure...)....LSB on the right...

  7. #7
    Join Date
    Dec 2007
    Posts
    60


    Did you find this post helpful? Yes | No

    Default

    I would go that far... you see, that also means, that my nIRQ interrupt pin that would not go high, no matter what, was also assigned as an output... And that is a problem that i have spent a lot of time on.

    I'm sure there's a saying somewhere about the worst problems are ones that you cause yourself.


    You will be pleased to know also that I have stopped re-inventing the wheel. And am now using shiftin/shiftout for my RFM12. I am currently receiving something, it's not what I am transmitting yet, but it's a start. I had actually missed your earlier post in my other thread recommending to use shiftin/shiftout. If I had have seen that, it would also have saved me a lot of time.

    I can now go and try to work out how much of this received info is status bits, and how much is actual received data.

    Anyway skimask, you are my new hero... Mister_e is back to number 2... haha

  8. #8
    Join Date
    Apr 2008
    Posts
    13


    Did you find this post helpful? Yes | No

    Default

    I'd rather code the button to debounce something like below:
    CHECK_PB:
    IF PB = 0 THEN DEBOUNCE_PB
    RETURN

    DEBOUNCE_PB:
    PAUSEUS 200
    IF PB = 0 THEN CHECK_PB

    MENU_CNT = MENU_CNT + 1

    RETURN
    and before that I would prefer to make the pin connected to button as output..

  9. #9
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by abidr View Post
    I'd rather code the button to debounce something like below:
    True...but the thing has to be working halfway in the first place...then all the options can be added...
    No sense in having spanky shiny rims on a car without an engine?

  10. #10
    Join Date
    Apr 2008
    Posts
    13


    Did you find this post helpful? Yes | No

    Default

    You need to look at the PIC16F877A data sheet page 51 which says that port D is a parallel Slave Port.
    I think you need to disable the PSP.

  11. #11
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by abidr View Post
    You need to look at the PIC16F877A data sheet page 51 which says that port D is a parallel Slave Port.
    I think you need to disable the PSP.
    You mean the Parallel Slave Port that's disabled by default on power up, thereby letting Port D function as normal I/O?

Similar Threads

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

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