0
\$\begingroup\$

I am working on PIC18F4550.

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

PORTA=0X00;
LATA=0X00;
ADCON1=0x0F; 
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.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Circuit diagram ? \$\endgroup\$
    – brhans
    Commented Mar 17, 2015 at 17:25

1 Answer 1

4
\$\begingroup\$

Your inputs may be lacking pull up resistors. Without them, the inputs float and can be at any voltage level.

Some inputs can be pulled up internally by configuring them that way. But not on port A for this device. (It is available on port B, though.)

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Or pull down if he's setting the outputs to 1 to drive a column / row in the matrix... \$\endgroup\$
    – Majenko
    Commented Mar 17, 2015 at 17:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.