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 CCS Technical Support

How code with multiple source files in CCS C

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



Joined: 24 Oct 2017
Posts: 2

View user's profile Send private message

How code with multiple source files in CCS C
PostPosted: Thu Aug 23, 2018 1:47 am     Reply with quote

Hello guys, I have a code for LC meter using Nokia 3310 display and PIC16F876A microcontroller. Which is written by some other person in MPLAB(8.4) version. The code is packed by winrar. When i extract the .rar file i have noticed that inside the folder there are three .c files and as well as three corresponding .h file. The three header files are:
1. "display.h" Which probably displays various values and to adjust screen.
2. "lcd3310.h" which is for activating the lcd module
3. "main.h" the main program.


Now inside the main program the above 3 header file is mentioned. Like below:

My question is how does the program work ? and which file should be uploaded in to the micro-controller ?

This time i wanted to use 0.96″ OLED I2C Display Module. And I have a code for this.https://www.ccsinfo.com/forum/viewtopic.php?t=52861

But as per my knowledge the entire code should be inside just one .C file not like 3 mentioned above.
My question is
1. What will be the difference if i use 3 separate code instead of just one main program Which consist of three part ?
2. If i write 3 individual code mentioned above then How can i join them and compiled them in to one ?

Please give detailed advice as i am a programming beginner.
Ttelmah



Joined: 11 Mar 2010
Posts: 19477

View user's profile Send private message

PostPosted: Thu Aug 23, 2018 3:16 am     Reply with quote

Using multiple files is normal. You do not want to have everything in one file.

The key though is that MPLAB, must only have the main file in it's 'source files' tab. The other files are put into the 'header files' tab. So in your case, main.c _only_ in the source files tab.

Your main file simply #INCLUDE's the other files.

My current project has 24 files in use.

None of these files will be uploaded to the controller. These are _sources_. They have to be compiled to turn them into machine code, which can be loaded into the controller.

The #INCLUDE lines you have already combine the files. Just compile main.c. Nothing else.
khatus



Joined: 24 Oct 2017
Posts: 2

View user's profile Send private message

PostPosted: Thu Aug 23, 2018 3:26 am     Reply with quote

But how can i do that in CCS C.Can you tell me the process??
Ttelmah



Joined: 11 Mar 2010
Posts: 19477

View user's profile Send private message

PostPosted: Thu Aug 23, 2018 3:38 am     Reply with quote

Read the manual!....

If you have just the command line compiler look at the section 'Invoking the command line compiler".
If you have the IDE, just run it. Then select the main file, and push the 'compile' button.
temtronic



Joined: 01 Jul 2010
Posts: 9215
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Thu Aug 23, 2018 5:03 am     Reply with quote

I've used CCS C 'from within' MPLAB for 20 years, simply pressing F10 will compile the code. CCS has a program(ap to the new folk) that 'merges' CCS C into MPLAB. One important point is that if using MPLAB, you must configure the 'build option' to 'release' NOT the original default of 'debug', otherwise the cmpled code, once downloaded into PIC will not execute correctly.
What's really handy is that pressing F11, opens up the MANUAL, making it easy to lookup any of the functions, check syntax, read FAQ,etc.
Jay
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Aug 23, 2018 5:43 pm     Reply with quote

khatus wrote:

But how can i do that in CCS C. Can you tell me the process?

This CCS page tells how to use their command line compilers (PCM, PCH,
etc.) with MPLAB vs. 8.xx:
https://www.ccsinfo.com/faq.php?page=ccs_mplab

This post shows how to write your main C source file, so it #includes
your .h and .c driver files:
http://www.ccsinfo.com/forum/viewtopic.php?t=18649&start=1

If you have setup your MPLAB project correctly, only your main.c file
should be listed in the Project window, as shown below:
Code:
-LC_meter.mcp
  - Source Files
     - main.c

  -Header Files

  -Other Files


Also, if you found this code on the internet, it may not be for the CCS
compiler. If it's for some other compiler, you will get a lot of errors
and the code will have to be re-written in many places to be compatible
with CCS.
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