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

trouble: for() iteration using INT32 variables

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



Joined: 08 Jun 2006
Posts: 14

View user's profile Send private message

trouble: for() iteration using INT32 variables
PostPosted: Wed Jan 02, 2008 7:11 am     Reply with quote

I`m working with a pic 16f88 on a CCS 4.023 and I have trouble when I use "for()" iteration with int32 variable but it works right if I do it with a "while()" iteration.
The piece of code that doesn`t work is:

#include <C:\Archivos de programa\CCS4\Devices\16F88.h>
#device ADC=10
#fuses NOWDT,INTRC_IO, PUT, NOBROWNOUT, NOLVP, NOWRT, NOPROTECT, MCLR
...
int32 aux_d;
int8 aux_dato;
...
for(aux_d=0x00000000; aux_d <= 0x0003ffff; dir++){
aux_dato = read_ext_eeprom(aux_d);
printf("%lx -- %x\n\r",aux_d,aux_dato);
if(aux_dato != 0xff){
aux_d = 0xffffffff;
dir = aux_d + 1;
printf("%lx -- %x\n\r",aux_d,aux_dato);
}
}
...
...
It run indefinitely, the statments printf arenĀ“t necessary but they help me to debug the program. printf shows to me that for() doesn't break out.

In the other hand, the next piece of code runs right:

#include <C:\Archivos de programa\CCS4\Devices\16F88.h>
#device ADC=10
#fuses NOWDT,INTRC_IO, PUT, NOBROWNOUT, NOLVP, NOWRT, NOPROTECT, MCLR
...
int32 aux_d;
int8 aux_dato;
...
aux_d=0x0003ffff;
aux_dato = read_ext_eeprom(aux_d);
printf("%lx -- %x\n\r",aux_d,aux_dato);
while((0xff == aux_dato) & (aux_d != 0)){
aux_d--;
aux_dato = read_ext_eeprom(aux_d);
printf("%lx -- %x\n\r",aux_d,aux_dato);
}
dir = aux_d + 1;
...
using while() iteration, it works ok.

What is happening? May be a Compiler bug?
Thank you to everybody.
Wayne_



Joined: 10 Oct 2007
Posts: 681

View user's profile Send private message

PostPosted: Wed Jan 02, 2008 8:02 am     Reply with quote

The condition for leaving the for loop will never be met because you are NOT incrementing aux_d.

no idea why you are incrementing dir or why it is there!
in the while loop you are actually going backwards through the addresses, why are you not doing the same in the for loop ?
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