system
October 17, 2010, 2:45am
1
I have an LCD display using the ST7920 controller and I am using the dfrobot serial library available here --> http://www.dfrobot.com/image/data/FIT0021/LCD12864RSPI.rar
I'm simply trying to write a number on to the LCD screen but having a little trouble as the function to write text to the screen requires unsigned char.
I can use the following to convert a number to a string.
char millis_char[16];
** unsigned long millis_ulong = millis();**
** sprintf(millis_char,"%d",millis_ulong);**
but I don't know how to convert the string to unsigned char.
this is to use in the LCDA.DisplayString function
any ideas?
system
October 17, 2010, 7:50am
2
Char and unsigned char convert themselves from one to the other, so no trouble there.
To access a single digit in your array, you just index it. For example to pass digit 3 (the numbering starts as 0) to a magic_display_function is:
magic_display_function (millis_char[3]);
Korman
system
October 17, 2010, 6:16pm
3
char to unsigned char?
You can tell the compiler to treat the array as unsigned char. (Use a cast)
char millis_char[16];
unsigned long millis_ulong = millis();
sprintf(millis_char,"%lu", millis_ulong); // Works OK: sprintf uses char arrays.
LCDA.DisplayString(0, 0, (unsigned char *)millis_char, 16);// The LCDA function requires unsigned char arrays.
Regards,
Dave
Footnote:
Not related to your question, but Something That It Is Good To Know:
Note that the format specifier "%d
" is used for ints.
For long ints use "%ld
"
For unsigned long ints use "%lu
"
system
October 18, 2010, 5:00am
4
Thanks davekw7x. Exactly the info I was looking for.