Embedded Software is a key element in every embedded project that is used to run the micro-controller to perform the desired operations. In our daily life, we frequently use many electronic devices such as washing machines, refrigerators, mobile phones, security system, digital camera so on which will be controlled using embedded C program. If you press a button to take a photo with your digital camera, then micro-controller will perform the functions essential to capture the image and store it. This article presents basics of embedded systemsmicro-controller consists of many ports to construct the embedded C programming tutorial.
7-Steps to Building Embedded C Programming Tutorial
The embedded C programming is a collection of one or more functions. Every function is a collection of statements that are used to perform some specific tasks. The embedded C programming tutorial is similar to a C language is constructed with some basic elements such as character set, variables, constants, data types, keywords, variable declaration, statements, expressions etc. that are used to write the program easily. However, we are providing 7-steps with embedded C programming tutorial to easily write the program such as:
- Comments
- Preprocessor directives
- Port configuration
- Global variables
- main() function or core function
- Variable declaration
- Program Logic
Step1: Comments
The comments are important to the programming languages which describes function of program. Comments are non-executable code that is used to provide documentation to the program. The comments make an easy way to understand function of the program. There are two types of comments in embedded C programming tutorial such as:
- Single Line Comment
- Double Line Comment or Multi Line Comment
Single Line Comment
Generally single line comments are useful for the programming languages that can be used to explain a part of the code. The single line comments starts with double slash(//) which can be placed anywhere in the program. Single line comments are used to ignore complete line in a program.
Multi Line Comment
The multi line comments starts with single slash and an asterisk (/*) that can be used to explain a block of code. The multi line comments can be placed any where in the program. The multi line comments are used to ignore a complete block of code in a program.
Step2: Processor Directives
Preprocessor directives are lines integrated in the code of programs which can be followed by a hash sign (#). These lines are not programmed statements, but directives for the preprocessor. The preprocessor inspects the code before actual compilation of code begins and resolves all these directives before any code is actually generated by regular statements. Even though there are many different preprocessor directives, but two directives are very useful in the embedded C programming tutorial such as
- #include
Which can be called as a header file, containing C declarations and macro definitions to be shared between several source files. The #include directive is normally used to include standard library such as study. h that can be used to access I/O functions from the C library. The #define directive normally used to define the string of variables and to assign the values by performing the operations in a single instruction it can be defined as macros.
Step 3:Port Configuration
In every micro-controller consists of many ports, each port contains many pins which can be used to control the interfacing devices. These pins are declared in a program using keywords. The embedded C has consist standard and predefined keywords such as bit, sbit, SFR which can be used to declare the single pin and bits in a program.
sbit:
This data type is used in case of accessing a single bit of SFR register.
- Syntax: sbit variable name = SFR bit ;
- Ex: sbit a=P2^1;
- Explanation: If we assign p2.1 as ‘a’ variable, then we can use ‘a’ instead of p2.1 anywhere in the program, which reduces the complexity of the program.
Bit:
This data type is used for accessing the bit addressable memory of RAM (20h-2fh).
- Syntax: name of bit variable;
- Ex: bit c;
- Explanation: It is a bit sequence setting in a small data area that is used by a program to remember something.
SFR:
This data type is used to get the SFR register peripheral pots by another name. All the SFR registers must be declared with capital letters.
- Syntax: SFR variable name = SFR address of SFR register;
- Ex: SFR port0=0×80;
- Explanation: If we assign 0×80 as ‘port0’, then we can use 0×80 instead of port0 anywhere in the program, which reduces the complexity of the program.
SFR Register:
‘Special Function Register’ is represented as SFR register. Microcontroller 8051 has 256 bytes of RAM memory, which is separated into two parts: the first part of 128 bytes is used for data storage, and the other of 128 bytes is used to SFR registers. All peripheral devices like timers and counters, I/O ports are stored in the SFR register, and each element has a unique address.
Step4: Global Variables
The variable declared before the main function is called a global variable, that can be accessed on any function in the program. The life time of the global variable depends on the program until program comes to an end.
Step5: Main Function or Core Function
The main function is a core of every program execution, starts with main function only. Every program uses only one main function because if program contains more than one main function, then the compiler will get confused where to start the program execution.
Step6: Variable Declaration
The variable is a name that can be used to store the values. That variable must be declared before used in the program. The declaration of a variable specifies its name and data type. The storage representation of data is called data type. The embedded C programming uses four basic data types such as float, integer, character, etc. used to store the data in the memory. The size and range of data type defined based on compiler.
Step7: Program Logic
The plan of path is called a program logic that presents the theory behind and expected outcomes of a program’s actions. It describes the assumption or theory about why the program will work, showing the acknowledged effects of activities or resources.
LED flash light Program
Hope this article gives basic information to the beginners of embedded C programming. Good understanding of the Embedded C programming is most essential for designing embedded based projects. We encourage and welcome queries, suggestions and comments from our readers. Therefore, you can post your queries and feedback about this article in the comments section given below.
Nice
Hi Dipak Datta, Thank you for your appreciation. Also, please check the user friendly website http://www.edgefxkits.com for project ideas on all the latest technologies. You can download project abstract and seminar presentation also from the website. Please check the website for complete details in the kit content section: http://www.edgefxkits.com/kitdetails/ and go through the FAQ: http://www.edgefxkits.com/contact-us/#faq. Further if you have any queries you can call us on the toll free no. 1800 108 7475 for clarifications/personal counseling. Niveditha (Mobile: +91 9959178000)
hello sie my name is mitali jain! sir i want some basic 8051 programming regarding for bigginers! please sir please! my email address- jainmitu158@gmail.com
Hi mitali jain
I sincerely appreciate your kind response regarding my article. As per your requirement, I can suggest you that please go through our website link you can get exact information
https://www.edgefx.in/embedded-systems-basics-with-applications/
https://www.edgefx.in/8051-microcontroller-architecture/
https://www.edgefx.in/importance-of-embedded-systems-in-automobiles-with-applications/
And once again please visit our domestic website http://www.edgefxkits.com/
For more details please contact to Mr. Sathish on +91 8885507011 or you can email us on info@edgefxkits.in
thankyou somuch….most help full
This is kumaresan I want for elevator design program and coding
Hi Kumaresan,
Kindly Please Visit our website once: http://www.edgefxkits.com/
And also,the Code,Circuit diagram and other documentation can be shared with you once purchase the project.
Meanwhile ,we suggest you to please follow this links:
Model no 364: http://www.edgefxkits.com/bidirectional-rotation-of-single-phase-induction-motor-without-run-capacitor
Model no 240: http://www.edgefxkits.com/svpwm-space-vector-pulse-width-modulation
Model no 14: http://www.edgefxkits.com/bidirectional-rotation-of-an-induction-motor-with-a-remote-control-device
For more details please contact Mr.Tarun Aggarwal on +91-9959178000
hello sir, this is sanket i am an electronics engineer. i want to know that, do you also conduct embedded c programming courses? if yes then please provide me all the details regarding courses.
thank you.
Hi Sanket Patil,
Sorry,we don’t provide any kind of courses,but we develop the projects based on embedded C programming and also we can give you the 100% support regarding your technical queries in order to complete your project efficiently.
So,we suggest you to please visit our website once for more details regarding the projects: http://www.edgefxkits.com/
For more details please contact Mr.Tarun Agarwal on +91-9908208883
Its very useful of basic embedded program outline. Thanks
Hi RRK
Thank You for Your appreciation
Please visit our site again /www.edgefx.in/
Hello,
Dear Tarun,
I am embedded Trainer, at private firm, your article is very nice and also your embedded projects. I have also many ideas regarding embedded projects with IoT. I want to develop one best home automation product which is operated by Iot. can you help me regarding home automation?
at just now i am using PIR, DHT 11 and MQ 2 sensors for motion , fan speed control and LPG leakage respectively so which other sensors I have to use?
Hi Twinkle
Thanks for your appreciation
As per your requirement we suggest you to follow the below model links
Model no 728: http://www.edgefxkits.com/iot-based-load-control-over-standalone-wi-fi
model no 727: http://www.edgefxkits.com/iot-based-home-automation-over-the-cloud
model no 553: http://www.edgefxkits.com/iot-internet-of-things-based-remotely-managed-home-automation-under-wi-fi-through-android-apps-from-any-smart-phone
And once again please visit our web site for more projects http://www.edgefxkits.com/
This is a very nice to the point tutorials on C embedded systems
Hi Robbie
Thank you so much for your feed back
And once again please visit our website http://www.edgefxkits.com/
For more details please contact our customer support on +91 8885507011
You’ve really imerssped me with that answer!
Hi Millicent
Thank you very much for telling me how much you have enjoyed reading my column
And once again, please visit our domestic website http://www.edgefxkits.com/
For more details please contact Mr. Sathish on +91 8885507011 or you can email us at info@edgefxkits.in
very useful article for beginners
I am very proud to say thanks.
hello Ganesh
Thank you very much for telling me how much you have enjoyed reading my column
And once again please visit our domestic website http://www.edgefxkits.com/
For more details please contact to Mr. Sathish on +91 8885507011 or you can email us on info@edgefxkits.in