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 support@ccsinfo.com

display on LCD problem

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



Joined: 24 Jul 2005
Posts: 20

View user's profile Send private message

display on LCD problem
PostPosted: Fri Aug 19, 2005 10:42 pm     Reply with quote

I have some trouble when working with LCD

I want to display an unsigned char on LCD. For exam var=51;
when display it on LCD it always 50. Mean that it always display
(var-var%10).

and when I display float number, it take me a lot of memory. how to improve?
Ttelmah
Guest







PostPosted: Sat Aug 20, 2005 3:33 am     Reply with quote

An integer should display fine. What you are not saying, is how you are getting 'to' this integer. If (for instance), this is being generated from earlier arithmetic, then the odds are that what you are seeing is a rounding error earlier on in the code.
If (for instance), you do:
Code:

float val;
int8 ival;
val=57500.0;
ival=val/1127.45;
printf("%u",ival);

You may well find that 'ival', is actually 50, not 51. The problem here is that depending on how the numbers store, if the result ends up as (say) 50.9999, the default conversion will be a 'floor' conversion (taking the integer below). You can round for yourself, by adding 0.499999 to the result before converting to an integer, and there are some signs in the latest compiler, that CCS are working on this aspect of their compiler.

On the float, the libraries are 'not bad'. Floating point arithmetic, takes a _lot_ of work for a small processor like the PIC, and a lot of code size.

The best thing that can be done, is to see if your problem can instead be solved using 'fixed point' arithmetic in a scaled integer. Though the compiler has some bugs at the moment, CCS have just added support for this into the printf statement, with the %w format.

Best Wishes
noisepic



Joined: 24 Jul 2005
Posts: 20

View user's profile Send private message

PostPosted: Sun Aug 21, 2005 9:08 pm     Reply with quote

I'm sorry this post is not clearly. Because of my english...
I want to display number such as 34.5,35,35.5..mean that each step is 0.5
If I use
[code]
printf(lcd_putchar,"%3.1f",val);
[\code]

it will take alot of memory. Or we have to buil a sub routine to display it.
I haven't tried %w format.

thanks
noisepic



Joined: 24 Jul 2005
Posts: 20

View user's profile Send private message

PostPosted: Sun Aug 21, 2005 9:26 pm     Reply with quote

I'm sorry this post is not clearly. Because of my english...
I want to display number such as 34.5,35,35.5..mean that each step is 0.5
If I use
Code:

printf(lcd_putchar,"%3.1f",val);


it will take alot of memory. Or we have to buil a sub routine to display it.
I haven't tried %w format.

thanks
Ttelmah
Guest







PostPosted: Mon Aug 22, 2005 2:18 am     Reply with quote

%w, is the answer to what you want. Use a long int, and increment it by 5, then output it with %3.1w
The value will need to be a long, since for the example you give, you need to hold '345', '350' etc., which won't fit in an 8bit integer.
You can get the same effect in older compilers, using something like:
Code:

ldiv_t val;
int16 ival;
//declare these where required. You must include stdlib.h beforehand.

ival=345;
//any value you want.

val=ldiv(ival,10L);
printf("%2ld.%1ld",val.quot,val.rem);


The printf here will output '34.5' for the 'ival' given.

Best Wishes
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