September 03, 2011

How to make a header file for Embedded C?

Hello folks many friends asked me "wouldn't it be better idea if we have our headerfile to include our own functions and not even copy paste them in coding?"
The solution is here, to create your own header file....
first of all make any C program which you want to include in header file...
like the one given here
this is a file for including a password in your micro controller...

basically this program is for the AVR8535 development board by Technophilia. and all hardware connections are assumed to be of that only, but it doesn't matter here which microcontroller I use because you have to make your own header file.........
so take this just as a demo..





After debugging every syntax and (a lot of)logical errors when you think that the program is working fine
you are ready to make your own header file...


step 1)Copy and paste your all codes into a notepad...


step2) edit your function's name
  • we must have to declare the function here which we want to call...
  • like in my demo i changed the name of "main" program to "pass"
  • here you can declare it as any function which can accept values or  return                               programming remains just same as C.
 step3)at the top of your header file you have to define the name of your header file
  • #ifndef _(your header file name)_H      //and do write name without braces
  • #define _(your header file name)_H     //and do write name without braces
step 4)at the end of your header file write
  • #endif 
step5)save the document as "(your header file name).h" as we mentioned earlier...




You are done now
here is how my header file looks like you can see no fuzzy thing is done over here
you can include your program any time you want just dont forget to put the header file in your work directory......


here is the example of how we can minimize the coding time including our own "home made header file"

you can see the size of both the main files and feel the HUGE difference because of including a header file,this is good because we have to deal with less on-chip memory....




so now guys you know that making your own header file  is not Rocket Science....



see ya :)





0 comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...