Need help! for microprocessor project.. 7x30 or 8x24 led dot matrix

Status
Not open for further replies.
hi jumper2high , you are right. I also noticed my program takes much more memory in pic.
Could you help me to optimize the code? Or just give me some hint for that...It will be helpfull for me....
 

Vinod,

I already wrote this in another topic, about the same thing - using IF statements to decode a character to 5x8 matrix is very costly in program memory and execution time. An 'if' statement is translated into several processor operations (load a literal, subtract it from the 'test number' and branch based on zero (or carry depending whether we're using if(c == somethng) or if (c < something)). So, at least 3-4 operations for every IF statement, and in the font() method, you have 100 of them. That means you're using 300-400 instruction words to handle the 'font'. This is exactly why I always say that anyone doing PIC programming should START WITH ASSEMBLER - so you get the "feel" for what a certain C command entails and how it's translated to machine instructions.

This also means that if the character you're looking for is 'a' - it will get to it in 3-4 instruction cycles, but if you're looking for the minus sign, it will get to it in 300-350 instruction cycles. Now remember, you're doing a LED Matrix program, so it is important that you 'scan' the matrix in correct timed sequence - so variable execution really screws up that plan. Now, imagine the following situation:

We store all 'font information' in EEPROM or initialize a bunch of general purpose registers for that purpose and organize them in the same order as they are in the ascii table. Then we make a 'font' method something like this:
Code:
void font(unsigned char c) {
		//Subtract 32 from c so that
		//the first usable character of the 
		//ascii table (Space) is 0 in our font
		//array.
	addr = c - 32;
		//Now we need to multiply addr x 5 because
		//or font is 5 bytes 'wide'.
	addr +=addr;
	addr +=addr;
	addr +=addr;
	addr +=addr;
		//We move the calculated address to the
		//EEPROM addressing register
	EEADR = addr;
		//And we have the first byte of the font
		//in EEDATA register so we send it off to the 
		//method for refreshing the display and carry on.
	EEADDR++;
		//Now we have the second byte, which we also send
		//to the method for refreshing
		
		//..and continue this for 3 other bytes. 
}

This function will decode a character to a font in 10 instruction cycles no matter which character it is, because it does the SAME operations only with different numbers. It's not so much of a big deal to save 300 words of program memory, but the fixed execution time (and a LOT quicker decoding) will not screw up your display timing and won't make some characters in different brightness.

Similarly, the scrolling text can be done in far less 'work' for the processor. Instead of referencing them directly one by one - use another block of general purpose registers to put the actual chars in there, and then just use a counter variable to go through it.

That way, instead of doing

(z13=z12);
(z12=z11);
(z11=z10);
...
40 times, you just increment (or decrement, depending on which way you want the text to scroll) the counter and have it wrap around the number of chars you have on the display by re-setting the counter when exceeds a certain value.
Code:
if(counter == 29)
	counter = 0;
else
	counter++;
So, the first time - it'll go from 0 to 29, then from 1 to 29 and wrap to 0. Then from 2 to 29, wrap to 0 and 1. Etc...

Oh, and I'd implement a TIMER interrupt system to 'time' the shifting through every character, instead of just using delay routines, because - just like variable execution time, it can make your characters different in intensity on the display.
 




hello, how the schematic will be look like?
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…