Professional Documents
Culture Documents
Embedded System: PART 1 (C Programming)
Embedded System: PART 1 (C Programming)
Press
here
#LEARN_IN DEPTH
#Be_professional_in
1 embedded_system
Embedded System
PART 1(C Programming)
C-Basics
ENG.KEROLES SHENOUDA
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
2
Why C, and not another language?
embedded_system
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
3
History
embedded_system
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
4
Compilation Process
embedded_system
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
5
C - Environment Setup
embedded_system
IDE + Compiler
1. Install MinGW GCC
Install Eclipse C/C++ Development Tool (CDT) Minimalist GNU for Windows
https://sourceforge.net/projects/mingw/file
Java Downloads for All Operating Systems s/
2. Cygwin GCC
https://www.cygwin.com/setup-x86.exe
Cygwin is:
a large collection of GNU and Open Source tools
which provide functionality similar to a Linux
distribution on Windows.
a DLL (cygwin1.dll) which provides substantial
POSIX API functionality.
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
12
Variable Name
embedded_system
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
13
Comments
embedded_system
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
Data Types
here
#LEARN_IN DEPTH
#Be_professional_in
14 embedded_system
structure union
enum typedef unsigned signed
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
Integer Values 15
#LEARN_IN DEPTH
#Be_professional_in
embedded_system
Unsigned Integer
size_in_bits
0 >>> (2 -1)
Signed Integer
long long 8 –9,223,372,036,854,775,808 to (size_in_bits-1)
9,223,372,036,854,775,807 (size_in_bits-1)
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
16
For example “char”
embedded_system
Another example if the Signed char value uses one byte (8 bits)
to hold the numeric
value. If Tow‟s Complement method is used to represent the
negative values:
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
17
For example “char”
embedded_system
For example if the Unsigned short value uses one byte (16 bits)
to hold the numeric value:
Another example if the Signed Integer value uses four byte (32 bits) to hold
the numeric
value. If Tow‟s Complement method is used to represent the negative values:
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
18
Note
embedded_system
int, this data type called the machine dependent data type, which means its
size and range
vary from a machine type to another machine type (EX: in 8 bit computers int
is 1 byte, in
16 bit computers int is 2 bytes, in 32 bit computers int is 4 bytes, in 64 bit
computers int is 8
bytes).
Know that (32 Bits computers) means the principle data unit size in those
computers are 32
bit, which mean the computer is designed and optimized to process 32 bit
values
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
19
Floating-Point Types
embedded_system
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
20
2′s Complement
embedded_system
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
21
bool is a data type ?
embedded_system
#include <stdio.h>
#include <stdbool.h>
int main()
{
bool a = true;
return 0;
}
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
22
bool
embedded_system
Press
here
#LEARN_IN DEPTH
#Be_professional_in
23
quiz: what is the output
embedded_system
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
24
quiz: what is the output
embedded_system
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
25
Integer and Float Conversions
embedded_system
An operation between an integer and real always yields a real result. In this
operation the integer is first promoted to a real and then the operation is
performed. Hence the result is real.
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
26
Type Conversion in Assignments
embedded_system
Here in the first assignment statement though the expression’s value is a float
(3.5) it cannot be stored in i since it is an int.
In such a case the float is demoted to an int and then its value is stored. Hence
what gets stored in i is 3.
Exactly opposite happens in the next statement. Here, 30 is promoted to
30.000000 and then stored in b, since b being a float variable cannot hold
anything except a float value.
int i ;
float b ;
i = 3.5 ;
b = 30 ;
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
27
Type Conversion in Assignments
embedded_system
in the assignment statement some operands are ints whereas others are
floats. As we know, during evaluation of the expression
the ints would be promoted to floats and the result of the expression would
be a float. But when this float value is assigned to s it is again demoted to an
int and then stored in s.
float a, b, c ;
int s ;
s = a * b * c / 100 + 32 / 4 - 3 * 1.1 ;
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#Be_professional_in
28 embedded_system
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#Be_professional_in
29 embedded_system
In the first statement, since both 2 and 9 are integers, the result is
an integer, i.e. 0. This 0 is then assigned to k. In the second
statement 9 is promoted to 9.0 and then the division is performed.
Division yields 0.222222. However, this cannot be stored in k, k
being an int. Hence it gets demoted to 0 and then stored in k.
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
30
Hierarchy of Operations
embedded_system
While executing an arithmetic statement, which has two or more Example 1.1: Determine the hierarchy of operations and
evaluate
operators, we may have some problems as to how exactly does it the following expression:
get executed. For example, does the expression 2 * x - 3 * y i=2*3/4+4/4+8-2+5/8
correspond to (2x)-(3y) or to 2(x-3y)? Similarly, does A / B * C
correspond to A / (B * C) or to (A / B) * C? To answer these i = 6 / 4 + 4 / 4 + 8 - 2 + 5 / 8 operation: *
questions satisfactorily one has to understand the ‘hierarchy’ of i = 1 + 4 / 4 + 8 - 2 + 5 / 8 operation: /
operations. i = 1 + 1+ 8 - 2 + 5 / 8 operation: /
i = 1 + 1 + 8 - 2 + 0 operation: /
i = 2 + 8 - 2 + 0 operation: +
i = 10 - 2 + 0 operation: +
i = 8 + 0 operation : -
i = 8 operation: +
https://www.facebook.com/groups/embedded.system.KS/
Follow us
#Be_professional_in
31 embedded_system
Two commonly used functions for I/O (Input/Output) are printf() and scanf().
The scanf() function reads formatted input from standard input (keyboard)
whereas the printf() function sends formatted output to the standard output
(screen).
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
32
Input Output
embedded_system
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
#Be_professional_in
33 embedded_system
with scanf()
Eclipse's terminal emulator
might be different and do
more buffering. Try calling
fflush(stdout); between the
printout and the call to
scanf().
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
34
C Floats Input/Output
embedded_system
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
35
int printf( const char* format, ... );
embedded_system
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
36
Quiz
embedded_system
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
37
Quiz
embedded_system
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
38 embedded_system
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
39 embedded_system
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Printf
Press
here
#LEARN_IN DEPTH
#Be_professional_in
40 embedded_system
Tricks
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
41
Solution
embedded_system
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
42 embedded_system
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
43
Mathematical and Logical
embedded_system
Expressions
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
44
Mathematical and Logical
embedded_system
Expressions
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
45
Mathematical and Logical
embedded_system
Expressions
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
46
Coding Convention
embedded_system
Coding convention is a set of rules that enhance the readability and the
understandability of
the code. At the end of each chapter a list of standard and related coding
convention is
mentioned.
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
47
Coding Convention
embedded_system
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
48
Generally following roles must be obeyed to
embedded_system
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
C Fundamentals 49 embedded_system
Statements
Control Statements
if
switch
Comments
goto Operators
for loop Keywords Identifiers
Relational operators
while loop
Logical operators
do-while loop
break
Assignment operators Constants Data Types
continue Arithmetic operators 1.Integer constants
Nested Loop 2.Floating-point User Defined
null statement constants
expression statement 3.Character constants Primitive/Basic Types
4.String constants
Conditional operators
enum typedef Real Values Integer Values
min = (x < y) ? x : y;
Identifier = (test expression)? Expression1: Expression2 ;
Derived unsigned signe
Bitwise Operators d
Comma operators
Press
here
#LEARN_IN DEPTH
Identifiers
#Be_professional_in
50 embedded_system
Identifiers are the names that are given to various program elements
such as variables, symbolic constants and functions.
Identifier can be freely named, the following restrictions.
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
51
Identifiers
embedded_system
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
52
Keywords
embedded_system
Keywords are standard identifiers that have standard predefined meaning in C. Keywords
are all lowercase, since uppercase and lowercase characters are not equivalent it's possible
to utilize an uppercase keyword as an identifier but it's not a good programming practice.
1. Keywords can be used only for their intended purpose.
2. Keywords can't be used as programmer defined identifier.
3. The keywords can't be used as names for variables.
The standard keywords are given below:
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
53
Integer Literals
embedded_system
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
54
Floating-point Literals
embedded_system
A floating-point literal has an integer part, a decimal point, a fractional part, and
an exponent part. You can represent floating point literals either in decimal form
or exponential form.
While representing decimal form, you must include the decimal point, the
exponent, or both; and while representing exponential form, you must include
the integer part, the fractional part, or both. The signed exponent is introduced
by e or E.
Here are some examples of floating-point literals:
https://www.facebook.com/groups/embedded.system.KS/