PDA

View Full Version : PORTB.3 Input not working as expected.



BobEdge
- 5th March 2013, 09:24
Hi,

I am having a problem with using port B as inputs. The inputs are inverted. Here is the code.


#config
__config _HS_OSC & _WDT_ON & _PWRTE_ON & _BOREN_ON & _CP_ON
#ENDCONFIG
define OSC 20
TRISC = 0
TRISD = 0
TRISB = 255

led1 var portd.7
led2 var portd.6
led3 var portd.5
led4 var portd.4
led5 var portd.5
led6 var portc.7
switch var portb.3

high led5
high led6

start:
if switch = 0 then
high led1
high led2
high led3
high led4
pause 3000
endif
portd = 0
while switch = 0
wend
goto start
end
I have tried the same code on both 871, and 877A with the same results.
If I move the switch to any other port B pin then the program works as expected, the LEDs light for 3 seconds, and will only light again after releasing, and pressing the switch again.

With the switch on port B3 pressing the switch turns on the LEDs as expected, but if I let go of the switch all outputs switch off instantly, not after 3 seconds. Then pressing the switch again will light up all of the outputs again, the first 4 for 3 seconds if I keep the switch pressed. Letting the switch go after that will turn off all outputs.

It seems that taking B3 low is ok but then if it goes high again then the outputs all go off, and the program will not function.

Anyone have any ideas please?

Regards
Bob.

BobEdge
- 5th March 2013, 09:58
Hi,

As usual after trawling the net, and data sheets for many hours, I have found the answer only 10 mins after posting.
When programming disable low voltage programming mode, and something called CPD also off.

I have never understood why things default to a state which makes pins unusable as GPIO, AD converter, CMCON.7. Surely it would make sense to turn features on if you want to use them, rather than having to turn off anything you don't want.

Regards
Bob.