Global variables and global functions in Codewarrior 5.1

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

Global variables and global functions in Codewarrior 5.1

ソリューションへジャンプ
2,939件の閲覧回数
Simone_Italy
Contributor I
Hi,
 
I'm using Codewarrior 5.1 (special edition) to develop a simple application on MC68HC908JK1CDW (I use C language). Please can you suggest where inserting global variables and global functions whose scope is main.c (the .c file containing the main function), event.c (I need to share variables between main() function and event functions) and all the other files I need?
Thank you in advance for your help.
Bye.
 
Simone
ラベル(1)
タグ(1)
1 解決策
1,298件の閲覧回数
CrasyCat
Specialist III
Hello
 
I assume you are using ProcessorExpert to generate code. Am I right?
 
I would recommend you to keep your source files separated from Processor Expert generated ones. You can do that the following way:
  - Create a new source file where you implement your function and define the necessary global
     variables / constants.
     For example you have a file called myfunc.c containing the following:
Code:
     unsigned char myCount;     unsigned char foo(void) {       /*Some code here*/       return myCount;     }

  - Add the file to the project (selecting Project -> "Add <...> to Project". 
  - Create a header file containing declaration for the global variables/constants you need and
     prototype for the function. For the above source file the include file will be called myfunc.h and will
     look as follow:
Code:
extern unsigned char myCount;unsigned char foo(void);
  - In the source file containing the implementation of the main function as well as in the Events.c file add an
    include from the new header file (myfunc.h in our example).
Code:
#include "Cpu.h"#include "Events.h"#include "myfunc.h"<...>

Then in main or in the Events module you can just use the  function or variable the usual way.
in the main function make sure you write your code between the marks:

  /* Write your code here */
  /* For example: for(;:smileywink: { } */
and
  /*** Don't write any code pass this line, or it will be deleted during code generation. ***/
  /*** Processor Expert end of main routine. DON'T MODIFY THIS CODE!!! ***/

That should do it and keep some kind of structure in the application.
I hope this helps.

CrasyCat

元の投稿で解決策を見る

2 返答(返信)
1,299件の閲覧回数
CrasyCat
Specialist III
Hello
 
I assume you are using ProcessorExpert to generate code. Am I right?
 
I would recommend you to keep your source files separated from Processor Expert generated ones. You can do that the following way:
  - Create a new source file where you implement your function and define the necessary global
     variables / constants.
     For example you have a file called myfunc.c containing the following:
Code:
     unsigned char myCount;     unsigned char foo(void) {       /*Some code here*/       return myCount;     }

  - Add the file to the project (selecting Project -> "Add <...> to Project". 
  - Create a header file containing declaration for the global variables/constants you need and
     prototype for the function. For the above source file the include file will be called myfunc.h and will
     look as follow:
Code:
extern unsigned char myCount;unsigned char foo(void);
  - In the source file containing the implementation of the main function as well as in the Events.c file add an
    include from the new header file (myfunc.h in our example).
Code:
#include "Cpu.h"#include "Events.h"#include "myfunc.h"<...>

Then in main or in the Events module you can just use the  function or variable the usual way.
in the main function make sure you write your code between the marks:

  /* Write your code here */
  /* For example: for(;:smileywink: { } */
and
  /*** Don't write any code pass this line, or it will be deleted during code generation. ***/
  /*** Processor Expert end of main routine. DON'T MODIFY THIS CODE!!! ***/

That should do it and keep some kind of structure in the application.
I hope this helps.

CrasyCat
1,298件の閲覧回数
Simone_Italy
Contributor I
Thank you very much for your help!
Bye.
 
Simone
0 件の賞賛