Академический Документы
Профессиональный Документы
Культура Документы
EMBEDDED C
By
Leena Aroza
25-NOV-10
1
TOPICS COVERED
C v/s Embedded C
Compile v/s Cross-Compiler
Programming in C
2
C
C’ is a well structured, well defined and standardized general purpose
programming language .
‘C’ offers a combination of the features of high level language and assembly and
helps in hardware access programming (system level programming) as well as
business package developments (Application developments like pay roll systems,
banking applications etc)
ANSI standard language.
Platform based Compiler.
EMBEDED C
Subset of conventional ‘C’ language
‘C’ instructions and with few target processor specific functions/
Instructions.
‘Cross-compiler’ is used for the conversion of programs written in Embedded C
to target processor/controller specific instructions.
eg:keil C51
The target processor/controller specific functions/instructions depends upon the
processor/controller
3
C
4
C Constants
Array
Integer Constants Pointer
Real Constants Structure
Character Constants Union
Enum
5
KEYWORDS
Keywords
do if static while
6
DATA TYPES
Data Type Size (Bits) Range Comments
Variables stored in the CPU Same as auto in scope and access. The
register register of processor. decision on whether a variable needs to be
Reduces access time of kept in CPU register of the processor
variable depends on the compiler
8
Arithmetic Operator
9
LOGICAL OPERATORS
Operator Operation Comments
Performs logical AND operation. Output is true
&& Logical AND (logic 1) if both operands (left to and right to of
&& operator) are true
10
Branching Instructions
//if statement //if else statement
if (expression) if else statement
{ if (expression)
statement1; {
statement2; if_statement1;
………….; if_statement2;
} …………….;
statement 3; }
…………..; else
{
else_statement1;
else_statement2;
……………….;
}
statement 3;
11
Conditional branching Instruction
//unconditional branching
Goto label
12
Looping Instruction
1) while LOOP
while (expression) do
{ {
body of while loop body of do loop
} }
while (expression);
13
Looping Instruction
2) For loop
//for loop
//exiting from loop
for(initialization;condition;increment)
break;
{
goto label
body of for loop
}
14
ARRAYS
Array is a collection of related elements (data types)
Array declaration
15
Array Initializations
//Initialization of array at //Selective initialization
the time of declaration
unsigned char arr[5];
unsigned char arr[5] = {5,
10, 20, 3, 2}; arr[0] = 5;
unsigned char arr[ ] = {5, arr[1] = 10;
arr[2] = 20;
10, 20, 3, 2};
arr[3] = 3;
arr[4] = 2;
16
Pointers
Pointer is a memory pointing based technique for variable access and
modification.
Egg:
char input; =34 //Declaring input as character variable
char *p; //Declaring a character pointer p (* denotes p is a pointer)
p = &input
0x34
input 0x7000
17
Equivalence of pointers and arrays
E.g. for the character array char arr[5], arr[ ] is equivalent to a
character pointer pointing to the first element of array arr
The array features like accessing and modifying members of an array
can be achieved using a pointer and pointer increment/decrement
operators
Arrays and pointer declarations are interchangeable when they are
used as parameters to functions
18
REFERECE
Shibu K.V-Introduction to Embedded System
Yashavant Kanetkar-Let us C
Balaguru Swamy-programming in C
19
?
20
THAK YOU
21