View previous topic :: View next topic |
Author |
Message |
Skywalker
Joined: 11 Mar 2004 Posts: 5 Location: Germany/Ilmenau
|
problem with a kind of a loop #include |
Posted: Thu Mar 11, 2004 8:09 am |
|
|
I have the following Problem:
I want that my main.c have access to the files file1.c and file2.c
these have header files file1.h and file2.h.
The filex.c have to have access to main.c and the main.h because I have #use delay... in the main.h an I have a delay in the file1.c
The other thing is, that I have to access some functions form file1.c in the main.c and the other way.
The problem I have is, that no variable in the main.c is accepted
I get an error that this is an undefined identifier, but i have declared it a few lines before.
Another is, that I can't use the delay in file1.c because this file has no access to the main.h
I know my description is not very good but I hope with my code you can understand whats my problem.
At another C Compiler I used this working code
main.c
main.h
Code: |
#ifndef h_main
#define h_main
#include <file1.h>
#include <file2.h>
#use delay .....
#define .....
#endif
|
file1.c
fille1.h
Code: |
#ifndef h_file1
#define h_file1
#include <file1.c>
define...
extern void functionx(void); //I want to use this in the main.c
#endif
|
file2.c
fille2.h
Code: |
#ifndef h_file2
#define h_file2
#include <file2.c>
define...
extern void functiony(void); //I want to use this in the main.c
#endif
|
I hope you can help me to make something like a loop access in the CCS Compiler.
Andreas |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Mar 11, 2004 11:29 am |
|
|
I'm not sure what you're doing, but I think you're trying to
be too fancy for CCS. There is no linker in CCS, so there
is no "extern". All files have to be "added" to the project
with #include statements. Here is one way to do a project
with several source modules in CCS:
Code: | #include <18F458.H>
#fuses XT, NOPROTECT, NOBROWNOUT, NOWDT, NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, errors)
#use i2c(Master, SDA=PIN_C4, SCL=PIN_C3)
#zero_ram
#ignore_warnings 202, 203
//----------------------------
// Header files for your modules.
#include <ds1307.h>
#include <24LC256.h>
// Other source modules.
#include <ds1307.c>
#include <24LC256.c>
//----------------------------
// Function prototypes for functions in this module.
void power_up_init(void);
//=======================================
void main()
{
power_up_init();
init_eeprom();
// Put other code here.
while(1);
}
//===========================
void power_up_init(void)
{
setup_adc_ports(NO_ANALOGS);
output_low(PIN_A0);
output_high(PIN_A1);
// etc.
} |
|
|
|
Skywalker
Joined: 11 Mar 2004 Posts: 5 Location: Germany/Ilmenau
|
|
Posted: Fri Mar 12, 2004 1:56 am |
|
|
Thx PCM programmer
That works fine
Andreas |
|
|
alemeno
Joined: 22 Sep 2011 Posts: 1 Location: Miami, Florida
|
|
Posted: Fri Oct 07, 2011 11:37 am |
|
|
I'm trying to add a .c file to my project using the #include but the compiler tells me "File can not be opened", and no file is added to my project. I even created a new project with the code above from PCM programmer and got the same results. What am I not doing right? Me compiler version is 4.104 |
|
|
bkamen
Joined: 07 Jan 2004 Posts: 1615 Location: Central Illinois, USA
|
|
Posted: Fri Oct 07, 2011 11:43 am |
|
|
Are you using
#include "filename.c"
or
#include <filename.c>
they are different.
While the "" looks in the same directory as the 'C' file you're compiling, <> will look in the library paths (whatever they may be)
if you have a subdirectory of .C files in your project directory, then you should include that subdir like thus:
#include "somedir/somefile.c"
I've also had global routines included in sub-projects like this
#include "../globalroutines.c"
-Ben _________________ Dazed and confused? I don't think so. Just "plain lost" will do. :D |
|
|
|