View previous topic :: View next topic |
Author |
Message |
mcdnkfc
Joined: 08 Sep 2009 Posts: 4
|
Problem with array when using PIC24FJ128GA010 |
Posted: Tue Jan 12, 2010 1:38 am |
|
|
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
|
|
Posted: Tue Jan 12, 2010 1:52 am |
|
|
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
|
|
Posted: Tue Jan 12, 2010 3:03 am |
|
|
So, is there any solution others than I change my compiler?
bcos I'm stuck here.... |
|
|
Wayne_
Joined: 10 Oct 2007 Posts: 681
|
|
Posted: Tue Jan 12, 2010 3:20 am |
|
|
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
|
|
Posted: Tue Jan 12, 2010 3:36 am |
|
|
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
|
|
Posted: Tue Jan 12, 2010 6:08 pm |
|
|
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
|
|
Posted: Wed Jan 13, 2010 1:27 am |
|
|
I compiled your float example with PCD V4.087 and if works O.K.
Code: | a=0;
printf("%u\r\n"data1[a]);
.. |
|
|
|
|