Me being the simple minded person I am. There must be a simple/easy way to convert an integer into ASCII to be sent to a LCD. Would you share this knowledge with yours truly.
admin's test signature
if you send 1 (int) to the LCD, simply add 48 an you get a 1
INT HEX SIGN
48 30 0
49 31 1
50 32 2
Is it that what you want ?
I appreciate the response but..
In a C program I need to convert integers like 1234 to ASCII, ready to be sent to an LCD. On a PC it is done like this.
printf("The number is %d\n", i);
How is it done using an STK500 with a 8515?
If I understand your question correctly, its a simple matter of using the sprintf() standard I/O library function. Change your code sample to:
#include // This was probably already in your program
char LCDBuffer; // The number is the maximum possible length of the output string
i = 1234;
sprintf(LCDBuffer,"The number is %d\n", i);
/* The text string is now in LCDBuffer, ready to send to the LCD with whatever routine
you have for that purpose */
Note that the above assumes regular ANSI C. GIven the harvard architecture of the AVR, your compiler may require some type casting or use an alternate form of the library function in order to deal with the fact that one of the strings passed will be in RAM, and the other in FLASH.
sprintf() is very useful but also quite large. If you have no other requirement for the sprintf() library function you might consider a function along the lines of 'f()' in the sampe below.
Replace the call to 'putchar()' with what ever function you use to emit a character at the current cursor position on your LCD. Also move the cursor backwards after each character is printed. putchar('\b') may work here.
void f(int n)
int minus = (n < 0);
if (minus) n = 0 - n;
int r = n % 10;
r += '0';
n /= 10;
if (minus) putchar('-');
© 2019 Microchip Technology Inc.