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 CCS Technical Support

function Variable Passing Between Multiple C files [Solved]

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



Joined: 10 Aug 2009
Posts: 9

View user's profile Send private message

function Variable Passing Between Multiple C files [Solved]
PostPosted: Sat Feb 20, 2010 4:43 pm     Reply with quote

Hi,
I am building an obstacle avoiding robot. I have tested various functionality of the peripherals. However I am having a tough time to pass an array to the main function. I get weird values in the main. However it is getting printed correctly in the Relevant function. Please find my code below. Please provide me with your feedback about pointer/array passing across these two files.
Thank You

Vivek

main.c
Code:

#include <Robot.h>

#include "C:\My PICC Programs\Robot\IR.h"
#include "C:\My PICC Programs\Robot\ObstacleAvoidance.h"
#include "C:\My PICC Programs\Robot\GlobalVariables.h"
#include <string.h>

extern unsigned char IRfar;
extern unsigned char IRnear;
extern unsigned char IRmid;
extern unsigned long *IRSendNear;
extern unsigned long *IRSendMid;
extern unsigned long *IRSendFar;
unsigned long *IRSendNearReceive;
unsigned long *IRSendMidReceive;
unsigned long *IRSendFarReceive;


void main(void)
{

IR_Setup();
 
while(1)
  {
   Monitor(&IRSendNearReceive,&IRSendMidReceive,&IRSendFarReceive);

   printf("\n\rMain Near :%c , Mid :%c , Far : %c",IRSendNearReceive[0],IRSendMidReceive[0], IRSendFarReceive[0]);
   printf("\n\rMain Near :%Lu , Mid :%Lu , Far : %Lu",IRSendNearReceive[1],IRSendMidReceive[1], IRSendFarReceive[1]);
  }

}


Obstacle Avoidance.c
Code:
   
#include "Robot.h"
#include "IR.h"
#include "GlobalVariables.h"

unsigned long IR_Sensor_A;
unsigned long IR_Sensor_B;
unsigned long IR_Sensor_C;
unsigned char IRfar;
unsigned char IRnear;
unsigned char IRmid;

unsigned long *IRSendNear;
unsigned long *IRSendMid;
unsigned long *IRSendFar;


void Monitor( unsigned long *IRSendNear,unsigned long *IRSendMid, unsigned long *IRSendFar)
{
IR_Sensor_A=IR_Read(IR_A);    //Reads a long value from the sensor function .Working Fine.
IR_Sensor_B=IR_Read(IR_B);    //Reads a long value from the sensor function .Working Fine.
IR_Sensor_C=IR_Read(IR_C);    //Reads a long value from the sensor function .Working Fine.
 
IRSendNear=near(IR_Sensor_A , IR_Sensor_B , IR_Sensor_C);  // This function returns an array[2]
IRSendMid=mid(IR_Sensor_A , IR_Sensor_B , IR_Sensor_C);// This function returns an array[2]
IRSendFar=far(IR_Sensor_A ,IR_Sensor_B , IR_Sensor_C);// This function returns an array[2]

printf("\n\rNear :%c , Mid :%c , Far : %c",IRSendNear[0],IRSendMid[0], IRSendFar[0]);
printf("\n\rNear :%Lu , Mid :%Lu , Far : %Lu",IRSendNear[1],IRSendMid[1], IRSendFar[1]);

}


The output:
Quote:

Near :C , Mid :B , Far : A // This is the expected result . It comes from Obstacle Avoidance.c
Near :267 , Mid :150 , Far : 4 // This is the expected result . It comes from Obstacle Avoidance.c
Main Near : , Mid :– , Far : // This is the unexpected result . It comes from main.c
Main Near :6346 , Mid :267 , Far : 6374 // This is the unexpected result . It comes from main.c
sonu2die4



Joined: 10 Aug 2009
Posts: 9

View user's profile Send private message

Solved!!!
PostPosted: Sat Feb 20, 2010 10:08 pm     Reply with quote

I am supposed to do Pointer to Pointer ........ Surprised
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