Here we are providing Embedded C programming tutorial for beginners. Initially you should learn embedded C programming basics to go further into the world Embedded development. It is a combined task of working with real hardware and writing a suitable source code using a software.
You have to deal with hardware like micro controllers, sensors, drivers, circuits and various input/output devices. You should be a big programmer before you starting with the hardware.
Create your own user feedback survey
The software source code which you will develop for your embedded devices will control the functionality of the application, thus your source code should be very much perfect in terms of logical algorithm and syntax.
Languages used in Embedded Programming
You can use assembly language or C language to develop embedded applications. Assembly language preferred for simple applications. But for complex application C language is the real solution.
Attention to those who are going to attend INTERVIEWS in the embedded field
Don’t miss your chance to become an embedded engineer in a high profile company. you should focus on the interview point of view. For that, we are recommending a video class success kit which not only focuses on the technical part of the embedded system. But also in the interview for the job in the embedded field. Click on the below link for more details.
EMBEDDED FIRMWARE DEVELOPMENT ONLINE INTERVIEW AND METHODOLOGY EXPERT VIDEO LEARNING SUCCESS KIT
This tutorial is a combination of text and graphics. This tutorial is designed in such a way that you can control its progress by reading repeatedly. You can view the graphics again and again.
Click here for Android App Development Tutorial classes
Here we start:
Let’s begin your journey to learn programming in C language and embedded applications. While developing this tutorial we have assumed that you are not totally new to the C language embedded. This tutorial will refresh your knowledge of C programming. It will teach you as to how to use your C programming for developing embedded applications.
What is a program?
A program is a set of instructions that are grouped together to accomplish a task or tasks. These set of instructions are written using languages like C, Assembly, C++, Java, ASP etc., You have to select the language according to the requirement. For example, if you want to develop a web page you will select HTML, ASP, Java to write set of instructions which will accomplish the task of making the web page. Similarly, if you want to make an embedded application, you will select assembly or C language to write your instructions. You will also find people using language named basic to develop embedded applications. Now I have a question for you.
Will the embedded device like micro controller understands the language is like assembly, C or basic?
Find its answer on the below image showing a set of instructions
The function of this set of instruction is to print a temperature value to the LCD screen used in an embedded application. This set of instruction is written using C language. Micro controllers or any embedded device cannot understand the set of instruction as it is. You have to convert it into a machine level language. The converted machine language will look like as shown inside the box. You have to use a compiler to convert instruction in the c language to the machine understandable language. In this way you require a compiler installed on your PC. Which will convert instructions written in C assembly or Basic languages to machine level language. You will find compiler and other software CD provided along with the product you have purchased. You no need to search it now. This tutorial will ask you to do so when we enter into writing source code.
C programming in Embedded System
C is a general-purpose, block structured, procedural computer programming language developed in 1972 by Dennis Richie at the Bell Telephone Laboratories for use with Unix operating system. It has since spread to many other platforms. We will use C language for Embedded Device Development platform.
Look at the below sample program written in
This program has no inputs and no outputs, this program is used here to simply explain you about the structure and layout of the C program this is a place where you can refer to ready-made stuff here in this example of file named io.h is located avr folder which is included in this program so that we need not to rewrite it again every time. Main is the starting point for any C program.
In other words, you should write the first line of source code inside the main function which you wish to execute as application starts. Next line of source code declares a variable named ‘a’ of data type int. further article will explain you about the data types and variables. Variable a has been assigned the value 10 using next line. Last line return value 0 to the operating system and program terminates.
Why we use semicolon in Embedded C programming ?
You may now further to understand these sections in detail semicolon indicates termination of the line curly brackets indicate scope of function or module you should follow these conventions while writing your program.
Data Types in Embedded C programming
Read three lines shown in the below image
Notice that the values and text highlighted by blue color carries some information. This information is called value in programming. These values are of different types.
Here we have used an integer value 10, a floating point value 93.4 and a character value Y thus in other words data type of these values are integer float and character respectively. In C programming you have to use various data types, some of the commonly used data types are described here.
Data types and is used to store integer values, for example 10, 234, 10009,45 . similarly Data type float is used to store floating-point values, for example 56.98, 68.00, 45.12 and Data type char used to to store single character values, for example n, b, v. See the below image having C program demonstrating the declaration and usage of data type.
By now you know how to declare a variable with a particular data type. Now the below image will show, how to use the values using statement.
Statements in Embedded C programming
A statement is a syntactic constructions that performs an action when a program is executed. Statement can alter the value of variables generate output or process input. Observe the below statements used to assign values and calculate the result.
Now I am winding up chapter 1, Click here for next chapter