Mutad0r
Junior Member level 3
- Joined
- Feb 13, 2013
- Messages
- 28
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,281
- Activity points
- 1,608
So I was recently on the microchip forum and people were apalled by my dirty code, and I agree with them, it's messy. And since my project is only going to get more complicated I thought I'd clean it up and make it.. better..
After some googling and searching the forum I was amazed at their righteousness clean coding standards and suprise that I didn't follow them as there were poor samples only showing the simplest of things. Sure, the programming is in c, so any c tutorial or example should be helpful, but the MPLAB enviorment is a bit different and it doesn't always work the same way.. as far as I'm aware of...
Basically the problem is using multiple files as you can guess, so far I had one source file and headers and I put almost everything in headers, prototypes, defines, functions. The Source file sure looked clean, but aparrently I shouldn't put functions in headers. Ok, sure, whatever, lets make more c files then.
So far I've learned that you should put prototypes in the headers and functions in the c files and I believe I can achieve that with simple code, but my code isn't very simple. There's some important information that I couldn't find, so here are a couple of questions that I have.
-Where do files go?
Header files is easy, put them in the header folder, the main source file is easy, put that in the source folder, the "other" .c files get a bit more difficult, there is mentioned that the other .c files should go in the "other" folder, but there is no such folder in MPLAB X, There is mentioned that "other" folder in MPLAB X is "important files" folder, but that folder doesn't accept .c files. Only the "linker files" folder accepts .c files, but that doesn't sound like the right place.
So only source files folder and linker files folder accepts .c files, but I read that the source folder should only contain the main c file, and the linker folder name suggests that it contains something other than what I'm looking for.
- How do I REALLY include things
There are multiple explanations on the web: make a header for the .c file and include that in the c file and the source file, or make a header for the .c file and include that in the source file and include the .c file in the header file.
-Seriously, how do I REALLLLLY include things??
With just the one source file and headers it was easy, I included all the relevant headers in the source files and everything worker, then I move the code from the header file to a .c file and all of a sudden the code cannot find functions declared in the #include <I2C.h> in the source file or the __delay_ms() functions wherever THAT is declared.
And then how can I use functions declared in one .c file to be used in another .c file
Hopefully someone can make a simple example... Meanwhile I'll keep scouring the web for answers...
After some googling and searching the forum I was amazed at their righteousness clean coding standards and suprise that I didn't follow them as there were poor samples only showing the simplest of things. Sure, the programming is in c, so any c tutorial or example should be helpful, but the MPLAB enviorment is a bit different and it doesn't always work the same way.. as far as I'm aware of...
Basically the problem is using multiple files as you can guess, so far I had one source file and headers and I put almost everything in headers, prototypes, defines, functions. The Source file sure looked clean, but aparrently I shouldn't put functions in headers. Ok, sure, whatever, lets make more c files then.
So far I've learned that you should put prototypes in the headers and functions in the c files and I believe I can achieve that with simple code, but my code isn't very simple. There's some important information that I couldn't find, so here are a couple of questions that I have.
-Where do files go?
Header files is easy, put them in the header folder, the main source file is easy, put that in the source folder, the "other" .c files get a bit more difficult, there is mentioned that the other .c files should go in the "other" folder, but there is no such folder in MPLAB X, There is mentioned that "other" folder in MPLAB X is "important files" folder, but that folder doesn't accept .c files. Only the "linker files" folder accepts .c files, but that doesn't sound like the right place.
So only source files folder and linker files folder accepts .c files, but I read that the source folder should only contain the main c file, and the linker folder name suggests that it contains something other than what I'm looking for.
- How do I REALLY include things
There are multiple explanations on the web: make a header for the .c file and include that in the c file and the source file, or make a header for the .c file and include that in the source file and include the .c file in the header file.
-Seriously, how do I REALLLLLY include things??
With just the one source file and headers it was easy, I included all the relevant headers in the source files and everything worker, then I move the code from the header file to a .c file and all of a sudden the code cannot find functions declared in the #include <I2C.h> in the source file or the __delay_ms() functions wherever THAT is declared.
And then how can I use functions declared in one .c file to be used in another .c file
Hopefully someone can make a simple example... Meanwhile I'll keep scouring the web for answers...