Diode in serial with switch...purpose?

Thread Starter

upand_at_them

Joined May 15, 2010
552
Regarding the image below. I don't understand the purpose of the diodes on the switches. (Ignoring RB4, that's a special case.)

The way the display works is that each digit is enabled, in turn. Digit 1 is connected to switch 1, digit 2 to switch 2, etc. As a digit is enabled, the switch connected to that pin can be tested for being closed. Clever.

RB4 - RB7 are set as outputs, never input. The pin is set high to enable that digit and set low when any other digit is enabled. The pin that reads the switches, RA3, only acts as an input (by design that's all it can do).

But I don't see the purpose of the diodes. I've tested this without the diode on, say, RB5/switch2, and it doesn't appear to be any different. The only thing I can think of is that maybe the diode helps the switching function?

4-Digit Schematic.jpg

EDIT: I cleaned up the image to be more concise, for the question.
 
Last edited:

Thread Starter

upand_at_them

Joined May 15, 2010
552
A-ha!

So, without the diodes, if two buttons are pressed at the same time, the HIGH from one digit pin is shorted to the LOW of the other digit pin (because at some point one digit will be enabled and the other disabled).

And with the diodes, the short never happens.

Thanks.
 

MisterBill2

Joined Jan 23, 2018
7,315
A-ha!

So, without the diodes, if two buttons are pressed at the same time, the HIGH from one digit pin is shorted to the LOW of the other digit pin (because at some point one digit will be enabled and the other disabled).

And with the diodes, the short never happens.

Thanks.
Exactly. The diodes are there for isolation. The 4 switches are only read when that RA3 line is pulled low.
 

Thread Starter

upand_at_them

Joined May 15, 2010
552
The 4 switches are only read when that RA3 line is pulled low.
Hi MisterBill,

Common to all PIC's, the RA3 pin (or the RA4 pin on many PIC's) can only act as an input. It's never pulled low, only ever high-Z. As each display digit is enabled the switch connected to that pin is read because it then has a "pullup" to HIGH. It's a clever way to have the switches share pins with the display.
 
Last edited:
Top