Include

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

Include

1,948 次查看
admin
Specialist II
I'm trying to learn the C language for microcontrollers but I'm facing a problem that I can not see the solution. I started an application using the CodeWarrior Processor Expert and after setting the pins, interruptions and so one, it generated two files named MCUinit.c and MCUinit.h and besides main.c,
libraries (include) files and others.
My intention is to generate a file type ".c", ".h", ".inc" or another (because I haven't had success yet) where I will place the global variables and/or functions that could be accessed by all files of the program (main.c, MCUinit.c).
I created a ".h" (and also tested as".c") file with definitions of  global variables but only file main.c can use this variables without problems while the file MCUinit.c returns the message that the variable was not declared.
If I include the same filte intto MCUinit.c file it returns that the variables had already been declared.
The microcintroller is MC9S08QG8
Could someone help me?
Thanks a lot.
标签 (1)
标记 (1)
0 项奖励
回复
2 回复数

1,057 次查看
allawtterb
Contributor IV
It sounds like you are trying to place definitions of variables in a header file(.h) and then include it in main.c and MCUinit.c. You should not put any definitions in your header file but only declarations, put your defintions at the top of your .c file. 
Code:
unsigned char Variable1;   // Defintion, should go at the top of the .c file it belongs toextern unsigned char Variable1;   // Declaration, this goes into your header file

You might want to take a look at the following link as well:

http://forums.freescale.com/freescale/board/message?board.id=CW816COMM&message.id=4163&query.id=5732...

I would also suggest reading up on the difference between a definition and a declaration.

 

- Brett

 

1,057 次查看
CrasyCat
Specialist III
Hello
 
Seems to be complex to explain and understand.
 
I would recommend you to submit a service request for that.

Click here to submit a service request.

Make sure to attach a reproducible project and installed product information to the service request.
To generate the required information:
- Start CodeWarrior
- Open the project
- Select "Help" -> "Pack and Go" and follow instructions on the screen.

Attach the generated .zip file to the SR.
 
CrasyCat