microcontroller - PROGRAM FLOW
Before programming a micro-controller, one should have basic concept on flow-chart and algorithm.
While programming a micro-controller, the following order of sequence is followed in general. A small deviation may be observed, which depends on the habit of the person, who is programming and micro-controller programming IDE (integrated Development Environment) software, which is used for programming and compiling. Some IDEs support the option to directly upload/write the binary code to MCU.
-
comments/remarks and GNU about the program
-
Declaration of frequency of the MCU clock. Sometimes optional, which may be declared in the settings/preferences.
-
include or import the libraries required. Some libraries may be included by default, which depends on the IDE.
-
Declare the global variables and initial values as required for the program
-
Declare the classes or structures, if any ( normally used for OOPS programming ).
-
Declare and write required functions / methods required.
-
Declare ONCE, the ports as input/Output/Analog/Communication and their direction of data flow, like from MCU (Output) , to MCU (Input) etc. The syntax may vary for each type of MCU. Some Variables and Functions, which are defined earlier, may be called for initial setup.
-
Write a continuous loop for actual requirement, which may have functions are called or input/Output/Analog/Communication ports are used to communicate with the external world of the MCU. |This is the main loop, which uses the required logic and sequence of operations to obtain required results.
The actual syntax and coding is depending on the programming language, but the logic is same for all the programming languages.