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

Adding extra .c files to a project

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



Joined: 12 Feb 2004
Posts: 9
Location: Surrey, UK

View user's profile Send private message Visit poster's website

Adding extra .c files to a project
PostPosted: Fri Feb 13, 2004 3:50 pm     Reply with quote

I would like to split my project into a number of .c files, sharing a common .h header file. I am trying to do this under MPLAB V6.30. I put function prototypes in the header file and an #include statement for the header file in each .c file.

However when I try to compile, I get "Function used but not defined" meaning that a function called in main.c is prototyped in the header file but the definition in the other .c file is being ignored.

What am I doing wrong? Both .c files are included in the project list.

Any help greatly appreciated!
rwyoung



Joined: 12 Nov 2003
Posts: 563
Location: Lawrence, KS USA

View user's profile Send private message Send e-mail

PostPosted: Fri Feb 13, 2004 7:00 pm     Reply with quote

It is my understanding that the CCS compiler can't deal with more than one C file unless you use a #include "xyz.c" and force the pre-processor to pull in the C file.
_________________
Rob Young
The Screw-Up Fairy may just visit you but he has crashed on my couch for the last month!
Peter F



Joined: 12 Feb 2004
Posts: 9
Location: Surrey, UK

View user's profile Send private message Visit poster's website

PostPosted: Sat Feb 14, 2004 3:40 am     Reply with quote

Thanks, I was beginning to suspect that. That's what I was doing originally to break up the files - although the extra files were saved as .h header files and brought in using #include. The problem with that, running under MPLAB, seems to be that the debugger can't resolve any breakpoints set in these files. I'll try again with them saved as .c files - maybe that will work!

I'd prefer to use the CCS IDE, but unfortunately I can't get the ICD-U40 to program the target chip - it runs the target self test fine, but always reads back FF. Works fine with ICD-2 under MPLAB...

If I could get the tools working I might be able to get on with some programming!
Douglas Kennedy



Joined: 07 Sep 2003
Posts: 755
Location: Florida

View user's profile Send private message AIM Address

ICDU-40
PostPosted: Sat Feb 14, 2004 7:31 am     Reply with quote

You may well have tried this but the ICDU needs a fair amount of power to program the target PIC. I had problems until I plugged the ICDU into an externally powered USB hub. If there is too little power you should get a message but there could be a no man's land where the USB bus doesn't see too much drain but there is not enough to get the PIC to take a download. Sharing a standard mobo USB port with the ICDU and something else could be your problem.
Peter F



Joined: 12 Feb 2004
Posts: 9
Location: Surrey, UK

View user's profile Send private message Visit poster's website

ICD-U40 not programming
PostPosted: Thu Feb 19, 2004 11:20 am     Reply with quote

I tried connecting the ICD-U40 via a powered hub (had to reload the usb driver), but this seemed to have no effect, unfortunately. Still read back all FF during verify. Crying or Very sad
rwyoung



Joined: 12 Nov 2003
Posts: 563
Location: Lawrence, KS USA

View user's profile Send private message Send e-mail

PostPosted: Thu Feb 19, 2004 2:10 pm     Reply with quote

There was a thread a while back about the ICD-U and I believe one of the problems was similar to what you are describing. The poster said that using a small ferrite torroid on the programming cable (not the USB cable) helped.

I think he was looping the programming cable through the torroid.
_________________
Rob Young
The Screw-Up Fairy may just visit you but he has crashed on my couch for the last month!
pat



Joined: 07 Sep 2003
Posts: 40
Location: Adelaide, Australia

View user's profile Send private message

PostPosted: Thu Feb 19, 2004 8:55 pm     Reply with quote

I've been able to do this with no problems.

The first lines of my main "ros.c" are as follows:

Code:
#include <16f876.h>
#include "ros.h"
#include "D:\iros\PIC drivers\utilities.c"
#include "D:\iros\PIC drivers\adxl driver.c"


For the few functions defined in "ros.c" I put their prototypes at the end of "ros.h". Most of the functions are defined in "utilities.c" and "adxl driver.c" and the prototypes are contained at the start of each of those ".c" files respectively.

I can't confirm right now, but I don't think "utilities.c" and "adxl driver.c" include "ros.h". If you needed defines from "ros.h" could you not use #ifndef at the start of "ros.h" so the compiler only includes it once?

Did that answer your question?
Pete Smith



Joined: 17 Sep 2003
Posts: 55
Location: Chester, UK

View user's profile Send private message Visit poster's website MSN Messenger ICQ Number

PostPosted: Fri Feb 20, 2004 5:38 am     Reply with quote

pat wrote:
I've been able to do this with no problems.

The first lines of my main "ros.c" are as follows:

Code:
#include <16f876.h>
#include "ros.h"
#include "D:\iros\PIC drivers\utilities.c"
#include "D:\iros\PIC drivers\adxl driver.c"




You can also include "D:\iros\PIC drivers\" in ccsc.ini, and then you can just do

#include "utilities.c"

Pete.
Peter F



Joined: 12 Feb 2004
Posts: 9
Location: Surrey, UK

View user's profile Send private message Visit poster's website

Adding c files
PostPosted: Mon Feb 23, 2004 2:21 am     Reply with quote

I found that I could use "include" to add extra c files at compile time. However under MPLAB you can't add these files to the project (otherwise they get compiled twice!) And therefore you cannot debug them - set breakpoints etc. Maybe OK within the CCS IDE, but I can't use that due to problems with ICD-U40.

Currently working with everything in one big file, which is a pain as I keep having to use "search" to get to the code I am debugging.
pmdebenham



Joined: 05 Nov 2003
Posts: 1
Location: UK

View user's profile Send private message Visit poster's website

PostPosted: Mon Feb 23, 2004 6:02 am     Reply with quote

Rename the additional "C" files with a different prefix (e.g. ".c2").

Include the additional source files with #include directives as suggested by previous posters.

You can now add the additional files to the MPLAB project without it trying to compile them. MPLAB will regard the .c2 files as unclassifiable but will allow you to set breakpoints, debug etc.

I have this happily working with MPLAB 6.40 and PCM v3.182.

This still has the problem compared to really having separate "C" files that all variables and functions share the same namespace but it is the best solution you are going to get with the CCS compiler.

Regards,
_________________
Dr Peter Debenham
Consultant
Plextek Ltd.
http://www.plextek.com
Peter F



Joined: 12 Feb 2004
Posts: 9
Location: Surrey, UK

View user's profile Send private message Visit poster's website

PostPosted: Mon Feb 23, 2004 10:01 am     Reply with quote

pmdebenham wrote:
Rename the additional "C" files with a different prefix (e.g. ".c2").

Include the additional source files with #include directives as suggested by previous posters.

You can now add the additional files to the MPLAB project without it trying to compile them. MPLAB will regard the .c2 files as unclassifiable but will allow you to set breakpoints, debug etc.

I have this happily working with MPLAB 6.40 and PCM v3.182.

This still has the problem compared to really having separate "C" files that all variables and functions share the same namespace but it is the best solution you are going to get with the CCS compiler.

Regards,


Thanks for that. I gave it a try, but I still couldn't set breakpoints within the included files. I even upgraded to MPLAB 6.40 but that made no difference. If I set a breakpoint in the included file, then press RUN, a warning comes up that the breakpoint cannot be resolved. The breakpoint is then removed and the program runs without breaking.
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