|
|
View previous topic :: View next topic |
Author |
Message |
BlueStar_Phil Guest
|
Why does variable in for-loop never increase? |
Posted: Thu Jul 13, 2006 1:49 pm |
|
|
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
|
|
Posted: Thu Jul 13, 2006 2:07 pm |
|
|
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
|
|
Posted: Thu Jul 13, 2006 5:16 pm |
|
|
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
|
|
Posted: Fri Jul 14, 2006 6:53 am |
|
|
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. |
|
|
|
|
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
|