100% found this document useful (1 vote)
833 views6 pages

Embedded C Programming Language (Overview, Syntax, One Simple Program Like Addition of Two Numbers)

The document discusses the basics of embedded C programming, including what embedded C is, its features, and the steps to build an embedded C program, using addition of two numbers as an example program. Key aspects covered include preprocessor directives, global variables, the main function, variable declaration, and an algorithm for an addition program using ports on a PIC18F4520 microcontroller.

Uploaded by

Pritam Salunkhe
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
833 views6 pages

Embedded C Programming Language (Overview, Syntax, One Simple Program Like Addition of Two Numbers)

The document discusses the basics of embedded C programming, including what embedded C is, its features, and the steps to build an embedded C program, using addition of two numbers as an example program. Key aspects covered include preprocessor directives, global variables, the main function, variable declaration, and an algorithm for an addition program using ports on a PIC18F4520 microcontroller.

Uploaded by

Pritam Salunkhe
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Assignment No1

Title: Study of Embedded C programming language (Overview, syntax, One simple program like
addition of two numbers).
-------------------------------------------------------------------------------------------------------------------------------

Aim: Write embedded C program to do addition of two numbers.


Objective: To study Embedded C programming language

------------------------------------------------------------------------------------------------------------------------------------

Theory:

What is an Embedded C Program ?

● Earlier, many embedded applications were developed using assembly level programming.
However, they did not provide portability. This disadvantage was overcome by the advent of
various high-level languages like C, Pascal, and COBOL.
● However, it was the C language that got extensive acceptance for embedded systems, and it
continues to do so. The C code written is more reliable, scalable, and portable; and in fact,
much easier to understand.
● Embedded C Programming is the soul of the processor functioning inside each and
every embedded system we come across in our daily life, such as mobile phones, washing
machines, and digital cameras.
● Each processor is associated with embedded software. The first and foremost thing is the
embedded software that decides to function of the embedded system. Embedded C language
is most frequently used to program the microcontroller.

What is C Language?

● C language was developed by Dennis Ritchie in 1969. It is a collection of one or more


functions, and every function is a collection of statements performing a specific task.
● C language is a middle-level language as it supports high-level applications and low-level
applications. Before going into the details of embedded C programming,

The main features of the C language include the following.

● C language is software designed with different keywords, data types, variables, constants,
etc.
● Embedded C is a generic term given to a programming language written in C, which is
associated with a particular hardware architecture.
● Embedded C is an extension to the C language with some additional header files. These
header files may change from controller to controller.
● The microcontroller PIC18f4520  #include<p18f4520.h> is used.
What is an Embedded C Programming

● In every embedded system based projects, Embedded C programming plays a key role to
make the microcontroller run & perform the preferred actions.
● At present, we normally utilize several electronic devices like mobile phones, washing
machines, security systems, refrigerators, digital cameras, etc. The controlling of these
embedded devices can be done with the help of an embedded C program.
● For example in a digital camera, if we press a camera button to capture a photo then the
microcontroller will execute the required function to click the image as well as to store it.
● Embedded C programming builds with a set of functions where every function is a set of
statements that are utilized to execute some particular tasks.
● Both the embedded C and C languages are the same and implemented through some
fundamental elements like a variable, character set, keywords, data types, declaration of
variables, expressions, statements. All these elements play a key role while writing an
embedded C program.
● The embedded system designers must know about the hardware architecture to write
programs.
● These programs play a prominent role in monitoring and controlling external devices.
● They also directly operate and use the internal architecture of the microcontroller, such as
interrupt handling, timers, serial communication, and other available features.

Embedded System Programming

● An Embedded system program allows the hardware to check the inputs & control outputs
accordingly. In this procedure, the embedded program may have to control the internal
architecture of the processor directly like Timers, Interrupt Handling, I/O Ports, serial
communications interface, etc.
● So embedded system programming is very important to the processor. There are different
programming languages are available for embedded systems such as C, C++, assembly
language, JAVA, JAVA script, visual basic, etc. So this programming language plays a key
role while making an embedded system but choosing the language is very essential.

Steps to Build an Embedded C Program

There are different steps involved in designing an embedded c program like the following.
● Comments
● Directives of Processor
● Configuration of Port
● Global variables
● Core Function/Main Function
● Declaration of Variable
● The logic of the Program

Comments

● Comments are used in programming language to describe the program’s function.


● The code of the comments is non-executable
● It gives extra information about code.
● In embedded C, comments are available in two types namely single line and mainline comment.
● In an embedded C programming language, we can place comments in our code which helps the
reader to understand the code easily.
C=a+b; /* add two variables whose value is stored in another variable C*/

Single Line Comment

● These comments begin with a double slash (//) and it can be located anywhere within the
programming language.

Multi-Line Comment

● Multi-line comments begin with a single slash (/) & an asterisk (/*) in the programming
languages which explains a block of code. 

Directives of Processor

● The lines included within the program code are called preprocessor directives which can be
followed through a hash symbol (#).
● These lines are the preprocessor directives but not programmed statements.
● The code can be examined through a preprocessor before real code compilation starts &
resolves these directives before generating a code through regular statements.
There are several special preprocessor directives are available although two directives are
extremely helpful within the programming language like the following
#include
#include<p18f4520.h>
#define
● The #include directive is generally used to comprise standard libraries like study and. h is used to
allow I/O functions using the library of ‘C’. The #define directive usually used to describe the
series of variables & allocates the values by executing the process within a particular instruction
like macros.

Data Types & Time Delays in C for PIC18


Data Type32-bit Size in Bits Data Range/Usage

Unsigned char 8-bit 0 to 255

char 8-bit -128 to 127

Unsigned int 16-bit 0 to 65,535

int 16-bit -32,768 to 32,767

Unsigned short 16-bit 0 to 65,535

short 16-bit -32,768 to +32,767

Unsigned short long 24-bit 0 to 16,777,215

Short long 24-bit -8,388,608 to 8,388,607

Unsigned long 32-bit 0 to 4,294,967,295

long 32-bit -2,147,483,468 to +2,147,483,648

Global Variables
● When the variable is declared before the key function is known as the global variable. This
variable can be allowed on any function within the program. The global variable’s life span
mainly depends on the programming until it reaches an end.
#include<p18f4520.h>
Unsigned int a, c =10;
Main()
{
……………
…………..
}

Main Function
● The main function is a central part while executing any program and it begins with the main
function simply. Each program utilizes simply one major function since if the program includes
above one major function, next the compiler will be confused in begin the execution of the
program.
#include<reg51.h>
Main()
{
……………
…………..
}

Declaration of Variable

Main();
{
Unsigned int a,b,c;
}

The Structure of an Embedded C Program is shown below.

comments
preprocessor directives
global variables
main() function
{
local variables
statements
…………..
…………..
}
fun(1)
{
local variables
statements
…………..
…………..
}
Algorithm:
Step-1 include header file #include<p18f4520.h>
Step-2 in main function initialize TRISB=0; it makes portB as o/p port
Also initialize LATB=0;
Step-3 take two numbers by initializing i=0x04; j=0x03;
Step-4 Make sum and store in x=i+j;
Step-5 pass result on port.
PORTB=x;
PORTC=i;
PORTD=j;
stop
Conclusion: Hence from this assignment we learned Embedded C programming language.
References:

https://www.elprocus.com/basics-and-structure-of-embedded-c-program-with-examples-for-beginners/

You might also like