void LongLatPrintf(unsigned char row,unsigned char col, signed int du, unsigned int fen,float miao) { unsigned char T[2]={0},D[4]={0},P[6]={0},Q[3]={0}; unsigned int temp=0; temp = abs(du); sprintf(D,"%d",temp);//度 if (temp < 10) { D[3] = D[0]; D[2] = ' '; D[1] = ' '; } else if (temp >= 10 && temp <100) { D[3] = D[1]; D[2] = D[0]; D[1] = ' '; } else if (temp >= 100 && temp <= 180) { D[3] = D[2]; D[2] = D[1]; D[1] = D[0]; } if (du < 0) D[0] ='-'; else D[0] =' '; D[4] = 0X00; PrintFunc(3,row,col,D);//度 SignDegree(row,col+25);//度符号 sprintf(T,"%d",fen); if (fen<10) { T[1]=T[0]; T[0]=' '; T[2]=0X00; } PrintFunc(3,row,col+28,T);//分值 SignFen(row,col+41); sprintf(P,"%f",miao); // P[6] = 0X00; if (miao<10) { T[0]=' '; T[1]=P[0]; Q[0]=P[2]; Q[1]=P[3]; Q[2]=P[4]; Q[3]=0X00; } else { T[0] = P[0]; T[1] = P[1]; Q[0] = P[3]; Q[1] = P[4]; Q[2] = P[5]; Q[3] = 0X00; } PrintFunc(3,row,col+42,T); SignFull(row,col+55); PrintFunc(3,row,col+58,Q); } It is one subroutine of my program,which function is displaying LCD .In this subroutine ,the varivble T[2],D[4],ect,is just defined when the subroutine running .But in my project , these variable occupy the RAM alltimes like static variable.How can I get it free after the subroutine finished?
This code appears wasteful in various ways. For starters, why don't you just use the flexibility the sprintf() command has, instead of rolling your own complicated scheme like that? All the shuffling of characters inside the strings could easily be avoided by using "% d" or "% f" as the format strings, from what I can see.