View previous topic :: View next topic |
Author |
Message |
wh1sp3r
Joined: 15 Jul 2006 Posts: 22
|
glcd and numbers |
Posted: Mon Jul 17, 2006 3:45 pm |
|
|
Hi, please, how to display a numbers on a glcd ? I tried Itoa(), but it show me milione numbers :D which i dont want ![Smile](images/smiles/icon_smile.gif) |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Jul 17, 2006 3:49 pm |
|
|
Look in the CCS example file, EX_GLCD.C. It shows how to do it.
The file is in this folder:
c:\Program Files\PICC\Examples |
|
![](templates/subSilver/images/spacer.gif) |
wh1sp3r
Joined: 15 Jul 2006 Posts: 22
|
|
Posted: Mon Jul 17, 2006 4:15 pm |
|
|
int ahoj = 10;
char ahojky[9];
sprintf(ahojky, "%d", ahoj);
glcd_text57(28, 15, ahojky, 1, ON);
where is a problem ? please |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Jul 17, 2006 4:29 pm |
|
|
Did you modify any of the CCS graphics functions, such as glcd_text57() ?
Also, what is your version of the compiler ? |
|
![](templates/subSilver/images/spacer.gif) |
wh1sp3r
Joined: 15 Jul 2006 Posts: 22
|
|
Posted: Mon Jul 17, 2006 4:48 pm |
|
|
Nothing is modified. Compiler version is 3.249
Iam using 18F442 @ 20 Mhz.
definition:
Code: | int seconds, minutes, hours;
char timeins[10];
int timestr;
char itoaf[10];
char colon[] = ":";
char point[] = "."; |
Code: | void showtime(int x, int y)
{
timestr = gettime_hours();
sprintf(itoaf, "%d", timestr);
strcat(timeins, itoaf);
strcat(timeins, colon);
timestr = gettime_minutes();
sprintf(itoaf, "%d", timestr);
strcat(timeins, itoaf);
strcat(timeins, colon);
timestr = gettime_seconds();
sprintf(itoaf, "%d", timestr);
strcat(timeins, itoaf);
glcd_text57(x, y, timeins, 1, ON);
} |
gettime return only int number.
It seems that this numbers are random, sometimes is all fine, sometimes this numbers are showing ... why ? maybe some delay for lcd ? everything work fine, but numbers no |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Jul 17, 2006 5:12 pm |
|
|
You are using the strcat() function on the timeins[10] array.
What does the strcat() function expect as parameters ?
Something is wrong with one of the parameters that you have
given to your first usage of strcat(). What is it ?
Quote: | int seconds, minutes, hours;
char timeins[10];
int timestr;
char itoaf[10];
char colon[] = ":";
char point[] = ".";
void showtime(int x, int y)
{
timestr = gettime_hours();
sprintf(itoaf, "%d", timestr);
strcat(timeins, itoaf);
strcat(timeins, colon);
timestr = gettime_minutes();
sprintf(itoaf, "%d", timestr);
strcat(timeins, itoaf);
strcat(timeins, colon);
timestr = gettime_seconds();
sprintf(itoaf, "%d", timestr);
strcat(timeins, itoaf);
glcd_text57(x, y, timeins, 1, ON);
|
|
|
![](templates/subSilver/images/spacer.gif) |
wh1sp3r
Joined: 15 Jul 2006 Posts: 22
|
|
Posted: Mon Jul 17, 2006 5:20 pm |
|
|
timeins is for saving time format "XX:XX:XX"
first, i get for number
this number convert to string and add to timeins
next, i add a colon char ":" ... etc |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Jul 17, 2006 5:26 pm |
|
|
I don't really want information. I want you to look closely at your
parameters. I want you to think about the problem.
What is the definition of a string ?
What are you giving to the first strcat() function ? |
|
![](templates/subSilver/images/spacer.gif) |
wh1sp3r
Joined: 15 Jul 2006 Posts: 22
|
|
Posted: Mon Jul 17, 2006 5:29 pm |
|
|
I give to first strcat() function a char itoaf, which contain number like 20 for example |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Jul 17, 2006 5:30 pm |
|
|
What about the other parameter, timeins[10] ?
Is it a string ? |
|
![](templates/subSilver/images/spacer.gif) |
wh1sp3r
Joined: 15 Jul 2006 Posts: 22
|
|
Posted: Mon Jul 17, 2006 5:35 pm |
|
|
yes, its a string, this string will be contains all time (for ex: 21:50:00) |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Jul 17, 2006 5:44 pm |
|
|
OK, I'm going to quit the coaching mode.
It's not a string until you make it a string. In your code, it's just
an un-initialized array. You have to initialize it to be a zero-length
string. You can do this by setting the first byte to 0, or by using
the following method:
char timeins[10] = {""}; |
|
![](templates/subSilver/images/spacer.gif) |
wh1sp3r
Joined: 15 Jul 2006 Posts: 22
|
|
Posted: Mon Jul 17, 2006 5:46 pm |
|
|
ok, i will try |
|
![](templates/subSilver/images/spacer.gif) |
wh1sp3r
Joined: 15 Jul 2006 Posts: 22
|
|
Posted: Mon Jul 17, 2006 5:49 pm |
|
|
Heey, it works now thank you.
Why is this happen ? becase of blank char ? you mean that it take some data from memory on some address? |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Jul 17, 2006 6:08 pm |
|
|
A string is an array of characters with a final byte of 0.
If you just declare an array, it's not set to anything.
It can have garbage in it. If you want to use the array
as a string, then you must initialized it as a string.
In the example I gave, it's set to a zero length string.
The compiler sets the first byte to 0, to indicate this. |
|
![](templates/subSilver/images/spacer.gif) |
|