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.

[SOLVED] Simplifying C script for controlling 64 LEDs

Status
Not open for further replies.

anschau

Newbie level 4
Newbie level 4
Joined
Jun 14, 2011
Messages
7
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,333
Hello, i am currently trying to make a led matrix. I am running all the leds off of 8 74HC595 shift registers linked together. my problem is that i have 64 leds to control and to set each led high or low i have to do something like this.

PORTA = 0b00000001;
PORTA = 0b00000010;
PORTA = 0b00000100;

that is to set one led to high, and doing that 64 times for one image takes a lot of time. I know there is a simpler way to this. I tried using a function like this.

PIN_HIGH {
PORTA = 0b00000001;
PORTA = 0b00000010;
PORTA = 0b00000100;
}

but it did not work. I am not sure what i am doing wrong here. Any help would be much appreciated.
 

Re: simplifying C Script

You can do
Code:
for(i=0;i<=7;i++) PORTA = 0b00000001 << i;
 

Re: simplifying C Script

Thank you for your suggestion, but is it possible to use a function to do it? because i was looking for something simple. say i have function A and function B. i was hoping i could just do something like ABBBABBBAAAAABBBBABBB etc. to simplify making an entire animation on the matrix.
 

Re: simplifying C Script

Thank you for your suggestion, but is it possible to use a function to do it? because i was looking for something simple. say i have function A and function B. i was hoping i could just do something like ABBBABBBAAAAABBBBABBB etc. to simplify making an entire animation on the matrix.
I don't understand what are you going to do. Maybe you should share schematic. This is example 48X8 dot matrix.
 

Re: simplifying C Script

... and C source code.. (moste important part of it)
 

Re: simplifying C Script

Thank you for your suggestion, but is it possible to use a function to do it?
Sure, your function should look like this:

Code:
void PIN_HIGH() {
PORTA = 0b00000001;
PORTA = 0b00000010;
PORTA = 0b00000100;
}
 

Re: simplifying C Script

Okay thank you. That is what i wanted to know, i guess i just left a few things out. thank you for all your help everyone!
 

Re: simplifying C Script

If you are not sending or receiving anything I don't see the reason to use a function
You can simply define a macro

Code:
#define PIN_HIGH PORTA = 0b00000001; PORTA = 0b00000010; PORTA = 0b00000100;

whenever you write PIN_HIGH it will be the same as writing PORTA = 0b00000001; PORTA = 0b00000010; PORTA = 0b00000100;

Alex
 

Re: simplifying C Script

Wow thank you that worked, and it was so much easier than trying to call a function later in the program.
 

Re: simplifying C Script

I don't see how using "PIN_HIGH" is "so much easier" than "PIN_HIGH()"..
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top