View previous topic :: View next topic |
Author |
Message |
Wraith
Joined: 08 Sep 2004 Posts: 5 Location: Ipswich
|
Function prototypes and multiple file programs |
Posted: Wed Sep 08, 2004 10:04 am |
|
|
I have just loaded the CCS compiler, I have been using the Keil compiler for 8051.
IN the Keil compiler you create the initial program file with the main() function and include .h containing the function prototypes for functions located in other files. This does not appear to work. Secondly, when the compiler starts to compile the second file it complains that there is no main() function in it.
I am sure that it is something which is easily solved but I have not managed to find anything to tell me what I am doing wrong. |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Wed Sep 08, 2004 10:17 am |
|
|
There is only one "C" file to be compiled. Other "C" files would have to be included in the main C file. |
|
|
StuH_CC
Joined: 07 May 2004 Posts: 16 Location: Shropshire, UK
|
|
Posted: Wed Sep 08, 2004 10:22 am |
|
|
The CCS compiler only supports one program (.c) source file. The concept of projects, with associated makefiles, is foreign to CCS C.
The usual workaround is to #include all the .c files in a project, e.g. in your main source it would look something like:
Code: |
#include <16F876a.h>
#include "prototypes.h"
#fuses HS,WDT,NOPROTECT,BROWNOUT,PUT,NOLVP //example!
//more setup here
#include "file_one.c"
#include "file_two.c"
void main( void )
{
//code here
}
|
It may not even be necessary to have any prototypes, depending on whether the function in question is called before or after its definition.
Stu. |
|
|
JBM
Joined: 12 May 2004 Posts: 54 Location: edinburgh, Scotland
|
Includiong .c |
Posted: Wed Sep 08, 2004 10:24 am |
|
|
In the .h file you refrence from the main file, do you also #include the .c file for those functions after the prototypes? eg
Code: |
------
<file main.c>
------
#include *.h
...
main()
{
}
------
file *.h
------
void function1();
void function2();
...
#include "*.c"
-----
|
This means you only compile the main.c file and the compiler refrences the other source files for you.
( or you could just add the code for the functions to the .h file after the prototypes, although it is a little unconventional ) |
|
|
Wraith
Joined: 08 Sep 2004 Posts: 5 Location: Ipswich
|
Further information |
Posted: Wed Sep 08, 2004 10:34 am |
|
|
I am using the CCS compiler through MPLABS.
I have just had a further thought. In the Keil software the files are compiled and then linked. Does this software just expect to compile one file (no linking required)? I have sucessfully compiled my skeleton structure using the line:
#include "adc control.c"
to include the file and removed 'adc control.c' from the source files section of the project (just leaving 'main.c').
Is this the way that the compiler has to be used through MPLABS? |
|
|
Wraith
Joined: 08 Sep 2004 Posts: 5 Location: Ipswich
|
|
Posted: Wed Sep 08, 2004 10:53 am |
|
|
Thanks for the help. This seems a bit alien to me but I am sure that I will get used to it, must have been using the keil compiler to long (7 years). |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Wed Sep 08, 2004 11:02 am |
|
|
Nope, its Alien! |
|
|
|