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

Why doesn't count more than 255 ??

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



Joined: 07 Jan 2006
Posts: 64
Location: Braga

View user's profile Send private message Send e-mail MSN Messenger

Why doesn't count more than 255 ??
PostPosted: Fri Jan 20, 2006 11:10 am     Reply with quote

I'm working with a 16F877 , made a counter but it don't pass over (seconds) >255 countings, it step to 0..1..2..3..4..255..0..1. Any body can help me with this ?? Thank you ALL

int seconds;

#int_rtcc
clock_isr() {
output_high(LED);
if(--int_count==0)
{
output_low(LED);
++seconds;
int_count=INTS_PER_SECOND;
}
Ttelmah
Guest







PostPosted: Fri Jan 20, 2006 11:11 am     Reply with quote

Look at what sizes variables can hold.
An _integer_, by default, is an 'int8', and can only hold 0....255.

Best Wishes
jruibarroso



Joined: 07 Jan 2006
Posts: 64
Location: Braga

View user's profile Send private message Send e-mail MSN Messenger

PostPosted: Fri Jan 20, 2006 11:59 am     Reply with quote

ok, thank you very much

but there is another problem...

i changed int seconds; to int16 seconds;

but returns an erros on this line

printf(lcd_putc,"\f %U TEMPERATURA %2U\n", seconds , temp);

do you know why ?
newguy



Joined: 24 Jun 2004
Posts: 1903

View user's profile Send private message

PostPosted: Fri Jan 20, 2006 12:18 pm     Reply with quote

Since 'seconds' is now a long integer (int16), you must use '%lu' not '%u' in your printf statement.

I recommend that you take some time to peruse the manual and/or online help.
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Fri Jan 20, 2006 12:22 pm     Reply with quote

Quote:

i changed int seconds; to int16 seconds;


Ok, then you used %U within the string to indicate an unsigned 8 bit variable.
If you defined int16 seconds, printf expect %lu.

Read the CCS Compiler Manual, it will show you the diferent formats for the built-in function printf().


Humberto
jruibarroso



Joined: 07 Jan 2006
Posts: 64
Location: Braga

View user's profile Send private message Send e-mail MSN Messenger

PostPosted: Fri Jan 20, 2006 12:43 pm     Reply with quote

THANK you !! Very Happy
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