CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

glcd and numbers

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
wh1sp3r



Joined: 15 Jul 2006
Posts: 22

View user's profile Send private message

glcd and numbers
PostPosted: Mon Jul 17, 2006 3:45 pm     Reply with quote

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
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Jul 17, 2006 3:49 pm     Reply with quote

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
wh1sp3r



Joined: 15 Jul 2006
Posts: 22

View user's profile Send private message

PostPosted: Mon Jul 17, 2006 4:15 pm     Reply with quote

int ahoj = 10;
char ahojky[9];

sprintf(ahojky, "%d", ahoj);
glcd_text57(28, 15, ahojky, 1, ON);



where is a problem ? please
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Jul 17, 2006 4:29 pm     Reply with quote

Did you modify any of the CCS graphics functions, such as glcd_text57() ?

Also, what is your version of the compiler ?
wh1sp3r



Joined: 15 Jul 2006
Posts: 22

View user's profile Send private message

PostPosted: Mon Jul 17, 2006 4:48 pm     Reply with quote

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
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Jul 17, 2006 5:12 pm     Reply with quote

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);
wh1sp3r



Joined: 15 Jul 2006
Posts: 22

View user's profile Send private message

PostPosted: Mon Jul 17, 2006 5:20 pm     Reply with quote

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
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Jul 17, 2006 5:26 pm     Reply with quote

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 ?
wh1sp3r



Joined: 15 Jul 2006
Posts: 22

View user's profile Send private message

PostPosted: Mon Jul 17, 2006 5:29 pm     Reply with quote

I give to first strcat() function a char itoaf, which contain number like 20 for example
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Jul 17, 2006 5:30 pm     Reply with quote

What about the other parameter, timeins[10] ?

Is it a string ?
wh1sp3r



Joined: 15 Jul 2006
Posts: 22

View user's profile Send private message

PostPosted: Mon Jul 17, 2006 5:35 pm     Reply with quote

yes, its a string, this string will be contains all time (for ex: 21:50:00)
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Jul 17, 2006 5:44 pm     Reply with quote

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] = {""};
wh1sp3r



Joined: 15 Jul 2006
Posts: 22

View user's profile Send private message

PostPosted: Mon Jul 17, 2006 5:46 pm     Reply with quote

ok, i will try
wh1sp3r



Joined: 15 Jul 2006
Posts: 22

View user's profile Send private message

PostPosted: Mon Jul 17, 2006 5:49 pm     Reply with quote

Heey, it works now Smile thank you.
Why is this happen ? becase of blank char ? you mean that it take some data from memory on some address?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Jul 17, 2006 6:08 pm     Reply with quote

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.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group