LEDs lighting

Discussion in 'Embedded Systems and Microcontrollers' started by alex90, Nov 27, 2013.

  1. alex90

    Thread Starter New Member

    Nov 27, 2013
    Hi guys,

    I am very new to embedded systems and I have very little knowledges about them and electronics.
    Recentrly I started to read a book(a little old) and I need some explanations about how the LEDs are illuminated because it didn't explain on the book.I use Pickit 1 flash starter kit, and a PIC16f684.
    Here is the diagram of LEDs(from my Pickit 1 flash starter kit user's guide)

    Here is the diagram from the old book:

    The C code is here:

    Code ( (Unknown Language)):
    2. #include<pic.h>
    6. main()
    7. {
    8.     PORTA = 0;
    9.     CMCON0 = 7;
    10.     ANSEL = 0;
    11.     TRISA = 0b001001;
    13.     while(1 == 1)
    14.     {
    15.         if(0 == RA3)
    16.         PORTA = 0b010010;
    18.         else
    19.         PORTA = 0b000100;
    21.     }
    22. }
    When I press the switch button the 0 and 7 LEDs are full lit and the 2 LED is lit but less then two others.
    When I release the button, 3, 5 and 6 LEDs are illuminated with the same power.
    So please if you can explain me why some LEDs are illuminated more than others or have the same power.I really want to learn embedded systems and I know I need electronics, but I believe that with your help I will succeed.
    Thank you and excuse me for my english if it is bad.
    Last edited by a moderator: Nov 27, 2013
  2. Markd77

    Senior Member

    Sep 7, 2009
    The normal way to use Charlieplexing (the name for the way these LEDs are wired up) is to set one pin to 1, another pin to 0, and to have all the other pins set to input so no current flows in them. That way there is one LED lit at full power. If you want it to appear that more than on LED is on then alternate between them fast enough that the eye can't tell the difference. With more than two pins set as outputs it quickly gets confusing.
  3. bwack

    Active Member

    Nov 15, 2011
    There are a couple of basic principles you need to know about electronics. The voltage law (KVL) and the current law (KCL).

    The sum of each voltage drop equals the total voltage in the circuit.
    The sum of each branch of current running into a point equals zero.

    In practice this means, if you have a device that drops 2V (the red led infact), you can subtract that from the total (5V battery), and the rest will lay over the rest of the circuit. Do this for both pressed and unpressed. PORTA=0b010010; means that RA1=RA4=5V, RA2=RA5=0V.
    Sorry I was interrupted. I'll finnish maybe later.
    Last edited: Nov 27, 2013
  4. bwack

    Active Member

    Nov 15, 2011
    I was going to draw the currents on the schematics, but it got quite confusing with the four pins as outputs. Maybe node analysis has to be done to show why some leds are brighter than others.
  5. alex90

    Thread Starter New Member

    Nov 27, 2013
    Thanks guys, you helped me with your answers.Now I can go to the next lesson. :)
  6. Art

    Distinguished Member

    Sep 10, 2007
    Does this lesson 1 source code and schematic belong together and provided by Microchip?
    I hope the future lessons are more relevant to the hardware.

    Is this that little development board that comes with a pickit?

    Lesson one is a pile of ****, and should only have dealt with two of those LEDs.
  7. bwack

    Active Member

    Nov 15, 2011