Upgrade to Pro — share decks privately, control downloads, hide ads and more …

1.EmbeddedProcess_EmbeddedCoding.pdf

Boaz
May 28, 2020

 1.EmbeddedProcess_EmbeddedCoding.pdf

Boaz

May 28, 2020
Tweet

Other Decks in Education

Transcript

  1. COMMON FOR B.SC/M.SC - EC/CS/IT/BCA/PHYSICS AND BE/ME – ECE/EEE/IT/CSE/MECH/MECHATRONICS/ E&I

    Online Course L.Boaz BE, M.Tech [email protected] Assistant Professor /B.Sc Electronics and Communication JPCAS 1
  2. Agenda  Embedded System Data representation HEX file  Let

    us ‘C’ Data types in C Decision Control Instruction Loop Control Instruction  KEIL IDE (Practical) using P89v51RD2 Microcontroller 2 Online Course | Embedded C Programming for c51 Microcontroller | L.Boaz | JPCAS | [email protected]
  3. EMBEDDED SYSTEM  Combination of Hardware and Software  Designed

    for a specific task  Dedicated system  Fixed into the chip of Software code  Inject the code by Electrical Pulses  Hardware – To store the code  Software – To control the HW 3 Online Course | Embedded C Programming for c51 Microcontroller | L.Boaz | JPCAS | [email protected]
  4. What is Computer? All the peripherals are connected from external.

    Rapid movement of code and data from external addresses Separate buses : Address, Data and Control. Can be used for any number of program execution such as word process, gaming, developing code. 4 Online Course | Embedded C Programming for c51 Microcontroller | L.Boaz | JPCAS | [email protected]
  5. INTERNAL ORGANISATION OF CPU 1. Flags 2. ALU 3. Program

    Counter 4. Instruction Decode 5. Buses 6. Registers 5 Online Course | Embedded C Programming for c51 Microcontroller | L.Boaz | JPCAS | [email protected]
  6. Internal Organization of CPU 1. CPU has number of Registers

    to store information temporarily 2. CPU also has what is called the ALU (Arithmetic Logical Unit) A. Arithmetic – Addition, Subtraction, Multiplication and Division B. Logical – AND (&), OR(|), NOT(~) 3. Every CPU has program Counter which is to point to the address of next instruction to be executed. 4. The function of Instruction decoder is to interpret the instruction fetched into the CPU. Just like a dictionary storing the meaning of each instruction and what steps the CPU should take upon receiving a given Instruction 6 Online Course | Embedded C Programming for c51 Microcontroller | L.Boaz | JPCAS | [email protected]
  7. GENERAL PURPOSE MICROPROCESSOR 1. Similar to a typical personal Computer

    2. All the ALU and multiple programs can be performed 3. All the peripherals are connected from external 4. The code is stored on external Flash or ROM (Raspberry Pi) 5. It need more circuitry components 6. The Instruction is fetched from the flash and moves into the RAM to process by the CPU 7 Online Course | Embedded C Programming for c51 Microcontroller | L.Boaz | JPCAS | [email protected]
  8. MICROCONTROLLER 1. All the peripherals are connected within a single

    chip 2. Only one application software is burned inside the flash or ROM memory 3. Rapid movement of code and data from Internal memory 4. Designed for a dedicated task only – (CD ROM driver, mouse, Hard Disk Controller) 5. Small in size 8 Online Course | Embedded C Programming for c51 Microcontroller | L.Boaz | JPCAS | [email protected]
  9. DESIGN AN EMBEDDED SYSTEM Computer IDE Microcontroller ROM HEX To

    design an embedded system we need an IDE which is installed in a PC, Laptop or a mobile phone then a microcontroller with sufficient flash or ROM memory to store the hex or binary file and a cable to transfer the code from the computer to the microcontroller. 9 Online Course | Embedded C Programming for c51 Microcontroller | L.Boaz | JPCAS | [email protected]
  10. Embedded Process •Developing code •Compile – Translate to machine code

    •Debug – Error check Code Level •Linker – Combines all codes together and create a single executable file. •Compiler – Converts into final HEX Code Object Code •Through Code burner Software the HEX file is stored into the flash memory of the Microcontroller. •ISP or IAP Support Code Burning 10 Online Course | Embedded C Programming for c51 Microcontroller | L.Boaz | JPCAS | [email protected]
  11. IDE – INTEGRATED DEVELOPMENT ENVIRONMENT  An integrated development environment

    (IDE) is a software suite that consolidates basic tools required to write and test software.  An IDE typically contains a code editor, a compiler or interpreter, and a debugger, accessed through a single graphical user interface (GUI).  The user writes and edits source code in the code editor.  The compiler translates the source code into a readable language that is executable for a computer.  The debugger tests the software to solve any issues or bugs.  An IDE can also contain features such as programmable editors, object and data modeling, unit testing, a source code library and build automation tools.  An IDE's toolbar looks much like a word processor's toolbar. The toolbar facilitates color-based organization, source-code formatting, error diagnostics and reporting, and intelligent code completion. 11 Online Course | Embedded C Programming for c51 Microcontroller | L.Boaz | JPCAS | [email protected]
  12. HEX FILE  It is a file format designed to

    standardize the loading of Executable machine codes into a ROM chip.  It is a binary file or machine code  It is stored in Microcontroller’s Flash or ROM memory by code burner 12 Online Course | Embedded C Programming for c51 Microcontroller | L.Boaz | JPCAS | [email protected]
  13. ANALYZING INTEL HEX FILE  “ : ” Each line

    starts with a colon  CC, the Count BYTE  AAAA is for Address. 16 bit Address  TT is for Type.  DD – Information or code byte  SS – Single Byte (Check Sum)  All the data are displayed as Hexadecimal data in HEX file while you open upon your computer. For example if you see the numbers 0-9 it is not decimal but hexadecimal. So read by two numbers or a byte. 13 Online Course | Embedded C Programming for c51 Microcontroller | L.Boaz | JPCAS | [email protected]
  14. READING HEX FILE : 0C (12 Byte) 00C7 00 787F…..AB

    DB Start Line No of Data Bytes 02 00 C7 Program Data Address Check Sum Type : 03 0000 00 0200C7 34 : 10 (16 Byte) 00AB 00 7589…..99 5E 14 Online Course | Embedded C Programming for c51 Microcontroller | L.Boaz | JPCAS | [email protected]
  15. DATA REPRESENTATION Data or Datum No of Bits Bit 1

    Nibble 4 Byte or 2 Nibble 8 Word or 2 Byte 16 Data or Datum No of Bits Binary 01011b Decimal 4 HEX 0xF4 15 Online Course | Embedded C Programming for c51 Microcontroller | L.Boaz | JPCAS | [email protected]
  16. C & Embedded C 16 Online Course | Embedded C

    Programming for c51 Microcontroller | L.Boaz | JPCAS | [email protected]
  17. WHY WE USE C INSTEAD OF ASSEMBLY LANGUAGE?  Less

    time consuming to develop the code  Easier to modify and update  Have function Libraries  C code is portable to other microcontroller with little or no modification.  Data types can save large amount of space  Can be readable 17 Online Course | Embedded C Programming for c51 Microcontroller | L.Boaz | JPCAS | [email protected]
  18. DATA TYPES IN EMBEDDED C  Used to create smaller

    HEX files  Data types or Keywords  32 Keywords available in C break case char continue default do else float for goto if int return short signed unsigned void while 18 Online Course | Embedded C Programming for c51 Microcontroller | L.Boaz | JPCAS | [email protected]
  19. unsigned char  8051 is an 8 bit Microcontroller 

    unsigned char is an 8 bit data type value from 0-255 or 00 to FF  Use this instead of int or signed char to reduce the memory of hex file  Uses Counter value 19 Online Course | Embedded C Programming for c51 Microcontroller | L.Boaz | JPCAS | [email protected]
  20. signed char  8 bit data type D7-D0  D7

    is to represent – or + value  D6-D7 -127 to +127 (7 bits for the magnitude and 8th bit is sign) Uses: To represent the temperature value 20 Online Course | Embedded C Programming for c51 Microcontroller | L.Boaz | JPCAS | [email protected]
  21. unsigned int  16 bit data type  0 to

    65535 or 0000 to FFFFH  Used to define 16 bit variable such as memory address  Also used to set counter values  It took two bytes of RAM D15 D14 D13 D12 D11 D10 D9 D8 D7 D6 D5 D4 D3 D2 D1 D0 Byte 2 Byte 1 Magnitude 21 Online Course | Embedded C Programming for c51 Microcontroller | L.Boaz | JPCAS | [email protected]
  22. signed int  16 bit data type  To represent

    the –ve or +ve values  15 bits for magnitude (D14-D0) and 16th bit (D15)for sign  -32768 to +32768 D15 Sign D14 D13 D12 D11 D10 D9 D8 D7 D6 D5 D4 D3 D2 D1 D0 1= - 0 = + Magnitude 1 1 1 1 0 1 0 1 1 0 1 0 1 0 0 0 - 7 5 A 8 0 1 1 1 0 1 0 1 1 0 1 0 1 0 0 0 + 7 5 A 8 22 Online Course | Embedded C Programming for c51 Microcontroller | L.Boaz | JPCAS | [email protected]
  23. sbit  It is designed to access single bit addressable

    registers.  It allows access to the single bits of the sfr (carry, sign, zero, auxiliary carry)  In embedded C it is used to access a single pin from a whole port sbit sensor1 = P2^0 It allows access the pin no 1 from the PORT2 of the microcontroller. 23 Online Course | Embedded C Programming for c51 Microcontroller | L.Boaz | JPCAS | [email protected]
  24. Operators - Comparison Operator Description Usage Example (x=5, y=8) ==

    Equal to expr1 == expr2 (x == y) → false != Not Equal to expr1 != expr2 (x != y) → true > Greater than expr1 > expr2 (x > y) → false >= Greater than or equal to expr1 >= expr2 (x >= 5) → true < Less than expr1 < expr2 (y < 8) → false <= Less than or equal to expr1 >= expr2 (y <= 8) → true 24 Online Course | Embedded C Programming for c51 Microcontroller | L.Boaz | JPCAS | [email protected]
  25. Operators - Logical Operator Description Usage && Logical AND expr1

    && expr2 || Logical OR expr1 || expr2 ! Logical NOT !expr ^ Logical XOR expr1 ^ expr2 25 Online Course | Embedded C Programming for c51 Microcontroller | L.Boaz | JPCAS | [email protected]
  26. Flow Control There are three basic flow control constructs –

    1. sequential, 2. conditional (or decision), 3. loop (or iteration), 26 Online Course | Embedded C Programming for c51 Microcontroller | L.Boaz | JPCAS | [email protected]
  27. Flow Control – Sequential  A program is a sequence

    of instructions.  Sequential flow is the most common and straight- forward, where programming statements are executed in the order that they are written - from top to bottom in a sequential manner. 27 Online Course | Embedded C Programming for c51 Microcontroller | L.Boaz | JPCAS | [email protected]
  28. Flow Control - Conditional There are a few types of

    conditionals, 1. if-then, 2. if-then-else, 3. nested-if (if-elseif-elseif-...-else), 4. switch-case, 5. conditional expression. 28 Online Course | Embedded C Programming for c51 Microcontroller | L.Boaz | JPCAS | [email protected]
  29. if statement if (T >= 40) { printf(“Hot in room");

    printf(“Plant Tree"); } // if-then if ( booleanExpression ) { true-block ; }  The if statement is also known as a decision making statement, as it makes a decision on the basis of a given condition or expression.  The block of code inside the if statement is executed is the condition evaluates to true.  However, the code inside the curly braces is skipped if the condition evaluates to false, and the code after the if statement is executed. 29 Online Course | Embedded C Programming for c51 Microcontroller | L.Boaz | JPCAS | [email protected]
  30. If – else // if-then-else if ( booleanExpression ) {

    true-block ; } else { false-block ; } if (T >= 25) { printf(“Room Temperature is Hot"); printf("Keep it Cool\n"); } else { printf(“Room Temperature is normal\n");}  In an if...else statement, if the code in the parenthesis of the if statement is true, the code inside its brackets is executed.  But if the statement inside the parenthesis is false, all the code within the else statement's brackets is executed instead. 30 Online Course | Embedded C Programming for c51 Microcontroller | L.Boaz | JPCAS | [email protected]
  31. Nested Else-if statements // nested-if if ( booleanExpr-1 ) {

    block-1 ; } else if ( booleanExpr-2 ) { block-2 ; } else if ( booleanExpr-3 ) { block-3 ; } else if ( booleanExpr-4 ) { ...... } else { elseBlock ; } if (T >= 80) { printf(“Your room is under fire\n"); } else if (T >= 40) { printf(“Check your Electricity\n"); } else if (T >= 30) { printf(“Fan is ON and AC is OFF\n"); } else if (T >= 20) { printf(“AC and Fan is running\n"); } else { printf(“Cool and Breeze\n"); }  The if...else statement executes two different codes depending upon whether the test expression is true or false. Sometimes, a choice has to be made from more than 2 possibilities.  The nested if...else statement allows you to check for multiple test expressions and execute different codes for more than two conditions. 31 Online Course | Embedded C Programming for c51 Microcontroller | L.Boaz | JPCAS | [email protected]
  32. Switch case  "switch-case" is an alternative to the "nested-if".

     In a switch-case statement, a break statement is needed for each of the cases.  If break is missing, execution will flow through the following case.  You can use either an int or char variable as the case-selector. 32 Online Course | Embedded C Programming for c51 Microcontroller | L.Boaz | JPCAS | [email protected]
  33. Switch Case  It allows us to make a decision

    from the number of choices is called as switch or switch-case-default.  Break statement when used in a switch takes the control outside the switch.  A float expression cannot be tested using switch.  Faster than if statement switch(integer expression) { case constant 1: do this; break; case constant 2: do this; break; case constant 3: do this; break; default: do this; } 33 Online Course | Embedded C Programming for c51 Microcontroller | L.Boaz | JPCAS | [email protected]
  34. The loop control structure  while  for  do

    while  break  continue This involves repeating some portion of the program either a specified number of times or until a particular condition is being satisfied. 34 Online Course | Embedded C Programming for c51 Microcontroller | L.Boaz | JPCAS | [email protected]
  35. while (infinite)  Want to do something a fix number

    of times  Tests the condition before executing any of the statements within the while loop. General form of while Intitialise loop counter; while(test loop counter using a condition) { Do this; And this; Increment loop counter; } 35 Online Course | Embedded C Programming for c51 Microcontroller | L.Boaz | JPCAS | [email protected]
  36. do - while do { this; and this; }while(this condition

    is true);  Tests the condition after having executed the statements within the loop.  It would execute its statements at least once, even if the condition fails for the first time. 36 Online Course | Embedded C Programming for c51 Microcontroller | L.Boaz | JPCAS | [email protected]
  37. for (Finite)  It allows us to specify three things

    about a loop in a single line. For(initialise counter; test counter; increment or decrement counter ) { do this; and this; } 37 Online Course | Embedded C Programming for c51 Microcontroller | L.Boaz | JPCAS | [email protected]
  38. break (jump to first statement)  When it is encountered

    inside any loop, control automatically passes to the first statement after the loop.  Break statement takes the control out of the case.  Break is usually associated with an if statement. 38 Online Course | Embedded C Programming for c51 Microcontroller | L.Boaz | JPCAS | [email protected]
  39. Continue (to the beginning)  When it is encountered inside

    any loop, control automatically passes to the beginning of the loop.  It is usually associated with an if statement. 39 Online Course | Embedded C Programming for c51 Microcontroller | L.Boaz | JPCAS | [email protected]
  40. goto (to take the control where you want)  It

    is used to transfer the normal flow of a program to the specified label in the program. { ……… go to label; ……… label: statement; } 40 Online Course | Embedded C Programming for c51 Microcontroller | L.Boaz | JPCAS | [email protected]
  41. Array – To create Data Log  An array is

    a list of elements of the same type, identified by a pair of square brackets [ ]. To use an array, you need to declare the array with 3 things: a name, a type and a dimension (or size, or length).  To create an array, you need to known the length (or size) of the array in advance, and allocate accordingly. Once an array is created, its length is fixed and cannot be changed. At times, it is hard to ascertain the length of an array  The syntax is: type arrayName[arraylength];  To store sensor values  To create buffer for ADC 41 Online Course | Embedded C Programming for c51 Microcontroller | L.Boaz | JPCAS | [email protected]
  42. Functions  At times, a certain portion of codes has

    to be used many times.  Instead of re-writing the codes many times, it is better to put them into a "subroutine", and "call" this "subroutine" many time - for ease of maintenance and understanding. Subroutine is called function. The benefits of using functions are:  Divide and conquer: construct the program from simple, small pieces or components. Modularize the program into self-contained tasks.  Avoid repeating codes: It is easy to copy and paste, but hard to maintain and synchronize all the copies.  Software Reuse: you can reuse the functions in other programs, by packaging them into library codes.  Two parties are involved in using a function: a caller who calls the function, and the function called. The caller passes argument(s) to the function. The function receives these argument(s), performs the programmed operations within the function's body, and returns a piece of result back to the caller. 42 Online Course | Embedded C Programming for c51 Microcontroller | L.Boaz | JPCAS | [email protected]
  43. [III] KEIL IDE  Keil is a German based Software

    development company. It provides several development tools like • IDE (Integrated Development environment) • Project Manager • Simulator • Debugger • C Cross Compiler , Cross Assembler, Locator/Linker 43 Online Course | Embedded C Programming for c51 Microcontroller | L.Boaz | JPCAS | [email protected]
  44. 8051 project development cycle  Create source files in C

    or assembly.  Compile or assemble source files.  Correct errors in source files.  Link object files from compiler and assembler.  Test linked application. 44 Online Course | Embedded C Programming for c51 Microcontroller | L.Boaz | JPCAS | [email protected]
  45. Contact Er.L.Boaz Assistant Professor Department of B.Sc Electronics and Communication

    J.P. College of Arts and Science College Road, Agarakattu, Ayikudi Tenkasi District Tamilnadu - 627 852 [email protected] [email protected] +91 95972 91816 /in/boazlawnce/ /NissiEmbeddedLab /boaz 46 Online Course | Embedded C Programming for c51 Microcontroller | L.Boaz | JPCAS | [email protected]