skmdmasud Member Jun 26, 2013 #1 Hi. I am trying to display 4 different int variables in my lcd using just single display command to save program memory. The lcd library that i am using accepts the following to display int LCDWriteIntXY(X,Y,VALUE,UNIT); LCDWriteIntXY(2,0,a,4); or LCDWriteStringXY(0,1,"My Values"); I have four different int variable e.g. a,b,c and d. a=1; b=2; c=999; d=999; I want to display this as following | 1-2-999-999 | How do i make it into a single char or string and display it. Regards.
Hi. I am trying to display 4 different int variables in my lcd using just single display command to save program memory. The lcd library that i am using accepts the following to display int LCDWriteIntXY(X,Y,VALUE,UNIT); LCDWriteIntXY(2,0,a,4); or LCDWriteStringXY(0,1,"My Values"); I have four different int variable e.g. a,b,c and d. a=1; b=2; c=999; d=999; I want to display this as following | 1-2-999-999 | How do i make it into a single char or string and display it. Regards.
Ian Rogers User Extraordinaire Forum Supporter Most Helpful Member Jun 26, 2013 #2 Use the sprintf() function. Code: sprintf( LCDBUFFER,"| %d-$d-%d_%d |", a,b,c,d); LCDWriteStringXY(0,1,LCDBUFFER); If this takes too much memory... write your own.
Use the sprintf() function. Code: sprintf( LCDBUFFER,"| %d-$d-%d_%d |", a,b,c,d); LCDWriteStringXY(0,1,LCDBUFFER); If this takes too much memory... write your own.
skmdmasud Member Jun 26, 2013 #3 Hi Ian thanks for the code. For my implementation sprintf takes out more memory in .elf when i compile in Atmelstudio 6. I think i will use the LCD library command. Thanks for your help.
Hi Ian thanks for the code. For my implementation sprintf takes out more memory in .elf when i compile in Atmelstudio 6. I think i will use the LCD library command. Thanks for your help.
Ian Rogers User Extraordinaire Forum Supporter Most Helpful Member Jun 26, 2013 #4 I write my own routines for ASCII conversion C: void printFloat(char * flt, long number, char digits) { if(number < 0) { number = ABS(number); } if(digits == 2) { flt[0] = number / 1000 + 48; if(flt[0] == 48) flt[0] = 0x20; flt[1] = ((number % 1000) / 100)+ 48; flt[2] = 46; flt[3] = ((number % 100) / 10)+ 48; flt[4] = (number % 10) + 48; flt[5] = 0; } else { flt[0] = number / 100 + 48; if(flt[0] == 48) flt[0] = 0x20; flt[1] = ((number % 100) / 10)+ 48; flt[2] = 46; flt[3] = (number % 10) + 48; flt[4] = 0; } } You could tune this to do what you need it to do...
I write my own routines for ASCII conversion C: void printFloat(char * flt, long number, char digits) { if(number < 0) { number = ABS(number); } if(digits == 2) { flt[0] = number / 1000 + 48; if(flt[0] == 48) flt[0] = 0x20; flt[1] = ((number % 1000) / 100)+ 48; flt[2] = 46; flt[3] = ((number % 100) / 10)+ 48; flt[4] = (number % 10) + 48; flt[5] = 0; } else { flt[0] = number / 100 + 48; if(flt[0] == 48) flt[0] = 0x20; flt[1] = ((number % 100) / 10)+ 48; flt[2] = 46; flt[3] = (number % 10) + 48; flt[4] = 0; } } You could tune this to do what you need it to do...