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

Why does variable in for-loop never increase?

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







Why does variable in for-loop never increase?
PostPosted: Thu Jul 13, 2006 1:49 pm     Reply with quote

I just update my PCWH from V3.345 to V3.249 and copied PCH.crg file from CCS Inc to folder C:\program Files\PICC, but many things became abnormally. One of them is as below.

Either in dubugg mode and running mode, for(i=0; i<6; i++) doesn't work any more. i was kept value '0x0', nevr increase, and the program could not jump out. I am using MPLAB v7.40 under WInXP.

---------------Code is as below---------------

void mpu_get_mdr_sn(void)
{
int8 myreg, i, j;
int32 time_over;

clear_mdr_sn();
for(i=0; i<6; i++)
{
mdr_sn_arrived_flag[i]=0;
MPU_Ask_MDR_SN[2]=0x77+i;

can_putd(CAN_MPU_ID, MPU_Ask_MDR_SN, 8, 0, TRUE, FALSE);

time_over=0;
while((mdr_sn_arrived_flag[i]==0)&&(++time_over<(0x7fff)));
mdr_sn_arrived_flag[i]=0;
}
}

---------------End of Code---------------

Can anyone tell what wrong is? Many thanks in advance.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jul 13, 2006 2:07 pm     Reply with quote

You didn't show the declarations for your arrays. One easy way
for 'i' to be reset to 0, would be if you are writing beyond the end
of an array, and accidently writing 0 to the address where 'i' is
allocated.

Post a very short, but complete test program. (short, less than 50 lines).
Guest








PostPosted: Thu Jul 13, 2006 5:16 pm     Reply with quote

PCM, thank you so much for your reply. I remove PCWH V3.249 and installed PCWH V3.236, then this problem seems solved.
sjbaxter



Joined: 26 Jan 2006
Posts: 141
Location: Cheshire, UK

View user's profile Send private message Visit poster's website

PostPosted: Fri Jul 14, 2006 6:53 am     Reply with quote

One thing to check for when getting odd results in code that appears simple is to check the .SYM file and make sure that the variable that is behaving oddly has not been corrupted by another variable being allocated over the same memory location.

There is a bug in the compiler from 3.242 which maps structures incorrectly. 3.236 doesn't have this bug and is the one I would recommend when using the CCS CAN driver which rely on the use of structures.
_________________
Regards,
Simon.
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