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 does my count roll over at 255 every time

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







why does my count roll over at 255 every time
PostPosted: Thu Nov 25, 2004 8:14 am     Reply with quote

i was trying to increment an int in a loop with a delay and the loop says when i<10000 count, but it only ever gets to 255 and then flips back to zero. how can i get a continuous count on my 16f84 via software loops?? next ill be trying to do it with timer0 so any info about that would also be appreciated.

thanks
matt
dyeatman



Joined: 06 Sep 2003
Posts: 1931
Location: Norman, OK

View user's profile Send private message

Int is 8 bits
PostPosted: Thu Nov 25, 2004 8:42 am     Reply with quote

THe default int here is 8 bits. You have to specify int16.
Sherpa Doug
Guest







Re: Int is 8 bits
PostPosted: Thu Nov 25, 2004 9:01 am     Reply with quote

dyeatman wrote:
THe default int here is 8 bits. You have to specify int16.


Note that this follows the original K&R definition of a C integer, that it should be the natural data width of the processor. It is only ANSI C where they arbitrarily forced it to be 16 bits.
buckeyes1997
Guest







hmm
PostPosted: Fri Nov 26, 2004 1:58 pm     Reply with quote

well i did try using int32 and it didnt make a difference....after 255 she rolls over. is there something better about int16 that int32 doesnt do?

i just tried a loop like

loop:
for(i=0; i<2000; i++)
{
printf(lcd_putc, "value=%u", i)
}
goto loop

how would i setup the system to count up to a really large number without rolling over??

thanks
Haplo



Joined: 06 Sep 2003
Posts: 659
Location: Sydney, Australia

View user's profile Send private message

PostPosted: Fri Nov 26, 2004 3:16 pm     Reply with quote

Your problem is the printf statement:

printf(lcd_putc, "value=%u", i);

Change it to:

printf(lcd_putc, "value=%lu", i)
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