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.

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.
 

i think its difficult to explain the full working, just if u found any problem while doing the project, then many one could help u....
i will just give an introduction if u r new to dotmatrix displays...
microcontroller is connected to row(7 rows),then connect a ring counter to 30 column (mod 30)
clock and reset of counter is controlled by microchip....

just read this sample c program i had done for our techfest (just day before yesterday)
then ask if u got any doubt....display which i made is 38x7 . just check the program and ask ur doubts...it will be better in ur case, i think so...



////////////////////////////////////////
//LED DOTMATRIX MESSAGE DISPLAY //
// vinodstanur@gmail.com //
////////////////////////////////////////
//used hightech c compiler(not free)////
////////////////////////////////////////
#include <htc.h>
#define _XTAL_FREQ 16e6 // 4MHz
__CONFIG(0x3F3A);

int a1,b1,c1,d1,e1,f1,g1,h1,i1,j1,k1,l1,m1,n1,o1,p1,q1,r1,s1,t1,u1,v1,w1,x1,y1,z1,z2,z3,z4,z5,z6,z7,z8,z9,z10,z11,z12,z13;


void begin()
{
(a1=0);(b1=0);(c1=0);(d1=0);(e1=0);(f1=0);(g1=0);(h1=0);(i1=0);(j1=0);
(k1=0);(l1=0);(m1=0);(n1=0);(o1=0);(p1=0);(q1=0);(r1=0);(s1=0);(t1=0);
(u1=0);(v1=0);(w1=0);(x1=0);(y1=0);(z1=0);(z2=0);(z3=0);(z4=0);(z5=0);
(z6=0);(z7=0);(z8=0);(z9=0);(z10=0);(z11=0);(z12=0);(z13=0);

}


void delay(unsigned int k){for(int i=0;i<=k;i++);}
void clock(){delay(50);PORTB=0;RD2=1;RD2=0;delay(10);}
void reset(){delay(50);PORTB=0;RD3=1;RD3=0;delay(10);}
void scroll(int a,b,c,d,e)
{
(a=~a);(b=~b);(c=~c);(d=~d);(e=~e);
int t;(t=0);


loop1:(a1=a);
for(int i=0;i<=10;i++)
{
PORTB=a1;clock();
PORTB=b1;clock();
PORTB=c1;clock();
PORTB=d1;clock();
PORTB=e1;clock();
PORTB=f1;clock();
PORTB=g1;clock();
PORTB=h1;clock();
PORTB=i1;clock();
PORTB=j1;clock();
PORTB=k1;clock();
PORTB=l1;clock();
PORTB=m1;clock();
PORTB=n1;clock();
PORTB=o1;clock();
PORTB=p1;clock();
PORTB=q1;clock();
PORTB=r1;clock();
PORTB=s1;clock();
PORTB=t1;clock();
PORTB=u1;clock();
PORTB=v1;clock();
PORTB=w1;clock();
PORTB=x1;clock();
PORTB=y1;clock();
PORTB=z1;clock();
PORTB=z2;clock();
PORTB=z3;clock();
PORTB=z4;clock();
PORTB=z5;clock();
PORTB=z6;clock();
PORTB=z7;clock();
PORTB=z8;clock();
PORTB=z9;clock();
PORTB=z10;clock();
PORTB=z11;clock();
PORTB=z12;clock();
PORTB=z13;reset();
}
(z13=z12);
(z12=z11);
(z11=z10);
(z10=z9);
(z9=z8);
(z8=z7);
(z7=z6);
(z6=z5);
(z5=z4);
(z4=z3);
(z3=z2);
(z2=z1);
(z1=y1);
(y1=x1);
(x1=w1);
(w1=v1);
(v1=u1);
(u1=t1);
(t1=s1);
(s1=r1);
(r1=q1);
(q1=p1);
(p1=o1);
(o1=n1);
(n1=m1);
(m1=l1);
(l1=k1);
(k1=j1);
(j1=i1);
(i1=h1);
(h1=g1);
(g1=f1);
(f1=e1);
(e1=d1);
(d1=c1);
(c1=b1);
(b1=a1);

(a=b);
(b=c);
(c=d);
(d=e);
(t=t+1);
if(t==5){(a=0);}
if(t==6){goto exit;}
goto loop1;
exit:;
}
//////FONT DATA BEGIN////////////////////////////////////////////////
void font(unsigned char c)///////////ASCII/////////////////////
{
if(c==97){scroll(0xF3, 0xAD, 0xAD, 0xAB, 0xC5);} //a
if(c==98){scroll(0x1, 0xED, 0xED, 0xED, 0xF3);}
if(c==99){scroll(0xC3, 0xBD, 0xBD, 0xBD, 0xDB);}
if(c==100){scroll(0xF3, 0xED, 0xED, 0xED, 0x1);}
if(c==101){scroll(0xC3, 0xAD, 0xAD, 0xAD, 0xCB);}
if(c==102){scroll(0xEF, 0xEF, 0x1, 0x6F, 0xAF);}
if(c==103){scroll(0xCF, 0xB5, 0xB5, 0xAD, 0xC3);}
if(c==104){scroll( 0x1, 0xEF, 0xDF, 0xDF, 0xE1);}
if(c==105){scroll(0xFF, 0xFF, 0xA1, 0xFF, 0xFF);}
if(c==106){scroll(0xFB, 0xFD, 0xFD, 0xA3, 0xFF);}
if(c==107){scroll(0x1, 0xF7, 0xE7, 0xDB, 0xFD);}
if(c==108){scroll(0xFF, 0xFF, 0x1, 0xFF, 0xFF);}
if(c==109){scroll(0xC1, 0xBF, 0xC1, 0xBF, 0xC1);}
if(c==110){scroll(0x81, 0xDF, 0xBF, 0xBF, 0xC1);}
if(c==111){scroll(0xC3, 0xBD, 0xBD, 0xBD, 0xC3);}
if(c==112){scroll(0x81, 0xD7, 0xB7, 0xB7, 0xCF);}
if(c==113){scroll(0xCF, 0xB7, 0xB7, 0xB7, 0xC1);}
if(c==114){scroll(0x81, 0xEF, 0xDF, 0xDF, 0xDF);}
if(c==115){scroll(0xDB, 0xAD, 0xAD, 0xAD, 0xB3);}
if(c==116){scroll(0xDF, 0xDF, 0x3, 0xDD, 0xDB);}
if(c==117){scroll(0x83, 0xFD, 0xFD, 0xFB, 0x81);}
if(c==118){scroll(0x87, 0xFB, 0xFD, 0xFB, 0x87);}
if(c==119){scroll(0x83, 0xFD, 0xF3, 0xFD, 0x83);}
if(c==120){scroll(0xB9, 0xD7, 0xEF, 0xD7, 0xB9);}
if(c==121){scroll(0x9B, 0xED, 0xED, 0xED, 0x83);}
if(c==122){scroll(0xDD, 0xD9, 0xD5, 0xCD, 0xDD);} //z
if(c==65){scroll(0xC1, 0xB7, 0x77, 0xB7, 0xC1);} //letter A
if(c==66){scroll(0x01, 0x6D, 0x6D, 0x6D, 0x93);}
if(c==67){scroll(0x83, 0x7D, 0x7D, 0x7D, 0xBB);}
if(c==68){scroll(0x01, 0x7D, 0x7D, 0xBB, 0xC7);}
if(c==69){scroll(0x01, 0x6D, 0x6D, 0x6D, 0x7D);}
if(c==70){scroll(0x01, 0x6F, 0x6F, 0x6F, 0x7F);}
if(c==71){scroll(0x83, 0x7D, 0x65, 0x6D, 0xA3);}
if(c==72){scroll(0x01, 0xEF, 0xEF, 0xEF, 0x01);}
if(c==73){scroll(0x7D, 0x7D, 0x1, 0x7D, 0x7D);}
if(c==74){scroll(0xF3, 0x7D, 0x7D, 0x03, 0x7F);}
if(c==75){scroll(0x01, 0xEF, 0xD7, 0xBB, 0x7D);}
if(c==76){scroll(0x01, 0xFD, 0xFD, 0xFD, 0xFD);}
if(c==77){scroll(0x01, 0xBF, 0xDF, 0xBF, 0x01);}
if(c==78){scroll(0x01, 0xBF, 0xDF, 0xEF, 0x01);}
if(c==79){scroll(0x83, 0x7D, 0x7D, 0x7D, 0x83);}
if(c==80){scroll(0x01, 0x6F, 0x6F, 0x6F, 0x9F);}
if(c==81){scroll(0x83, 0x7D, 0x75, 0x79, 0x81);}
if(c==82){scroll(0x01, 0x6F, 0x6F, 0x6F, 0x91);}
if(c==83){scroll(0x9B, 0x6D, 0x6D, 0x6D, 0xB3);}
if(c==84){scroll(0x7F, 0x7F, 0x01, 0x7F, 0x7F);}
if(c==85){scroll(0x03, 0xFD, 0xFD, 0xFD, 0x03);}
if(c==86){scroll(0x07, 0xFB, 0xFD, 0xFB, 0x07);}
if(c==87){scroll(0x01, 0xFB, 0xF7, 0xFB, 0x01);}
if(c==88){scroll(0x39, 0xD7, 0xEF, 0xD7, 0x39);}
if(c==89){scroll(0x3F, 0xDF, 0xE1, 0xDF, 0x3F);}
if(c==90){scroll(0x79, 0x75, 0x6D, 0x5D, 0x3D);} //letter Z
if(c==48){scroll(0x83, 0x7D, 0x7D, 0x7D, 0x83);} //NUM 0
if(c==49){scroll(0xDD, 0xBD, 0x1, 0xFD, 0xFD);}
if(c==50){scroll(0xBD, 0x79, 0x75, 0x6D, 0x9D);}
if(c==51){scroll(0x7B, 0x7D, 0x5D, 0x4D, 0x33);}
if(c==52){scroll(0xCF, 0xAF, 0x6F, 0xEF, 0x1);}
if(c==53){scroll(0xB, 0x5D, 0x5D, 0x5D, 0x63);}
if(c==54){scroll(0x83, 0x6D, 0x6D, 0x6D, 0xB3);}
if(c==55){scroll(0x79, 0x77, 0x6F, 0x5F, 0x3F);}
if(c==56){scroll(0x93, 0x6D, 0x6D, 0x6D, 0x93);}
if(c==57){scroll(0x9B, 0x6D, 0x6D, 0x6D, 0x83);} //NUM 9
if(c==32){scroll(0xFF, 0xFF, 0xFF, 0xFF, 0xFF);} //space
if(c==46){scroll(0xFF, 0xF9, 0xF9, 0xFF, 0xFF);} //.
if(c==58){scroll(0xFF, 0x99, 0x99, 0xFF, 0xFF);} //:
if(c==47){scroll(0xFB, 0xF7, 0xEF, 0xDF, 0xBF);} // /
if(c==92){scroll(0xBF, 0xDF, 0xEF, 0xF7, 0xFB);} // \
if(c==35){scroll(0xD7, 0x1, 0xD7, 0x1, 0xD7);} // #
if(c==40){scroll(0xC7, 0xBB, 0x7D, 0x7D, 0xFF);} // (
if(c==41){scroll(0xFF, 0x7D, 0x7D, 0xBB, 0xC7);} // )
if(c==95){scroll(0xFD, 0xFD, 0xFD, 0xFD, 0xFD);} // _
if(c==64){scroll(0x83, 0x6D, 0x55, 0x6D, 0x8B);} // @
if(c==38){scroll(0xC9, 0xB6, 0xCA, 0xFD, 0xFA);} // &
if(c==45){scroll(0xEF, 0xEF, 0xEF, 0xEF, 0xEF);} // -
if(c==36){scroll(0xDF, 0xAB, 0x1, 0xAB, 0xF7);} // $
if(c==43){scroll(0xEF, 0xEF, 0x83, 0xEF, 0xEF);} // +
if(c==37){scroll(0x3B, 0x37, 0xEF, 0xD9, 0xB9);} // %
if(c==94){scroll(0xEF, 0xDF, 0xBF, 0xDF, 0xEF);} //^
if(c==63){scroll(0xBF, 0x7F, 0x65, 0x5F, 0x9F);} // ?
if(c==59){scroll(0xFF, 0x92, 0x91, 0xFF, 0xFF);} // ;
if(c==61){scroll(0xEB, 0xEB, 0xEB, 0xEB, 0xEB);} // =
if(c==60){scroll(0xEF, 0xD7, 0xBB, 0x7D, 0xFF);} // <
if(c==62){scroll(0xFF, 0x7D, 0xBB, 0xD7, 0xEF);} // >
if(c==44){scroll(0xFF, 0xF5, 0xF3, 0xFF, 0xFF);} // ,
if(c==91){scroll(0xFF, 0x1, 0x7D, 0x7D, 0xFF);} // [
if(c==93){scroll(0xFF, 0x7D, 0x7D, 0x1, 0xFF);} // ]
if(c==126){scroll(0xEF, 0xDF, 0xEF, 0xF7, 0xEF);} // ~
if(c==33){scroll(0xFF, 0xFF, 0x5, 0xFF, 0xFF);} // !
if(c==42){scroll(0xAB, 0xC7, 0x1, 0xC7, 0xAB);} // *
//////FONT DATA END////////////////////////////////////////////////



}
int f;s
void typehere(const char *s)
{
while(*s)
font(*s++);
}

void main()
{
__delay_ms(100);
__delay_ms(200);
__delay_ms(100);
TRISB=0;
TRISD=0b01110011;
PORTD=0;
RD3=1;
RD3=0;
begin();
delay(10);
begin();

while(1)
{

typehere("-*-*-*-WELCOME TO GHATECH 2011-*-*the tech feast of Palghat-*-");

typehere(" GOVERNMENT ENGINEERING COLLEGE SREEKRISHNAPURAM, PALAKKAD ");

typehere(" ...testing display font..... abcdefghijklmnopqrstuvwxyz....ABCDEFGHIJKLMNOPQRSTUVWXYZ....0123456789....!@#$%^&*()_+-=;:?/>.<,~+\..... ..... ..... ..... .....");



}
}
:):):):):):):):):):):):):):idea::idea::idea::idea::):):):):):):):)

---------- Post added at 14:17 ---------- Previous post was at 14:13 ----------

my 'c' knowledge is limited , so that will be very much reflected in the above program(never mind), i dont mean u should use the program, its just for getting some ideas....



hello, how the schematic will be look like?
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top