Multiple file program

Go To Last Post
12 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,

   As a novice, I'm not aware of how to split a big program into multiple files using Atmel Studio 4.

Can anyone suggest me the steps that should be followed to split a program into multiple files?

If possible please let me know the detailed procedure of it.

Also tell me how & what should be present in the header files(.h) & files with .c extension.

Gaurav Gawade

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Which version of AS4 are you using? Here is a project that can talk with up to 4 USART ports, it should give you an idea. Should open with AS4.18

Attachment(s): 

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

To be honest there's nothing really specific to the AVR about this. Your standard C manual should tell you about things like "extern" and when/where to use it. But we do have this tutorial on Freaks too:

 

https://www.avrfreaks.net/forum/t...

 

Bottom line: shared declarations in .h file, unique definitions in .c files.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

In the GNUlinux world (and cygwin), there is a tool called csplit which puts each and every fuction of an initial C file into a seprate file  https://www.computerhope.com/uni... . A brute force approach, having a *.c file (then, a .h file) can be done. (Christophe Blaess criticezed csplit, as it splits commented out functions, too... and had another solution).

 

Perhaps you should look at http://www.github.com/abcminiuse... (this solution makes you reread what you wrote, and is therefore less mecanical and does not favor bug survival)

 

 

Last Edited: Mon. Jul 31, 2017 - 09:38 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

dbrion0606 wrote:
In the GNUlinux world (and cygwin), there is a tool called csplit which puts each and every fuction of an initial C file into a seprate file
But surely that is simply in preparation for creating a static .lib? What relevance does that have here?

 

Presumably OP has a long source that maybe includes a bit of UART, a bit of ADC and so on and he wants to put the UART related bits into uart.c/.h and ADC bits into adc.c/.h - don't see how this could be automated?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

But surely that is simply in preparation for creating a static .lib? What relevance does that have here?

 

 

Well, I suppose people who made csplit were just wanting to ... split C programs into functions , nothing else (ftnsplit did the same). It can be used to understand / print part of a software.... Blaess managed to overcome the commented out fuction issues in https://www.blaess.fr/christophe... . His purpose was .. to understand...

 

Seems printing/understanding is a good idea before making static libraries???? (and abcminiuser, I linked to, was rather methodical in this purpose)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks

 

Deleted the rest....JS

Gaurav Gawade

Last Edited: Mon. Jul 31, 2017 - 09:18 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Was it really necessary to make 5 identical "Thanks" posts? Why not just "Thanks everyone"?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks everyone. Is it ok clawson?

Gaurav Gawade

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It's OK. (-:

 

Just be a little careful when you "navigate backwards"  in your web browser. You will get back to the page where you wrote your post, and before a refresh it will look like you never posted. Don't post a second time when this happens.

 

I know a member here who has more than 25000 posts and still manages to do double-posts like that from time to time.. ;-)

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

Last Edited: Mon. Jul 31, 2017 - 01:30 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ok

 

Gaurav Gawade

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

As a "novice" do not split a big project into multiple files.

 

start by reading which stuff should go where and why.

Read tutorials, follow existing conventions.

 

Then start a new project with 2 C files and 2 header files.

 

main.c

#include <stdio.h>
#include "stuff.h"

void main (void) {
    printf( "Stuff = %3d\n %5d ", stuff(), number);
}

main.h

// Empty.

 

stuff.c

 

const int number = 42*42;

int stuff ( void) {

    return 42; // The answer to god, the universe and everything.
}

stuff.h

extern const int number;

extern int stuff( void);

Code above is untested, but it is about as simple as you can make it.

Get this to compile first and then extend your knowledge by the act of learning :)

 

And do this on a PC. do not run it on a uC because that is only an extra complication you do not need at this time.

Doing magic with a USD 7 Logic Analyser: https://www.avrfreaks.net/comment/2421756#comment-2421756

Bunch of old projects with AVR's: http://www.hoevendesign.com

Last Edited: Tue. Aug 1, 2017 - 02:38 PM