CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

problem with a kind of a loop #include

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Skywalker



Joined: 11 Mar 2004
Posts: 5
Location: Germany/Ilmenau

View user's profile Send private message ICQ Number

problem with a kind of a loop #include
PostPosted: Thu Mar 11, 2004 8:09 am     Reply with quote

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
Code:

#include <main.h>


main.h
Code:

#ifndef h_main
#define h_main

#include <file1.h>
#include <file2.h>

#use delay .....

#define .....

#endif


file1.c
Code:

#include <main.h>


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
Code:

#include <main.h>


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

View user's profile Send private message

PostPosted: Thu Mar 11, 2004 11:29 am     Reply with quote

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

View user's profile Send private message ICQ Number

PostPosted: Fri Mar 12, 2004 1:56 am     Reply with quote

Thx PCM programmer

That works fine

Andreas Very Happy
alemeno



Joined: 22 Sep 2011
Posts: 1
Location: Miami, Florida

View user's profile Send private message

PostPosted: Fri Oct 07, 2011 11:37 am     Reply with quote

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: 1611
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Fri Oct 07, 2011 11:43 am     Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group