Hi.. >(Alternatively, make B0-B3 >outputs, A2 input, strobe each in turn, and look for corresponding >strobe on A2). Yeah I'd do it this way: Connect one side of each switch to A2 with a 10k pullup resistor to Vdd. Connect the other side of the switches to B0-B3. bring B0 low, with B1-3 high. if RA2 is low key 1 is pressed. bring B1 low, the others high if RA2 is low key 2 is pressed. etc BTW if you had a pin on portb spare you could use an internal pullup so wouldn't need the external one. Regards, Stewart Pye At 12:15 AM 13/06/99 -0700, you wrote: >Hi, > >I'm building a project which requires 4 pushbuttons to be attached to >a bus interface. I *could* obviously use a tristate buffer, but I'm >trying to keep the chip count down. I do have one spare pin on the >PIC (A2), so my initial solution was to have this pin as the common >connector to 4 switches, and have the other side of the switches >wired to B0-B3, (which is in use as part of a bus interface). >When the bus in in use, I float A2, so pressing a button doesn't >interfere with the bus operation. When I'm not using the bus, I flip >B0-B3 to inputs, set A2 high, read B0-B3, set A2 low, read B0-B3 again >and figure out which switches are closed. > >Of course, a moment's thought demonstrates that if two switches are >closed at the same time, unspeakable confusion will occur, because >two of the bus lines will be shorted together, regardless of whether >or not A2 is floating, and when the bus *is* in use, disaster will >occur. > >So, I'm thinking - presumably if I got a transistor for each line, >arranged in an open-collector configuration, such that B0-B3 remain >outputs, each driving a transistor, I could take the second >approach described above (use A2 as input), and it wouldn't matter >if two buttons were pressed simultaneously. (I don't need to detect >simultaneous presses - it's just that they can't interfere with >anything!). > >My question is, (and once again, I'm forced to demonstrate my >complete lack of elec eng knowledge...), how exactly do I connect >the transistors? I need a series resistor on the base, yes? If so, >what sort of value should I use? > >Alternatively, if anyone can suggest a simpler way to get around >this problem, I'm all ears! > >Cheers, >Ben >