# PIC 18F PORTA pins as input

I am working on PIC18F4550.

I have configured PORTA Pin0-Pin3 as inputs using following code

PORTA=0X00;
LATA=0X00;
CMCON = 0x07;
TRISA =0XCF;


and PORTE as outputs using following code

TRISEbits.TRISE0=0
TRISEbits.TRISE1=0;
TRISEbits.TRISE2=0;


I have connected a passive keypad to this pins and I am just scanning inputs by making outputs 1 at a time.

But I am getting very erratic values in PORTA register. I even tried debugging using pickit3. I set a break point just after making output 1 and before I scan for inputs. PORTA register is changing in whimsical manner even when I haven't pressed any key. Please suggest what I might be doing wrong.

## migrated from meta.electronics.stackexchange.comMar 17 '15 at 17:23

This question came from our discussion, support, and feature requests site for electronic hardware hacking enthusiasts.

• Circuit diagram ? – brhans Mar 17 '15 at 17:25