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

Multiple Files Compilation

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



Joined: 09 Sep 2009
Posts: 7

View user's profile Send private message

Multiple Files Compilation
PostPosted: Wed Feb 22, 2012 11:23 am     Reply with quote

Hello,

I have seen tons of threads on this subject and not once seems to outline a simple example.

I have a PIC and I want to separate into multiple C files and .h files all the actions.

Contain top level

main.c
main.h

low level
adc.c
adc.h
interrupts.c
interrupts.h
gpio.c
gpio.h
spi.c
spi.h
i2c.c
i2c.h

I want to write everything pertinent to ADC only in ADC, and use all the functions in main. How do I do this? Likewise for all the other c files. I want them visible to main. I also want certain variable in the other c files be usable in main.c . I suppose I can use the EXTERN keyword right?

What should main have? I would imagine main.c will have all the header files, and all the functions should be visible in main. Do I need to use Extern for variables used in spi.c to be visible in main.c or viceversa?

In main.c I placed all header files

main.c
Code:

#include adc.h
#include interrupts.h
#include gpio.h
#include spi.h
#include i2c.h

void main(void)
{
// my state machine here with functions only to remove all clutter!
}


I compile and I get garbage... it will not compile correctly as compared to a single file (i.e., I bunch all the functions into a single main.h and main.c).

Please if you reply to this post, please don't refer me to a link. I have seen them all literally. None of them answer my question. I am using strictly CCS IDE with PCH, and not MPLAB.

I want to know if under options there is a check box or something to make the IDE understand that all C files are part of the same project (single unit compilation). I never that this issue with Code composer or IAR compiler for other targets. The IDE recognizes automatically the C files are part of the project and compiles them. Why is this such an ordeal in CCS? Can anyone share my pain and frustration?

I just want a simple example that works, and that allows me to break the code into multiple c files and generate the same code as when I generate a single C file.

Anyone with a simple example that compiles fine and wishes to share it, I will really appreciate it. I keep reading threads that do not resolve the issues. If I figure it out, I will post my example too.

Regards
rjrodrig[/u]
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Feb 22, 2012 2:41 pm     Reply with quote

The problem with your post is:

1. You limit it to the CCS IDE. This cuts out at least 50% of all possible
replies, from people who use MPLAB but who might otherwise be able to help.

2. You say that you read all posts in the archives and don't want links.
This cuts out all the entire body of knowledge that we have, even in our minds.

3. Effectively, we are not allowed even to ask you any questions.
For example, we'd like to ask, "Are you using Multiple Compilation Units
in the CCS IDE" ? And a lot of other questions. But in all the previous
archived posts, I am sure that topic came up and you don't want to hear
about it.

So, no reply, really.
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