A less Cumbersome way of manipulating several LEDS?
Hi all,
I seek an easier way of controlling leds!
At the minute, due to my restrictive board layout, I've several leds scattered across all the PIC's port/pins, for example...
Code:
LED0 VAR PortC.6
LED1 VAR PortB.6
LED2 VAR PortB.5
LED3 VAR PortB.4
LED4 VAR PortC.2
LED5 VAR PortC.1
LED6 VAR PortC.0
LED7 VAR PortA.2
LED8 VAR PortA.1
at the minute, to say switch some leds on/off, I'm doing something like this.
Code:
high led0
high led1
low led2
low led3
high led4
...which ok isn't too bad, but gets rather long winded - especially when you want a few different permutations.
Forgive the naive line of questioning, but is there anyway, I can group the 'port diverse' LED mappings all together into something like a virtual Port (or logical byte/word), where I could for example do something like this....
if so, bear in mind I have 9 LEDs ...how would that work out with the above in mind?!
In a similar vein, can I group just two specific leds together for ease of handling? (I always will want two specific LEDS to light/extinguish together - but want to treat them as one entity vs having to duplicate the commands to each port/pin per LED)
Many thanks!
Re: A less Cumbersome way of manipulating several LEDS?
how fast human eye is btw? vport is nowhere near to be that slow
Re: A less Cumbersome way of manipulating several LEDS?
Quote:
In a similar vein, can I group just two specific leds together for ease of handling? (I always will want two specific LEDS to light/extinguish together - but want to treat them as one entity vs having to duplicate the commands to each port/pin per LED)
Why not wire them in "anti-parallel" then? One is on when pin is low, the other when pin is high and both are off when TRIS is 1.
/Henrik.
Re: A less Cumbersome way of manipulating several LEDS?
Quote:
Originally Posted by
HenrikOlsson
Why not wire them in "anti-parallel" then? One is on when pin is low, the other when pin is high and both are off when TRIS is 1.
/Henrik.
Because I need them to light up together....if I'm reading your suggestion correctly, only one LED can be on at a time?
Re: A less Cumbersome way of manipulating several LEDS?
Sorry, I misunderstood that. I thought you wanted one on when the other was off. I guess I kind of took that for granted because I can't really see the point in using more than one pin. Just wire the LEDs in parallel or, which is probably better, in series. Depends on the powersupply voltage and forward voltage drop of the particular LED.
Are these some high power blue LEDs? High current and high Vf? Is that the reason you need one pin for each LED? Please tell me what I'm missing :-)
/Henrik.
Re: A less Cumbersome way of manipulating several LEDS?
Quote:
Originally Posted by
HenrikOlsson
Sorry, I misunderstood that. I thought you wanted one on when the other was off. I guess I kind of took that for granted because I can't really see the point in using more than one pin. Just wire the LEDs in parallel or, which is probably better, in series. Depends on the powersupply voltage and forward voltage drop of the particular LED.
Are these some high power blue LEDs? High current and high Vf? Is that the reason you need one pin for each LED? Please tell me what I'm missing :-)
/Henrik.
Yes, I'm using high brightness blue leds (fwd voltage 3.2V, my PSU is 4V) in parallel drawing about 20mA, therefore two = 40ma...too much for one PIC pin...hence wanting to treat two pins as one virtual pin in code. But it's no big deal....thought I'd ask - and as ever there is something that exists that can be brought into play, except that I need to control the pin on/off via TRISC to avoid clicking so I can't personally use it.
Re: A less Cumbersome way of manipulating several LEDS?
Maybe something like this? Not very swanky, but should work.
Code:
LED VAR WORD
Main:
LED = %XXXXX111111111 'ALL LEDS ON
GOSUB LED_OUT
LED = %XXXXX000000000 'ALL LEDS OFF
GOSUB LED_OUT
Goto Main
LED_OUT:
PORTC.6 = LED.0
PORTB.6 = LED.1
PORTB.5 = LED.2
PORTB.4 = LED.3
PORTC.2 = LED.4
PORTC.1 = LED.5
PORTC.0 = LED.6
PORTA.2 = LED.7
PORTA.1 = LED.8
RETURN
Re: A less Cumbersome way of manipulating several LEDS?
Since you are driving LEDs, why not MIBAM ?
Re: A less Cumbersome way of manipulating several LEDS?
Quote:
Originally Posted by
sayzer
Since you are driving LEDs, why not MIBAM ?
I have a common dim function in place already (via a PWM driven mosfet)...I don't really need dimming per pin
Re: A less Cumbersome way of manipulating several LEDS?
Hi Mark, Apologies...I missed your earlier contribution...that looks like something along the lines of what I need...I'll give it a try over the weekend - many thanks!
Re: A less Cumbersome way of manipulating several LEDS?
You probably realize this... but you will need a pause, of some time delay, after each "GOSUB LED_OUT", in Mark's example. In order for your eye to see the LED's ON or OFF or they may just appear to be flickering at half brighteness.
Also the "X's" in the example will not compile... need to use "0's". At least they don't compile using microcodestudio.
Code:
LED VAR WORD
Main:
LED = %0000000111111111 'ALL LEDS ON
GOSUB LED_OUT
PAUSE 500 'or delay of your choosing
LED = %0000000000000000 'ALL LEDS OFF
GOSUB LED_OUT
PAUSE 1000 'or delay of your choosing
Goto Main
LED_OUT:
PORTC.6 = LED.0
PORTB.6 = LED.1
PORTB.5 = LED.2
PORTB.4 = LED.3
PORTC.2 = LED.4
PORTC.1 = LED.5
PORTC.0 = LED.6
PORTA.2 = LED.7
PORTA.1 = LED.8
RETURN
good luck!!
Re: A less Cumbersome way of manipulating several LEDS?
Heckler, you are right on all accounts.
In the digital world "X" means "don't care". A 1 or 0 will not cause a state change.
Sorry for the confusion. In PBP you can drop the leading zeros in a binary variable.
This %000000111111111 would equal %111111111.
Best regards