Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
05/05/04 22:57
Read: times


 
#69912 - RE: Convert int to a string
Responding to: ???'s previous message
Hi All, I've been following this one with interest, as I have to run a 4 line by 20 character display. I have the write character function down pretty efficiently and am working on method of getting a floating point value to an ascii representation. I never cared for using stdio functions, and now I remember why. I'm taking a floating point value to the display like; value=123.456, displayputs out 123.4 (don't need last two digits). I made two functions that perform the same task and included them below. The first one seems better in all way except for ease of implementation(I managed somehow) and put some comments about execution time and code size, and I'd welcome any comments, associated links, insults, or suggestions for improvement any of you gentlemen have to offer (be nice to get the 104uC time down a bit. I measured the timing by writing a bit hi before the function call, and writing it low after and measuring it with a scope.

Andy Curda


void make_screen_1(void)
{
//this function adds 640 bytes of code
//takes 104uC regardless of current value
unsigned char temper,decer;
memset(&display,'',sizeof(display));

display[0]='I';
display[1]='(';
display[2]='A';
display[3]=')';
display[4]='=';

temper=(unsigned char)current;
decer=((unsigned int)(current*10)%10);
display[7]=((unsigned char)(temper%10))+48;
temper=temper /10;
display[6]=((unsigned char)(temper%10))+48;
if (display[6]=='0') display[6]=' ';
temper=temper /10;
display[5]=((unsigned char)(temper%10))+48;
if (display[5]=='0') display[5]=' ';
display[8]='.';
display[9]=decer+48;
display[10]=0;

}

void make_screen_1(void)
{ //using sprintf adds approx 2500 bytes of code
//takes approx 200uS to execute with current=123.456
//takes approx 160uS to execute with current=3.456
sprintf(display,"I(A)=%4.1f",current);

}


List of 12 messages in thread
TopicAuthorDate
Convert int to a string            01/01/70 00:00      
   RE: Convert int to a string            01/01/70 00:00      
   RE: float to ascii            01/01/70 00:00      
   RE: Convert int to a string            01/01/70 00:00      
   RE: Convert int to a string            01/01/70 00:00      
   RE: Convert int to a string            01/01/70 00:00      
      RE: Convert int to a string            01/01/70 00:00      
   Back to basics            01/01/70 00:00      
   RE: Convert int to a string            01/01/70 00:00      
      RE: Convert int to a string            01/01/70 00:00      
         RE: Convert int to a string            01/01/70 00:00      
   RE: Convert int to a string            01/01/70 00:00      

Back to Subject List