2. WHAT IS EMBEDDED C?
Whenever the conventional „C‟
language and its extensions are
used for programming
embedded systems, it is
referred to as “Embedded C”
programming.
3. C V/S EMBEDDED C
„C‟ is a well structured, Embedded „C‟ can be
well defined and considered as a subset
standardised general of conventional „C‟
purpose programming language.
language. A software program
called „Cross compiler‟
A platform specific is used for the
application , known as , conversion of programs
compiler is used for the written in Embedded
conversion of programs „C‟ to target
written in C to the processor/controller
target processor specific
specific binary files. instructions(machine
language).
4. COMPILER V/S CROSS COMPILER
Compiler is a Cross compilers are
software tool that software tools used in
cross platform
converts a source development applications.
code written in a high (In cross platform
level language on top development , the
of a particular compiler running on a
operating system particular target
processor/OS converts the
running on a specific source code to machine
target processor code for a target
architecture. processor whose
architecture and
instruction set is different
from the current
development environment
5. KEYWORDS
These are the reserved names used by the
„C ‟ language.
All keywords should be written in ‘lowercase’
letters.
Examples- int, char, double, float, void, while, for,
long etc.
ANSI „C‟ supports 32 such keywords.
6. IDENTIFIERS
Identifiers are user defined names and
labels.
Can contain letters of English alphabet(both
upper and lower case) and numbers.
Note: The starting character of an identifier
should be a letter and the only special
character allowed in identifier is
underscore(_).
7. DATATYPES
Datatype represents the type of data held by
a variable.
Datatype Size(Bits)
char 8
int 16
float 32
double 64
Note: The storage size may vary for data type
depending on the cross compiler in use for
embedded applications.
8. STORAGE CLASS
Keywords related to storage class provide
information on the scope i.e. visibility or
accessibility and lifetime i.e. existence of a
variable.
„C‟ supports four types of storage classes .
9. Storage Class Meaning Comments
auto Variables declared Scope and accessibility
inside a function. is restricted within the
Default storage class is function where the
auto. variable is declared.
No initialization.
register Variables stored in the Same as auto in scope
CPU register of and access.
processor. The decision on
Reduces access time of whether a variable
variable. needs to be kept in
CPU register of the
processor depends on
the compiler.
static Local variable with Retains the value
lifetime same as that throughout the
of the program. program.
By default initialises to
zero on variable
creation.
10. Storage Class Meaning Comments
static Accessibility depends
on where the
variable is declared.
extern Variables accessible Can be modified by
to all functions in a any function within a
file and all files in a file or across
multiple file multiple files.
program.
11. ARITHMETIC OPERATIONS
Operator Operation Comments
+ Addition Adds variables or
numbers
- Subtraction Subtracts variables or
numbers
* Multiplication Multiplies variables
or numbers
/ Division Divides variables or
numbers
% Remainder Finds the remainder
of a division
12. LOGICAL OPERATIONS
Fordecision making and program control
transfer.
Operator Operation Comments
&& Logical AND Performs logical
AND
operation.Output
is true(logic 1) if
both
operands(left to
right of &&
operator) are
true.
13. Operator Operation Comments
|| Logical OR Performs logical OR
operation.Output is
true(logic 1) if either
operand is true.
! Logical NOT Performs logical
negation.Operand is
complemented.
14. RELATIONAL OPEATIONS
Fordecision making and program control
transfer on the basis of comparison.
Operator Operation Comments
< Less than Checks whether the
operand on the left
side of „<‟ operator
is less than the
operand on the right
side.If yes return
logic one, else
return logic zero.
15. Operator Operations Comments
> Greater than Checks whether the
operand on the left
side of „>‟ operator is
greater than the
operand on the right
side.If yes return
logic one else return
logic zero.
<= Less than or equal to Checks whether the
operand on the left
side of „<=‟ operator
is less than or equal
to the operand on
the right side.If yes
return logic one, else
return logic zero.
16. Operator Operation Comments
== Checks equality Checks whether the
operand on the left
side of „==‟ operator
is equal to the
operand on the right
side.If yes return
logic one, else return
logic zero.
!= Checks non-equality Checks whether the
operand on the left
side of „!=‟ operator
is not equal to the
operand on the right
side.If yes return
logic one, else return
logic zero.
17. BRANCHING INSTRUCTIONS
CONDITIONAL UNCONDITIONAL
BRANCHING BRANCHING
Depends on These instructions
certain conditions divert program
and if the execution
conditions are unconditionally.
met, the program
execution is
diverted
accordingly.
18. Conditional Branching Explanation
instruction
//if statement Evaluates the expression first and
if it is true executes the
statements given within the { }
if(expression){ braces and continue execution of
Statement 1; statements following the closing
Statement 2; curly brace(}).Skips the
………………… ; execution of the statements
} within the curly brace{ } if
Statement 3; expression is false and continue
………………… ; execution of statements
following the closing curly brace
(}).
One way branching
19. Conditional Branching Explanation
Instruction
//if else statement Evaluates the expression first
if(expression){ and if it is true executes the
if_statement1; statements given within the { }
if_statement2; braces following if (expression)
………………….. ; and continue execution of the
} statements following the closing
else curly brace (}) of else block.
{ Executes the statements within
else_statement1; the curly brace { } following the
else_statement2; else, if the expression is false
………………………. ; and continue execution of
} statements following the closing
statement 3; curly brace(}) of else.
20. Conditional Branching Explanation
instruction
//switch case statement Tests the value of a given
expression against a list of case
switch(expression){ values for a matching
case value 1: condition.The expression and
break; case values should be
case value 2: integers.value1, value2, etc. are
break; integers.If a match found,
default: executes the statement following
break; the case and breaks from the
} switch.If no match found,
executes the default case.
Used for multiple branching.
21. Conditional branching Explanation
instruction
//conditional operator Used for assigning a value
//?exp1:exp2 depending on the
(expression) ?exp1:exp2 (expression).(expression) is
calculated first and if it is
E.g. greater than 0, evaluates exp1
if(x>y) and returns it as a result of
A=1; operation else evaluate exp2 and
else returns it as result.
A=0; The return value is assigned to
some variable.
Can be written using conditional It is a combination of if else with
operator as assignment statement.
A=(x>y)1:0 Used for two way branching.
22. Unconditional Branching Explanation
instruction
goto Goto is used as an unconditional
branching instruction.goto
transfers the program control
indicated by a label following
the goto statement.the label
inicated by goto statement can
be anywhere in the program
either before or after the goto
label instruction.
goto is generally used to come
out of deeply nested loops in
abnormal conditions or errors.
25. LOOPING INSTRUCTIONS
For executing a particular block of code
repeatedly till a condition is met or wait till an
event is fired.
Used to check the status of certain I/O ports,
registers, etc. and also for producing delays.
Certain devices allow write/read operations to
and from some registers of the device only when
the device is ready and the device ready is
normally indicated by a status register or by
setting/clearing certain bits of status
registers.Hence the program should keep on
reading the status register till the device ready
indication comes.
26. Looping instruction explanation
//while statement Entry controlled loop statement.
The expression is evaluated first
while (expression){ and if it is true the body of the
loop is entered and
body of while loop executed.Execution of „body of
while loop‟ is repeated till the
} expression becomes false.
27. //using while loop
char *status_reg=char(*)0x3000 ; /*Declares
memory mapped register*/
while(*status_reg!=0x01); /*Wait till
status_reg=0x01 i.e. device ready state*/
28. Looping instruction explanation
//do while loop The „body of the loop‟ is
executed at least once.At the
do{ end of each execution of the
„body of the loop‟, the while
body of do loop condition (expression) is
evaluated and if it is true the
} loop is repeated, else loop is
while(expression) terminated.
29. //using do while loop
char *status_reg=(char*)0x3000;
do{
// body of do loop
}while(*status_reg!=0x01); /* loop till
status_reg=0x01 */
30. Looping instruction explanation
//for loop Entry controlled loop.
Enters and executes „the body of
for(initialisation;test for loop‟ only if the test for the
condition;update variable){ condition is true. for loop
contains a loop control variable
body of for loop which may be initialised within
the initialisation part of the
} loop.
Multiple variables can be
initialised with „,‟ operator.
31. // using for loop
char *status_reg=(char*) 0x3000;
for(;(*status_reg!=0x01););