<< The Fribotte Home page >>

[Home] [Who are we?] [Robot] [Tech DB] [e=m6 cup] [Forum] [Reports] [Links]

The ports of a PIC are not enough numerou and should be saved.
But it is not always very simple. It is at the same time necessary to decrease the number of ports, not to add any other component (there is usually not much room on the board) and not to complicate the programming (there is not much room too there).
We will thus save the inputs/outputs by using only one port for two LEDs.


  The Diagram
The diagram is very simple :
2 LEDs for 1 port of a PIC
  • There are four LEDs
  • and two resistances of 100 ohms.

Price : 5 FF

Or :

  • There are two LEDs
  • Four diodes 1N4148
  • and two resistances of 100 ohms.

Price : 4 FF

2 LEDs for 1 port of the PIC
The principle is not much more difficult.

When the port of the PIC is at 0, the red LED is correctly polarized, the current crosses it (from 10 to 20 mA). It is lighted on. If the port is put at 1 (5V), this time the yellow LED is crossed by a current. Now if you quickly turn the port from 0 to 1 and 1 to 0 (at more 50Hz), you will have the impression that the two LEDs are lit.

You know now how to light the red LED or the yellow one, individually or simultaneously (at least seemingly),

  • But how to turn them off both ?
  • It is very simple ;-)

You just have to turn the port in high impedance, i.e. input. And the LEDs will not be any more fed and will be thus turned off.

I can now explain you the role of the second LED in series (or of the 2 diodes): When the port is set as an input, the wiring is found isolated from the PIC. The 4 LEDs and 2 resistances in series are fed in 5V but this is not sufficient to light on the LEDs. The threshold of the LEDs being of 1,5V minimum, it would be necessary at least to have 6V so that a current crosses them (it is the same thing for the diodes with a threshold of 0,6V minimum, having a power of 5,4 V). This phenomenon does not occur if the PIC itself feeds the high or low part of the diagram, in this case the threshold are at 3V (or 2,7V).

By the way ! : When you light the 2 LEDs, the average power is shared between the two and when you want to light only one LED, it receives all the power. Therefore to do it properly, in order to have the LEDs lit with the same intensity and in the case of one single LED lit, it is necessary swing from a high/low level to a high impedance state (and not as I wrote it before, I wanted to simplify the description).

Have you understood ?

Well. Very well. You now just have to write the program ;-)
So I launch the contest of the most optimised function to light on these LEDs. It's your turn to work !

I will soon give my answer and the most interesting ones that I have received on the forum.


Another solution.
You liked it ?

Well! Before going on and giving you the PIC program, I give you another diagram.
It has even less components and it uses the same program. The disadvantage is that it has a very bad throughput.

2 LEDs for 1 port of a PIC
  • There are 2 LEDs
  • and 2 resistances of 100 ohms.
  • Price : 3 FF

  • You can also replace the 2 LEDs
    by a two-tone LED with 2 pins.
  • Price : 6 FF

How does it work ?

As for the first 2 wirings, there are 3 cases to study :

First case :

The port of the PIC is in a high impedance state.
Both LEDs are off.

One of the pins of each LEDs is found off-line, thus no current crosses them.
On the other hand, the resistances are crossed by a current which is wasted (approximately 25mA).

Equivalent diagram :
2 LEDs pour 1 port du PIC

Second case :

The port of the PIC is at 1.
The red LED is lit.

The port is at approximately 5V, the LED D2 is polarized in reverse thus no current crosses it. The LED D1 remains in the equivalent diagram in parallel with the resistance R1.
The LED is crossed by a current ranging from 10 to 20mA for a loss in the resistance R1 from 15 to 20 mA.

Equivalent diagram :
2 LEDs pour 1 port du PIC

Third and last case :

The port of the PIC is at 0.
The yellow LED is lit.

The port is at approximately 0V, the LED D1 is polarized in reverse, which in the equivalent diagram puts the LED D2 in parallel with resistance R2.
And as for the preceding case, the current of the LED ranges from 10 to 20mA and the loss from 15 to 20mA

Equivalent diagram :
2 LEDs pour 1 port du PIC


Dernière modification : february 8 2000