PIC's and LED's

Discussion in 'Embedded Systems and Microcontrollers' started by dayv3, Dec 28, 2014.

  1. dayv3

    Thread Starter Member

    May 22, 2014

    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.

    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.
  2. shteii01

    AAC Fanatic!

    Feb 19, 2010
    I would file that under: control freak.
  3. elec_mech

    Senior Member

    Nov 12, 2008
    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.

    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.
  4. MikeML

    AAC Fanatic!

    Oct 2, 2009
    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.
    elec_mech likes this.
  5. dayv3

    Thread Starter Member

    May 22, 2014
    Must admit I did not think of that one. I like it. Thanks