Programming I
Agenda
o Why we need Software
o Choosing the appropriate programming language
o “ C “ Features
o Desktop C Vs Embedded C
o Structure of C program
o Hello, World!
o Constants & Variables
o Operators
o Control flow
Why we need Software in ES
Embedded Systems is a mixture of hardware and software.
Choosing the appropriate programming language
Programming Language Ranking
C Features
C language is an old but popular programming language , because of the
following features :
o Easier and less time consuming
o Easier to modify and update
o Codes available in function libraries
o Portable
o Efficient use of pointers
Embedded C Vs Desktop C
Embedded C is a set of extensions for the ordinary C , Developed to be used
with Embedded Systems. It has uses most of C syntax but differ from Desktop C
at the following :
o Writing low level code
o Writing in-line assembly code
Structure of C program
“Hello, World!” Program
Constants
Constant :
Constants are the terms that can't be changed during the execution of a
program. For example: 99 , 65.5 … C has 3 types of Constants.
Constants types :
o Integer Constant : like 10 , 68
o Float-point Constant : 2.9 , 3.0
o Character Constant : ‘A’ , ‘ r’ , ‘255’
Constants : Example
Variables
Variable :
Variables are memory location in computer's memory to store data. And
each location of memory has its special name.
Rules for variable names :
o Variable name can be composed of letters , digits and underscore '_' only.
o The first letter of a variable should be either a letter or an underscore.
o Note :
In C programming, you have to declare variable before using it in the
program.
Data types in C
Type Size Min Max
Char 1 Byte 0 255
Short 2 Byte 0 65,535
Int 2 Or 4 Byte 0 4,294,967,295
Long 4 Byte 0 4,294,967,295
Float 4 Byte 1.2E-38 3.4E+38
Double 8 Byte 2.3E-308 1.7E+308
Variables : Example
Operators : Arithmetic
Operator Description
+ Adds two operands
- Subtracts second operand from the first
* Multiplies both operands
/ Divides numerator by de-numerator
% Modulus Operator and remainder of after an integer
division
++ Increments operator increases integer value by one
-- Decrements operator decreases integer value by one
Operators : Relational
Operator Description
== Checks if the values of two operands are equal or not, if yes then
condition becomes true
!= Checks if the values of two operands are equal or not, if values are not
equal then condition becomes true
> Checks if the value of left operand is greater than the value of right
operand, if yes then condition becomes true
< Checks if the value of left operand is less than the value of right
operand, if yes then condition becomes true
>= Checks if the value of left operand is greater than or equal to the value
of right operand, if yes then condition becomes true
<= Checks if the value of left operand is less than or equal to the value of
right operand, if yes then condition becomes true
Operators : Logical
Operator Description
&& Called Logical AND operator. If both the operands are non-
zero, then condition becomes true
|| Called Logical OR Operator. If any of the two operands is
non-zero, then condition becomes true
! Called Logical NOT Operator. Use to reverses the logical
state of its operand. If a condition is true then Logical NOT
operator will make false
Operators : Bitwise
Operator Description
& Binary AND Operator copies a bit to the result if it exists in both
operands
| Binary OR Operator copies a bit if it exists in either operand
^ Binary XOR Operator copies the bit if it is set in one operand but not
both
~ Binary Ones Complement Operator is unary and has the effect of
'flipping' bits
<< Binary Left Shift Operator. The left operands value is moved left by the
number of bits specified by the right operand
>> Binary Right Shift Operator. The left operands value is moved right by
the number of bits specified by the right operand
Control Flow
C language has many ways to change the flow of the program for example
o If Statement
o If .. Else statement
o Switch
Q & A

C language

  • 1.
  • 2.
    Agenda o Why weneed Software o Choosing the appropriate programming language o “ C “ Features o Desktop C Vs Embedded C o Structure of C program o Hello, World! o Constants & Variables o Operators o Control flow
  • 3.
    Why we needSoftware in ES Embedded Systems is a mixture of hardware and software.
  • 4.
    Choosing the appropriateprogramming language
  • 5.
  • 6.
    C Features C languageis an old but popular programming language , because of the following features : o Easier and less time consuming o Easier to modify and update o Codes available in function libraries o Portable o Efficient use of pointers
  • 7.
    Embedded C VsDesktop C Embedded C is a set of extensions for the ordinary C , Developed to be used with Embedded Systems. It has uses most of C syntax but differ from Desktop C at the following : o Writing low level code o Writing in-line assembly code
  • 8.
  • 9.
  • 10.
    Constants Constant : Constants arethe terms that can't be changed during the execution of a program. For example: 99 , 65.5 … C has 3 types of Constants. Constants types : o Integer Constant : like 10 , 68 o Float-point Constant : 2.9 , 3.0 o Character Constant : ‘A’ , ‘ r’ , ‘255’
  • 11.
  • 12.
    Variables Variable : Variables arememory location in computer's memory to store data. And each location of memory has its special name. Rules for variable names : o Variable name can be composed of letters , digits and underscore '_' only. o The first letter of a variable should be either a letter or an underscore. o Note : In C programming, you have to declare variable before using it in the program.
  • 13.
    Data types inC Type Size Min Max Char 1 Byte 0 255 Short 2 Byte 0 65,535 Int 2 Or 4 Byte 0 4,294,967,295 Long 4 Byte 0 4,294,967,295 Float 4 Byte 1.2E-38 3.4E+38 Double 8 Byte 2.3E-308 1.7E+308
  • 14.
  • 15.
    Operators : Arithmetic OperatorDescription + Adds two operands - Subtracts second operand from the first * Multiplies both operands / Divides numerator by de-numerator % Modulus Operator and remainder of after an integer division ++ Increments operator increases integer value by one -- Decrements operator decreases integer value by one
  • 16.
    Operators : Relational OperatorDescription == Checks if the values of two operands are equal or not, if yes then condition becomes true != Checks if the values of two operands are equal or not, if values are not equal then condition becomes true > Checks if the value of left operand is greater than the value of right operand, if yes then condition becomes true < Checks if the value of left operand is less than the value of right operand, if yes then condition becomes true >= Checks if the value of left operand is greater than or equal to the value of right operand, if yes then condition becomes true <= Checks if the value of left operand is less than or equal to the value of right operand, if yes then condition becomes true
  • 17.
    Operators : Logical OperatorDescription && Called Logical AND operator. If both the operands are non- zero, then condition becomes true || Called Logical OR Operator. If any of the two operands is non-zero, then condition becomes true ! Called Logical NOT Operator. Use to reverses the logical state of its operand. If a condition is true then Logical NOT operator will make false
  • 18.
    Operators : Bitwise OperatorDescription & Binary AND Operator copies a bit to the result if it exists in both operands | Binary OR Operator copies a bit if it exists in either operand ^ Binary XOR Operator copies the bit if it is set in one operand but not both ~ Binary Ones Complement Operator is unary and has the effect of 'flipping' bits << Binary Left Shift Operator. The left operands value is moved left by the number of bits specified by the right operand >> Binary Right Shift Operator. The left operands value is moved right by the number of bits specified by the right operand
  • 19.
    Control Flow C languagehas many ways to change the flow of the program for example o If Statement o If .. Else statement o Switch
  • 20.