i have written the C code complied it with 0 error and 0 warnings.
now how can i divide this codes into small c codes in same project.
please help me as i am new to embedded world
This has nothing specifically to do with embedded - nor even with any specific programming language! This is a basic programming principle.
You should look for functions (and associated data) that have something in common, and group them into a "module" (ie, a .c source file) of their own.
How well a group of functions goes together is known as "Cohesion". There are several types of cohesion; eg,
Functional Cohesion - things which go together to perform a single, well-defined function within the system; eg, a UART driver.
Temporal Cohesion - things which happen at the same time; eg, initialisation.
Coincidental Cohesion - things which really don't have anything in common at all, and are just grouped together because you couldn't think of anywhere else to put them!
See: en.wikipedia.org/.../Cohesion_(computer_science)
For the specifics of how to do this in 'C', see your 'C' textbook, and take a look at c-faq.com/.../decldef.html
Also take a look at the examples included in your C51 installation (also available on this website) - I think pretty much all of them contain more than 1 source file...
thanks, it helped me alot.
I think a prime example of Coincidental Cohesion is to put all your globals from the whole project into one file called "globals.c" - with a corresponding "globals.h"...
one file with the following
#if ralph #define fido extern #else #define fido #endif
and all definitions/declarations preceeded by fido
then in one .c file #define ralph
Erik
That's not a prime example of anything. It is, above all, a bad example. An altogether too common one, too.
#if ralph #define fido extern #else #define fido #endif /*there should be an*/ #undef ralph /*here, to avoid nasty side effects from multiple inclusion
Let's note that most people still using that "trick" actually call that fido "EXTERN" or some variation of that to make it at least marginally self-explaining.
But it's still a half-baked idea. For starters, it breaks down as soon as you want to have explitly initialized globals use the same scheme. It also upsets various kinds of static analyzers that hate it when the same header expands to different things in different translation units.
It is a prime example of a Bad Thing!
this works for me i find 0 errors and 0 warning...
thanks u all....
You mean, the compiler finds 0 errors?
But the compiler can only find syntax errors - it cannot tell if your project is well-organised, easily maintainable, reliable, etc...
In fact, 0 errors and 0 warnings doesn't even mean that your program will work!
thanks i got the problem, it was that when i am calling a function which where in the different C file was not linked with other C files of projects
thanks to all of u.
now my project is working