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

Problem with array when using PIC24FJ128GA010

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



Joined: 08 Sep 2009
Posts: 4

View user's profile Send private message

Problem with array when using PIC24FJ128GA010
PostPosted: Tue Jan 12, 2010 1:38 am     Reply with quote

Hi all, I'm using PIC24FJ128GA010, and compiler ver4.088.

Here is the problems:
Code:

#include <24fj128GA010.h>
#fuses HS,PR_PLL    // Crystal HS, 4xPLL
#fuses NOIESO       // No 2-speed Start Up
#fuses NOJTAG       // No JTAG
#fuses NOPROTECT    // No Memory Protection
#fuses NOWDT        // No WatchDog Timer
#fuses NODEBUG      // Debug Mode.

#use delay(clock=32M, oscillator=8M)
#use rs232(UART2, STREAM=serial_debug, baud=9600, bits=8)

/********Global Variable*************/
float data1[2]={10,20};

/*********Main Program***************/
void main()
{   
   unsigned char a;

   a = 0;
   printf("%0.0f\r\n"data1[a]);
   delay_ms(100);   
   
   a = 1;
   printf("%0.0f\r\n"data1[a]);
   delay_ms(100);      
}

>>It prints out:
>>0
>>0

But, if this, it is ok:
Code:

/***********Global Variable*************/
float data1[2]={10,20};

/**************Main Program**********/
void main()
{   
   printf("%0.0f\r\n"data1[0]);
   delay_ms(100);   
   
   printf("%0.0f\r\n"data1[1]);
   delay_ms(100);      
}

>>and print out
>>10
>>20

I also try out this and it's work:
Code:

/***********Global Variable****************/
char data1[2]={10,20};

/**************Main Program**************/
void main()
{   
   unsigned char a;
   a=0;
   printf("%u\r\n"data1[a]);
   delay_ms(100);   
   
   a=1;
   printf("%u\r\n"data1[a]);
   delay_ms(100);      
}

So, is there any problems with the variable 'a' when it locating the floating point array?
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Tue Jan 12, 2010 1:52 am     Reply with quote

V4.088 has considerably more PCD bugs then recent versions. 32 bit operations are one favourite place for it.
mcdnkfc



Joined: 08 Sep 2009
Posts: 4

View user's profile Send private message

PostPosted: Tue Jan 12, 2010 3:03 am     Reply with quote

So, is there any solution others than I change my compiler?
bcos I'm stuck here.... Crying or Very sad
Wayne_



Joined: 10 Oct 2007
Posts: 681

View user's profile Send private message

PostPosted: Tue Jan 12, 2010 3:20 am     Reply with quote

Just a note,
there should be a comma between the format string and the data e.g.

printf("%0.0f\r\n", data1[a]);

Also try

Code:

a = 0;
float f;

f = data1[a];
   printf("%0.0f\r\n", f);
 
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Tue Jan 12, 2010 3:36 am     Reply with quote

I was able to fix previous PCD bugs with 32-bit data and pointers by cutting complex expressions to more simple ones, like Wayne suggested.
mcdnkfc



Joined: 08 Sep 2009
Posts: 4

View user's profile Send private message

PostPosted: Tue Jan 12, 2010 6:08 pm     Reply with quote

I tried but still the same problem.
I already gave up v4.088 and changed to C30.
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Wed Jan 13, 2010 1:27 am     Reply with quote

I compiled your float example with PCD V4.087 and if works O.K.
Code:
   a=0;
   printf("%u\r\n"data1[a]);
  ..
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