Re: Reading Input on Port B
http://forums.basicmicro.net/downloa...php?id=115&t=1
The pinout usually give some great hints... AN like ANALOG.. so you want to disable the analog features of the offending pins...and have a look at this thread
http://www.picbasic.co.uk/forum/showthread.php?t=561
Re: Reading Input on Port B
I am able to read each pin separately without any problems.
This works:
if (portb.2 = 0) Then do something
So does this:
if (portb.3 = 0) Then do something
So does this:
if (portb.4 = 0) Then do something
However, if I check all three immediately after one another, I am getting funny results. Do I need to let portb 'rest' in-between reads, etc? Is there something I am missing?
I have set the registers as per the datasheet for the 16f887:
CM1CON0=%00000000 'disable COMPARATOR 1
CM2CON0=%00000000 'disable COMPARATOR 2
trisb = %11111111 'set all pins to input
Any ideas?
Re: Reading Input on Port B
Maybe the victim of R-M-W? I am guessing the do something part may be setting output pins high? If they are on the same port, maybe this is the problem. I like to grab the input port and put it in a variable. Then I can check the bits in the variable and do something -or not.
Just suggestions, I am not sure of the problem.
Re: Reading Input on Port B
Quote:
Maybe the victim of R-M-W?
Nope.
Pins that power-up as analog inputs, when read (assuming it's a digital input), will read ZERO unless you have disabled the analog peripheral on the pin you're reading.
TIP: Look at ANSELH.
I'll bet, if you set all of these pins to logic 1 (externaly), they still all read zero until you disable the analog periperal!
Re: Reading Input on Port B
I have set:
ANSELH=%00000000
If I check for say a portb.3 button press, it works fine. If I check for a portb.5 button press it works fine.
However, if I check for say portb.3 and then portb.5 straight away, sometimes portb.5 comes back as 1 instead of 0, etc.
Re: Reading Input on Port B
Post your code. It's tough to help troubleshoot what we can't see..;)
Re: Reading Input on Port B