• Home
  • Electrical
    • Power Electronics
  • Electronics
    • General Electronics
  • Embedded Systems
    • Arduino
    • ARM Cortex
    • Raspberry Pi
  • Robotics
  • Android
  • Others
    • Communications
    • Solar
    • Sensor based
  • Buy projects

Buy Electronics & Electrical Projects in India

Buy Electronic Kits & Electrical Projects in New Delhi, Hyderabad, Mumbai, Bangalore, Pune, Chennai, Ahmedabad and the rest of India.

  • New Delhi
  • Ahmedabad
  • Banglore
  • Chennai
  • Hyderabad
  • Mumbai
  • Pune

Steps To Build The Embedded C Programming Tutorial

October 28, 2014 by Tarun Agarwal 19 Comments

C Programming for Embedded Systems

C Programming for Embedded Systems

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:

  1. Comments
  2. Preprocessor directives
  3. Port configuration
  4. Global variables
  5. main() function or core function
  6. Variable declaration
  7. Program Logic
7 Steps to Build Embedded C Programming Tutorial

7 Steps to Build Embedded C Programming Tutorial

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.

Single Line Comment

Single Line Comment

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.

Multi Line Comment

Multi Line Comment

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
  • #define

P2Which 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.

Port Configuration

Port Configuration

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.

Main Fucntion

Main Fucntion

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.

Variable Declaration

Variable Declaration

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.

Program Logic

Program Logic

LED flash light Program

LED flash light Program

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.

Filed Under: Embedded Systems

About Tarun Agarwal

Tarun Agarwal is the Chief Customer Support Officer at Edgefx Technologies Pvt Ltd. He has 8 years of experience in Customer Support, Operations and Administration.

Comments

  1. Dipak Datta says

    June 17, 2015 at 5:55 pm

    Nice

    Reply
    • Tarun Agarwal says

      June 23, 2015 at 5:11 pm

      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)

      Reply
      • mitali jain says

        June 8, 2017 at 10:05 am

        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

        Reply
        • Tarun Agarwal says

          June 23, 2017 at 6:57 pm

          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

          Reply
  2. nani says

    July 30, 2015 at 11:45 am

    thankyou somuch….most help full

    Reply
  3. Kumaresan says

    April 2, 2016 at 10:29 am

    This is kumaresan I want for elevator design program and coding

    Reply
    • Tarun Agarwal says

      April 5, 2016 at 10:24 am

      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

      Reply
  4. sanket patil says

    June 3, 2016 at 1:28 am

    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.

    Reply
    • Tarun Agarwal says

      June 3, 2016 at 12:39 pm

      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

      Reply
  5. RRK says

    July 1, 2016 at 12:27 am

    Its very useful of basic embedded program outline. Thanks

    Reply
    • Tarun Agarwal says

      July 1, 2016 at 3:51 pm

      Hi RRK

      Thank You for Your appreciation

      Please visit our site again /www.edgefx.in/

      Reply
  6. Twinkle says

    July 8, 2016 at 11:45 am

    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?

    Reply
    • Tarun Agarwal says

      July 12, 2016 at 1:41 pm

      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/

      Reply
  7. Robbie says

    August 24, 2016 at 1:24 am

    This is a very nice to the point tutorials on C embedded systems

    Reply
    • Tarun Agarwal says

      September 28, 2016 at 7:13 pm

      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

      Reply
  8. Millicent says

    February 12, 2017 at 1:26 am

    You’ve really imerssped me with that answer!

    Reply
    • Tarun Agarwal says

      July 8, 2017 at 2:52 pm

      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

      Reply
  9. Ganesh says

    July 5, 2017 at 4:56 pm

    very useful article for beginners
    I am very proud to say thanks.

    Reply
    • Tarun Agarwal says

      July 5, 2017 at 6:29 pm

      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

      Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Search Here!

Join our Loyal Fan Base!




Recent Posts

  • Circuit Design of Pulse Amplitude Modulation
  • What Are The Advantages Of Using A Printed Circuit Board (PCB)
  • How Does A Transistor Work?
  • Home and Industrial Safety Using Fire and Gas Detection System Using GSM
  • Heart Attack Detection and Medical Attention Using Heart Beat Sensor

Download Ebook Worth 99$





Subscribe to our Youtube Channel

Like us on Facebook

Copyright © 2021 · Magazine Pro Theme on Genesis Framework · WordPress · Log in