PDA

View Full Version : button pullup/down resistor?



davewanna
- 15th June 2008, 00:36
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



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.

skimask
- 15th June 2008, 01:00
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.



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.

davewanna
- 15th June 2008, 01:18
Simplified, and still not working.



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)

skimask
- 15th June 2008, 01:22
TRISD = %10000000
Take a good hard look at that line.

davewanna
- 15th June 2008, 01:41
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.

skimask
- 15th June 2008, 01:46
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...

davewanna
- 15th June 2008, 01:55
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

abidr
- 18th June 2008, 06:42
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..

skimask
- 18th June 2008, 14:26
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?

abidr
- 19th June 2008, 04:41
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.

skimask
- 19th June 2008, 05:13
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? :D