How to transfer variables between main.c and Event.c

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to transfer variables between main.c and Event.c

Jump to solution
671 Views
aaronlee
Contributor V

Hi,

We are using S12ZVCA with processor expert. How to transfer variables between main.c and Event.c?

main.c as follow:

unsigned int i;

void main(void)
{

   .........

   for(;;)
   {
      SCI_Send(i);
   }
   .........

........
/*
** ###################################################################
**
** This file was created by Processor Expert 10.3 [05.09]
** for the Freescale HCS12Z series of microcontrollers.
**
** ###################################################################
*/

Event.c as follow:

unsigned int i;

void TI1_OnInterrupt(void)
{
   ++i;                                       // How to transfer i to main.c
}

Best regards,

Aaron

Labels (1)
Tags (1)
0 Kudos
1 Solution
500 Views
dianabatrlova
NXP TechSupport
NXP TechSupport

Hi Aaron,

Create a global variable in your own source file can be the solution as you can see on the below link: 

https://community.nxp.com/message/24869?commentID=24869#comment-24869 

There is a description with different Code Warrior and MCU, but the principle is the same.

I hope it helps you.

Best regards,

Diana

View solution in original post

0 Kudos
2 Replies
501 Views
dianabatrlova
NXP TechSupport
NXP TechSupport

Hi Aaron,

Create a global variable in your own source file can be the solution as you can see on the below link: 

https://community.nxp.com/message/24869?commentID=24869#comment-24869 

There is a description with different Code Warrior and MCU, but the principle is the same.

I hope it helps you.

Best regards,

Diana

0 Kudos
500 Views
aaronlee
Contributor V

Hi Diana,

Thanks for you quick reply. We got the link error as follow:

pastedImage_1.png

myfunc.c

#include "myfunc.h"

unsigned char TI1_CountUp;

unsigned char foo(void)
{
   return TI1_CountUp;
}

myfunc.h

#ifndef MYFUNC_H_
#define MYFUNC_H_

extern unsigned char TI1_CountUp;

unsigned char foo(void);

#endif /* MYFUNC_H_ */

Event.c

#include "Cpu.h"
#include "Events.h"

/* User includes (#include below this line is not maintained by Processor Expert) */
#include "Board_B0005_v100.h"
#include "myfunc.h"

............

void TI1_OnInterrupt(void)
{
   /* Write your code here ... */
   ++TI1_CountUp;
}

............

main.c

/* Including needed modules to compile this module/procedure */
#include "Cpu.h"
#include "Events.h"

.........

/* User includes (#include below this line is not maintained by Processor Expert) */
#include "myfunc.h"

.........

void main(void)
{

   ........

   /* Write your code here */

   for(;;)

   {

      do{} while(!AS1_GetTxComplete());

      AS1_SendChar(TI1_CountUp);

   }

}

How to resolve the issue:

ERROR L1822: Symbol __copy in file C:/....../FLASH/Sources\main_c.obj is undefined

Best regards,

Aaron

0 Kudos