Structure of embedded c program
This section deals with the structure of Embedded C programming. This section is described the tiva launchpad but the structure is similar for other microcontrollers too. The programming structure helps to build the algorithm for application.
Embedded C program can be divided into the following section:
1. Import header files:
When writing an embedded C program, including the header file is the first step. Normally two types of header files are using in the program: standard c programming related header files and header files which consists of information related location of register and peripherals functionality. It may contain a library-related file which is used for a specific feature of an application.
2. Declaration of global variables:
Declaration of a global variable is the second step. This variable is accessible for all the functions of the program. Stack memory is used to store this program.
3. Function declaration:
After declaring the global variables the definition of which are linked with the main program are declared. This section mainly consists of interrupt related functions.
4. Declaration of local variables:
Local variables are declared inside a function. These variables have a scope limited to that particular function only. Stack memory is used to store these variables.
5. Main function:
It is the main function of the program where the application starts to run.
6. System initialization:
This section mainly deals with the selection of a clock circuit. Different values of frequencies are generated by selecting the main oscillator, internal precision oscillator, or using PLL. This is the main operational part of the program.
7. Initialization of peripheral:
This part used for enabling peripherals which are required for building application. Initialization of timer, GPIO port, CAN-UART-SPI module will be done here.
8. Configuration of peripheral:
After the initialization of the configuration of the peripheral of a particular pin will be done here. Input-output pin, sensing of input current, etc. will be declared here.
9. Main loop:
Execution of a particular task with proper sequence will be declared here. This is the main body part of the program which is executing multiple times.
Comments
Post a Comment