Connect with us

Help with a keypad connection to GPIO pins

Discussion in 'Electronic Basics' started by [email protected], Apr 8, 2005.

Scroll to continue with content
  1. Guest

    I am hoping someone in this group can explain why, the below, is ok to
    do. I'm a little cautious in implementing it because I already did
    something similar (without pulling up the 4-lines high with resisters)
    and it appears to have shorted the ports on my development board. I
    don't want to make another costly mistake! If you can respond to
    this...I'll be very indebted!

    I'm attaching a schematic of what Zilog recommends in terms of how to
    connect a keyboard to the GPIO ports. The problem I have is that I
    don't understand it. Specifically:

    Looking at the schematic - If you imagine that the GPIO pins PB4 - PB7
    are output and set to high...and that the pins PB0 - PB3 are set to
    input. And that by pressing a key you make a direct connection from
    PB7 out through line 1 of the keypad then it would see that you would
    have a problem. with the current going through PB0. Because it is
    being sent through PB7 through the keypad and out of line 1 and into
    PB0 directly (there is no resister on that end) you would have a
    problem, wouldn't you?

    Initially I think I burnt out my development board because I had half
    of the GPIO pins tied to the input of the other half of the pins with
    no current limiting resister. It appears that this schematic does the
    same thing, doesn't it?

    Some further information about the pins when they are set to output
    and input modes is in the other attachment, GPIO modes.jpg.

    The problem I'm having is that - based on the table you see in that
    attachment it appears that there should not be any problem connecting
    the output of one pin to the input of another. Because it is 'high
    impedance' it limits the current and, therefore, I don't need a
    limiting resister. If that's the case - how did I destroy my original
    development board? I didn't use resisters but I did tie the output to
    the input of another pin.

    Links to the two examples I'm talking about can be found:

    Thanks very much for your help!
  2. Bob Monsen

    Bob Monsen Guest

    If PB0 is an input, it won't act like it's an output. It acts like a 1MEG
    resistor, unless you have pullups enabled, in which case it'll act like a
    resistor of whatever value the pullups are. I don't know which processor
    you are using (your schematic didn't make it) so I can't help there.
    It may, or it may not. Again, no schematic.
    This is true
    I dont' know. However, it's possible that the processor comes up with all
    outputs. I know the PICs don't do this, for this very reason; they all
    start out as inputs.

    If you have a software bug where you've made them outputs by mistake,
    they'll pass as much current as they can.

    Another possibility is that the input was whacked by SCR latchup. If you
    put too much current into an input, and it is higher or lower than the
    power pins, it can get stuck into a state where the pin is sinking large
    amounts of current. If you don't catch it and stop it, it'll destroy the
    input port.

    One simple thing you can do is read the datasheet, and find out what the
    maximum current is into a pin, and put a resistor there that will keep it
    from getting to that maximum current. So, if the max current is, say,
    20mA, and your power rail is 5V, you put a 5/.02 = 250 ohm resistor in
    front of the port. That way, no matter what you do, you won't be able to
    hurt it.
  3. Lord Garth

    Lord Garth Guest

    Forgetting all else, if PB4 - PB7 are output and set high, you can't get
    anything useful like this. You must ripple a low (0) from PB4 through
    PB7 with your keyboard routine. 0111, 1011, 1101, 1110 rapidly.
    Between each increment, you read PB0 through PB3 for a low input.
    Pull-up resistors wouldn't hurt anything and is recommended.

    Knowing which output bit is low and which input bit read that low
    allows you to know which key was pressed. Any low that is read should
    stop scanning and re-read the input to eliminate bounce. Scanning should
    resume when the inputs are again all high.

    The tricky part comes when more than one key is simultaneously pressed.
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Electronics Point Logo
Continue to site
Quote of the day