Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Driving LEDs, the Matrix way

Status
Not open for further replies.

millwood

Advanced Member level 3
Joined
Jul 2, 2009
Messages
733
Helped
80
Reputation
164
Reaction score
35
Trophy points
1,308
Activity points
5,088
matrix leds

I thought about ways to drive the most number of LEDs with a given number of pins from a mcu (a PIC in this case).

you can drive two LEDs from one pin - but one of the LEDs has to be on at a given point.

you can drive two LEDs from two pins - you can put both of them off.

with three pins, you can connect two LEDs, reverse biased, between any two pins so you can drive a total of 6 LEDs. However, you have to turn any pin that you are not using into a high impedance mode (input).

so here is a little program that demonstrates that concept. it runs on a 12f675, using three pins to drive six LEDs.

Code:
#include <htc.h>

#define COMBO	6
#define LEDPort	GPIO
unsigned char LEDArray[COMBO][2] = {//first byte for trisio and 2nd byte for port
	{0b100, 0b001},					//pin0//1 output, pin0 high pin1 low
	{0b010, 0b001},					//pin0//2 output, pin0 high pin2 low
	{0b100, 0b010},					//pin0//1 output, pin0 low pin1 high
	{0b001, 0b010},
	{0b010, 0b100},
	{0b001, 0b100}
};

void delay(unsigned long int dly) {
	for (; dly>0; dly--)
	;
}

__CONFIG(MCLRDIS & WDTDIS);

void
main(void)
{
	unsigned char i;
	
	CMCON=0x07;
	ANSEL=0x00;
	
	while (1){
		//TODO Auto-generated main function
		for (i=0; i<COMBO; i++) {
			TRISIO=LEDArray[i][0];
			LEDPort=LEDArray[i][1];
			delay(20000);
		}
	}
}

you can easily expand the program so that it can drive n*(n-1) LEDs using n pins.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top