PDA

View Full Version : Using 18F4525 with PortA defined as all inputs - RA2 and RA3 always show logic 0



rknepp
- 8th March 2011, 13:14
I am using an 18F4525 and I would like to use PortA as inputs. I am using an external osc, so pins RA6 and RA7 are allocated for that function. I have configured PortA to be all inputs, but when I read the port with logic 1 on the inputs, RA2 and RA3 always show 0. Can someone point out what I am doing wrong? Thank you.

porta = %00000000
adcon1 = %11111111 ' PortA - Set to digital
cmcon = %00000111 ' Disable Comparators
trisa = %11111111 ' PortA - All Inputs
trisb = %00000000 ' PortB - All Outputs

statusloop: portb = porta
pause 500
goto statusloop

I have LEDs on all PortB pins and bits 0, 1, 4, & 5 follow the logic placed on the corresponding PortA pins. Bits 2 and 3 always show 0.

cncmachineguy
- 8th March 2011, 13:44
maybe this is the problem?:


Note: On a Power-on Reset, RB4:RB0 are
configured as analog inputs by default and
read as ‘0’; RB7:RB5 are configured as
digital inputs.
By programming the Configuration bit,
PBADEN, RB4:RB0 will alternatively be
configured as digital inputs on POR.

rknepp
- 8th March 2011, 14:05
In my full program I flash all of the LEDs on PortB to show that PortB is working correctly and they do all flash as I would expect them to. I believe that it is something with the configuration of PortA, but I don't know what! Thank you.

Bruce
- 8th March 2011, 14:24
Try adcon1 = %00001111. With adcon1 = %11111111 you have RA2 and RA3 set for Vref- & Vref+.

cncmachineguy
- 8th March 2011, 14:35
I doubt this is it, but can you try it with


adcon1 = %11001111