PIC's and LED's

Thread Starter

dayv3

Joined May 22, 2014
38
Hi,

I normally attach a resistor and then a LED to an output port pin and then give the LED a
logic one to turn it on. While looking at what other people have done I have found circuits
where the PIC supplied the ground instead of the power (the opposite of what I do.) but more
importantly I found a circuit where the designer sourced the LED with a output port pin but then
supplied the ground with a input port pin thus using two pins on the PIC.

Questions:
Does anyone know why one would source and ground a LED using two ports?

Is there any advantage to doing one way over the other?

I know this is a simple task but, I am curious about this one.
Dave
 

elec_mech

Joined Nov 12, 2008
1,500
Does anyone know why one would source and ground a LED using two ports?
Perhaps if they were using the ports to control something else using those same pins and/or performing some logic function, e.g., if pin 1 is high and pin 2 is low, then LED is lit.

This is often done when driving multiple LED's in order to conserve pins which is known as multiplexing. For instance, same you want to control 20 LED's. You can make up five rows of 4 LED's each. The anode for each LED in the same row is connected together. The cathode for each LED in the same column is connected together. Now you only need 9 I/O pins instead of 20.

Is there any advantage to doing one way over the other?
Not sure about using two pins to control a single LED, but as far as sourcing or sinking a pin to control an LED, it depends. Some microcontrollers can sink more current on a pin than source current, so that may be a deciding factor on which type to use. If they are the same, then there isn't an advantage I'm aware of other than making the program or circuit simpler to wire or program in some way.
 

MikeML

Joined Oct 2, 2009
5,444
Another idea= use a bi-color LED, or a RED inverse-connected with a GREEN. Now you can get four states: OFF (both pins high or low), RED (one high, other low), GREEN (one low, other high), and AMBER(square wave, and inverted square wave).

Some pins can sink more current than they can source, so active-low to light the LED is often preferred.
 

Thread Starter

dayv3

Joined May 22, 2014
38
Another idea= use a bi-color LED, or a RED inverse-connected with a GREEN. Now you can get four states: OFF (both pins high or low), RED (one high, other low), GREEN (one low, other high), and AMBER(square wave, and inverted square wave).
Must admit I did not think of that one. I like it. Thanks
Dave
 
Top