This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Help for a beginner

Can someone pleae tell me how to write a medium size code systematically??
for example, I have one .c file for LCD, another .c file for keyboard, another .c file for ADC reading. main() is written as main.c. Now i have added all these source codes; but my doubt is how can I call these deifferent files from main; how compiler wil come to know that these many files make the code complete??
Is there any reading material available anywhere?? please help..

Parents Reply Children
  • In the example files provided by keil compiler, few examples are with a header files particular to that project and some don't? what is the criteria for these headewr files?

  • Unfortunately it is necessary to learn a bit about 'C' before you can start using it. Maybe you could take a class? Once you are reasonably familiar with 'C' you would do well to read the 'Getting started' guide provided with the Keil tools.

  • Thanx Andrew and Stefan for ur promt replies.

  • Typically a larger program will be subdivided into modules. Each module contains a group of functions with a single common purpose, a unifying theme. For example, I might have a serial port module that has the UART interrupt handler, buffering, and I/O routines in it, and another module that contains routines for erasing and programming flash.

    In C, such modules are usually represented by a .c file, containing the definitions of functions and variables needed to implement the features of the module, and a .h (header) file, which contains only the declarations for the public interface to the module. Many modules will have some routines intended to be used only internally. These need not be declared in the .h file.

    Clients of a module would then #include the .h file to have access to the interface for the module, and would use those routines.

    The compiler produces object files from the .c files. The linker takes all the object files necessary to create a complete program, and creates the linked, "executable" form of the program.

    It's generally the responsibility of the programmer to tell the linker which object files are needed. Since larger projects tend to divided into dozens of files, there are tools intended simply to organize and automate this process. "Make" is the classic example from Unix, and project build files are often called "makefiles" even for other tools. The uVision IDE supplied with the Keil tools has its own format for project build files that lists all the components of a particular program.

  • "Typically a larger program will be subdivided into modules. Each module contains a group of functions with a single common purpose, a unifying theme. For example, I might have a serial port module that has the UART interrupt handler, buffering, and I/O routines in it, ..."

    This is well illustrated by the Keil interrupt-driven serial IO example download:

    http://www.keil.com/download/docs/200.asp

    The UART interrupt handler, buffering, and I/O routines are defined in the file sio.c; a header file sio.h provides declarations; the main.c file #includes sio.h so that it can use the serial IO facilites.

  • Thanbx Andrew

    This has cleared my doubt completely. Thank you once again.