View previous topic :: View next topic |
Author |
Message |
buckeyes1997 Guest
|
why does my count roll over at 255 every time |
Posted: Thu Nov 25, 2004 8:14 am |
|
|
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: 1934 Location: Norman, OK
|
Int is 8 bits |
Posted: Thu Nov 25, 2004 8:42 am |
|
|
THe default int here is 8 bits. You have to specify int16. |
|
|
Sherpa Doug Guest
|
Re: Int is 8 bits |
Posted: Thu Nov 25, 2004 9:01 am |
|
|
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 |
Posted: Fri Nov 26, 2004 1:58 pm |
|
|
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
|
|
Posted: Fri Nov 26, 2004 3:16 pm |
|
|
Your problem is the printf statement:
printf(lcd_putc, "value=%u", i);
Change it to:
printf(lcd_putc, "value=%lu", i) |
|
|
|