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 transferring an array to a routine

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







Problem transferring an array to a routine
PostPosted: Sun Mar 14, 2004 9:31 am     Reply with quote

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?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Mar 14, 2004 3:43 pm     Reply with quote

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
}
revo
Guest







PostPosted: Sun Mar 14, 2004 4:50 pm     Reply with quote

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
Revo
Guest







PostPosted: Tue Mar 16, 2004 3:54 pm     Reply with quote

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
}
Gerrit



Joined: 15 Sep 2003
Posts: 58

View user's profile Send private message

PostPosted: Tue Mar 16, 2004 5:11 pm     Reply with quote

Revo,

Should it not be an pointer that you receive in your fuction?


void routine(char * number)//
{
printf(" %u",number[1]);
}



Gerrit
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Mar 16, 2004 5:19 pm     Reply with quote

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.
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