2 LEDs used Bi-directionally


Closed Thread
Results 1 to 15 of 15
  1. #1
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,154

    Default 2 LEDs used Bi-directionally

    I'm building a matrix using this idea:
    http://www.picbasic.co.uk/forum/showthread.php?t=14439

    Name:  Bi-directional LEDs.JPG
Views: 533
Size:  51.8 KB

    Pseudo-code:
    Code:
    GP0 TRIS 1     ' Input
    GP1 TRIS 0     ' Output
    GP1 = 1         ' Yellow ON
    
    GP0 TRIS 0     ' Output
    GP1 TRIS 1     ' Input
    GP0 = 1         ' Red ON
    Is that right?

    And how do you turn them both off? Both output LOW?

    Robert

  2. #2
    Join Date
    Jan 2009
    Location
    Miami, Florida USA
    Posts
    699


    Did you find this post helpful? Yes | No

    Default Re: 2 LEDs used Bi-directionally

    Check this thread out. You might get some hints...

    http://www.picbasic.co.uk/forum/show...1692#post91692
    "No one is completely worthless. They can always serve as a bad example."

    Anonymous

  3. #3
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,154


    Did you find this post helpful? Yes | No

    Default Re: 2 LEDs used Bi-directionally

    I had read that thread already, but they were going PIN to VDD/VSS. I'm going PIN to PIN so I have to play with TRIS more. Rereading it did show me TRISx = 1 will turn off LEDs though.

    Setting up the breadboard to test what I have so far. I better change for an old PIC, just in case of magic.

  4. #4
    Join Date
    Jan 2009
    Location
    Miami, Florida USA
    Posts
    699


    Did you find this post helpful? Yes | No

    Default Re: 2 LEDs used Bi-directionally

    TRISx = 1 is used to read an analog input, ex: A/D input. It turns the port into a high impedance input. So, if you want the port to sink in current just make that port low with TRISx = 0 like in the example in that thread.
    "No one is completely worthless. They can always serve as a bad example."

    Anonymous

  5. #5
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,154


    Did you find this post helpful? Yes | No

    Default Re: 2 LEDs used Bi-directionally

    I feel like a retard. So...

    PIN --- DUAL LEDs --- RESISTOR --- 5VDC

    PIN defined as output:

    HIGH will source, turn on outgoing LED (like we always do)
    LOW will sink, turn on incoming LED


    I don't get how I'm to set ports/TRIS at both ends so neither LED will turn on. I've gone through that thread and a few others all evening but I can't see the forest through the trees apparently.


    Quote Originally Posted by rsocor01 View Post
    TRISx = 1 is used to read an analog input, ex: A/D input. ...
    Even if my ports are defined as digital?

    Robert
    Last edited by Demon; - 12th January 2014 at 05:01. Reason: analog VS digital

  6. #6
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,154


    Did you find this post helpful? Yes | No

    Default Re: 2 LEDs used Bi-directionally

    Found my answer to sinking the incoming LED.

    Do I set it as an output then set it's low state?
    Quote Originally Posted by mackrackit View Post
    YUP.

    Think of it like this. LED connected anode to positive rail. To make it light with the cathode connected to a PIC pin you would output LOW. (LED has a drop down resistor)
    ...
    http://www.picbasic.co.uk/forum/showthread.php?t=7638


    PIN --- DUAL LEDs --- RESISTOR --- PIN

    Is it a simple matter of leaving both pins output LOW? That would mean both are connected to ground; no chance of leaking current.

    Robert

  7. #7
    Join Date
    Oct 2009
    Location
    Utah, USA
    Posts
    427


    Did you find this post helpful? Yes | No

    Default Re: 2 LEDs used Bi-directionally

    Robert,

    In your schematic at the top of the thread... the highlighted (green) LED's will be dark when GP 1&2 are BOTH High OR LOW. But the trick is to keep track of that interaction with the other LED's that are also tied to either of those two pins.

    If GP1 is high and GP2 is low then the Yellow LED will be lit, and vice/versa for the Red one.

    Seems like to me it's time to draw up a good ol'e fashioned truth table.

    With 5 bits (pins) in use it will have 2 exp 5 = 32 possibilities. The truth table will also help you develop your code.

    Is this what they call Charlieplexing?? I've never done one of those, but that is how it seems to my feeble mind.

    good luck
    Dwight
    These PIC's are like intricate puzzles just waiting for one to discover their secrets and MASTER their capabilities.

  8. #8
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default Re: 2 LEDs used Bi-directionally

    Hi Robert,
    This is what Microchip did on their PICKIT1 demo board.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  9. #9
    Join Date
    Jan 2009
    Location
    Miami, Florida USA
    Posts
    699


    Did you find this post helpful? Yes | No

    Default Re: 2 LEDs used Bi-directionally

    Quote Originally Posted by Heckler View Post
    If GP1 is high and GP2 is low then the Yellow LED will be lit, and vice/versa for the Red one.

    Seems like to me it's time to draw up a good ol'e fashioned truth table.
    Yes, it seems like you are going to have more lit LEDs that what you want at any given time. More than one LED is going to light up for any given combination.
    "No one is completely worthless. They can always serve as a bad example."

    Anonymous

  10. #10
    Join Date
    Jan 2009
    Location
    Miami, Florida USA
    Posts
    699


    Did you find this post helpful? Yes | No

    Default Re: 2 LEDs used Bi-directionally

    Quote Originally Posted by Demon View Post

    Even if my ports are defined as digital?
    TRISx = 1 'Sets the port as analog
    TRISx = 0 'Sets the port as digital

    When TRISx = 1 the port is set to a high impedance input mode, meaning no current in or out for the LEDs. In other word it turns the port off for the LEDs.
    "No one is completely worthless. They can always serve as a bad example."

    Anonymous

  11. #11
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,154


    Did you find this post helpful? Yes | No

    Default Re: 2 LEDs used Bi-directionally

    Quote Originally Posted by rsocor01 View Post
    TRISx = 1 'Sets the port as analog
    TRISx = 0 'Sets the port as digital

    When TRISx = 1 the port is set to a high impedance input mode, meaning no current in or out for the LEDs. In other word it turns the port off for the LEDs.
    It seems I'm getting denser every year.

    "high impedance input mode" means nothing to me.

    "meaning no current in or out for the LEDs" <--- this I understand


    You only have to explain things once to me, but repeat yourself 12 times, post 3 sample programs, add 6 pictures, include 4 schematics, and I'm good to go.

    I really appreciate the patience you guys have.

    Robert

  12. #12
    Join Date
    Sep 2010
    Location
    Las Vegas, NV
    Posts
    305


    Did you find this post helpful? Yes | No

    Default Re: 2 LEDs used Bi-directionally

    In regard to the site mentioned in post #1:

    Just to let you know I found the value of the current limiting resistors for the LEDs to be important. Set incorrectly they'd give me ghosting.

    You also have to repeatedly set the TRISIO and the GPIO to get the specific LED or LEDs you want lit. Usually once wasn't good enough.

    If you're in need of more than 20mA per pin I successfully used opto-isolators instead of the LEDs. I don't remember the specific part number but I think I posted that link somewhere. If needed I'll find it and reference it here.

    I'd also suggest you put a switch in the ICSP clock and data lines to isolate the PIC for programming. It will save you alot of time and effort.

    As always good luck and please post program here when finished.

  13. #13
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,154


    Did you find this post helpful? Yes | No

    Default Re: 2 LEDs used Bi-directionally

    Quote Originally Posted by AvionicsMaster1 View Post
    In regard to the site mentioned in post #1:

    Just to let you know I found the value of the current limiting resistors for the LEDs to be important. Set incorrectly they'd give me ghosting...
    I'm using Darrel's interrupts to control blinking; both on and off duration. Ghosting is not a problem.


    Quote Originally Posted by AvionicsMaster1 View Post
    ...You also have to repeatedly set the TRISIO and the GPIO to get the specific LED or LEDs you want lit. Usually once wasn't good enough...
    I'm testing activating LEDs in bi-directionnal manner now. It's taking me a while 'cause I'm setting it up so the bytes RX from Master will line up with pin order. I'm also learning bit masking; never did that really.


    Quote Originally Posted by AvionicsMaster1 View Post
    ...If you're in need of more than 20mA per pin I successfully used opto-isolators instead of the LEDs. I don't remember the specific part number but I think I posted that link somewhere. If needed I'll find it and reference it here...
    I have MCT6 opto-isolators for now if needed. I don't know if I'll need faster, testing will show.


    Quote Originally Posted by AvionicsMaster1 View Post
    ...I'd also suggest you put a switch in the ICSP clock and data lines to isolate the PIC for programming. It will save you alot of time and effort...
    I simplified matters and dedicate MCLR, PGD, PGC, RX1 and TX1 pins.


    Now I just have to figure my bits:

    Code:
    Port has: 10001001
    Mask is:  10001111
    Desired:  10000110 (bits 7-4 untouched, bits 3-0 reversed)
    I made a truth table using an LCD to show how bitwise operators work. It's just setting up this particular syntax.

    Robert


    UPDATE: Have my bit masking working exsactly like I want it. Thanks everyone.
    Last edited by Demon; - 13th January 2014 at 01:43.

  14. #14
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,154


    Did you find this post helpful? Yes | No

    Default Re: 2 LEDs used Bi-directionally

    Quote Originally Posted by Demon View Post
    I'm building a matrix using this idea:
    http://www.picbasic.co.uk/forum/showthread.php?t=14439
    ...
    For those of you that are visual and like working with rows and columns like me, I came up with this design:

    Name:  CharliePlex.JPG
Views: 360
Size:  101.9 KB

    You can have a lot more LEDs by using pins across ROWs and COLUMNs, but that adds more complexity than I can handle, and this is good enough for me.

    By using a maximum of 8 pins per side in this configuration, you can use BYTEs and LOOPs to control lighting.

    Robert

  15. #15
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,154


    Did you find this post helpful? Yes | No

    Default Re: 2 LEDs used Bi-directionally

    And this is how I plan to turn the LEDs ON-OFF 1 column at a time:

    Name:  CharliePlex logic.JPG
Views: 373
Size:  66.2 KB

    (in theory, I still have to finish my breadboard)

Similar Threads

  1. 32 LEDs with less than 20mA
    By Demon in forum Off Topic
    Replies: 11
    Last Post: - 23rd January 2014, 03:28
  2. Leds on/off
    By Leonardo in forum mel PIC BASIC Pro
    Replies: 16
    Last Post: - 2nd September 2009, 21:36
  3. Two LEDs on one Pin
    By modifyit in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 6th June 2006, 13:32
  4. 8 Leds
    By leonel in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 24th June 2005, 22:15
  5. Want some help with LEDs
    By Srigopal007 in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 23rd November 2004, 20:46

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts