I am working on PIC18F4550.

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

CMCON = 0x07;

and PORTE as outputs using following code


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.

  • 1
    \$\begingroup\$ Circuit diagram ? \$\endgroup\$ – brhans Mar 17 '15 at 17:25

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.)

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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