![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
Revo Guest
|
Problem transferring an array to a routine |
Posted: Sun Mar 14, 2004 9:31 am |
|
|
When I compile with PCM and PIC16f876 it work fine
But when i compile with PCH v3.168 and PIC18F252 the array is not transferred correctly
number[1] SHOULD BE 2 BUT IT IS ANOTHER VALUE
void routine(int number[5])
{
printf(lcd_putc," %u",number[1]);//<-------number[1] SHOULD BE 2 BUT IT IS ANOTHER VALUE
}
main (){
int array[5];
lcd_init();
array[1]=2;
printf(lcd_putc," %u",array[1]);
routine(array);
}
Can anyone help me? |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Mar 14, 2004 3:43 pm |
|
|
I modified your program slightly, because I don't have a LCD on
my 18F458 demo board. I compiled it with PCH vs. 3.178, and
it worked OK. It displayed this on the terminal window:
2 2
I don't have PCH vs. 3.168, so I can't test that version.
Code: | #include <18F458.h>
#device ICD=TRUE
#fuses HS, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 4000000)
#use rs232(baud = 9600, xmit=PIN_C6, rcv = PIN_C7, ERRORS)
//========================================
void routine(int number[5])
{
printf(" %u",number[1]);
}
main ()
{
int array[5];
array[1]=2;
printf(" %u",array[1]);
routine(array);
while(1); // Prevent PIC from going to Sleep
} |
|
|
![](templates/subSilver/images/spacer.gif) |
revo Guest
|
|
Posted: Sun Mar 14, 2004 4:50 pm |
|
|
I have run your code in my demo board
It displayed this on the terminal window 2 0
So I think it is a bug in the version 3.168
I will update my compiler
Thanks |
|
![](templates/subSilver/images/spacer.gif) |
Revo Guest
|
|
Posted: Tue Mar 16, 2004 3:54 pm |
|
|
I have updated my CCS
But I have the same problem. The terminal displayed 2 0
I found a solution to resolve it.
The follow code work Ok
#include <18F458.h>
#device ICD=TRUE
#fuses HS, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 4000000)
#use rs232(baud = 9600, xmit=PIN_C6, rcv = PIN_C7, ERRORS)
//========================================
void routine(int number)// <---- This is the difference before: void routine(int number[5])
{
printf(" %u",number[1]);
}
main ()
{
int array[5];
array[1]=2;
printf(" %u",array[1]);
routine(array);
while(1); // Prevent PIC from going to Sleep
} |
|
![](templates/subSilver/images/spacer.gif) |
Gerrit
Joined: 15 Sep 2003 Posts: 58
|
|
Posted: Tue Mar 16, 2004 5:11 pm |
|
|
Revo,
Should it not be an pointer that you receive in your fuction?
void routine(char * number)//
{
printf(" %u",number[1]);
}
Gerrit |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Mar 16, 2004 5:19 pm |
|
|
That is strange. I have two different demo boards.
On the one I tested with your code earlier, I get "2 2".
On my other demo board, I get "2 0", just like you did.
Something weird is going on. In each case, I am using
PCH vs. 3.178. I don't have time to research it right now,
but I will, and I'll post the reason if I can find one. |
|
![](templates/subSilver/images/spacer.gif) |
|
|
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
|