SlideShare a Scribd company logo
1 of 80
Download to read offline
Higher technology institute Electrical & computers Dept
Report on /
Embedded System
Industrial training /
ITR 202
Submitted to : Examiners Committee
Submitted by : Name / Islam nabil mahmoud mohamed ID / 20130890
Supervised by : Dr / Mohamed Ali Torad ( HTI )
May- August 2017
Islam Nabil Mahmoud 20130890 1 Electrical&computers Dept Industrial Training 4 ITR 202
Abstract
Embedded system & Its Application
Microcontrollers
System on chip
System on board
Difference Between Microprocessor and Microcontroller
Microcontroller CPU architectures
Memory unit
Types Of Real Time Systems
Simulator vs. Emulator
C programming
Data structure & Algorithms
Computer Architecture
Labs
Islam Nabil Mahmoud 20130890 2 Electrical&computers Dept Industrial Training 4 ITR 202
Detailed Content
Chapter 1 Introduction to Embedded system........................................................................................................................8
Embedded systems applications...........................................................................................................................................8
General Purpose Processors................................................................................................................................................10
Embedded general purpose Processors...............................................................................................................................10
Digital signal processors.....................................................................................................................................................10
Microcontrollers.................................................................................................................................................................10
Software characteristics......................................................................................................................................................10
Hardware characteristics.....................................................................................................................................................11
System on board..................................................................................................................................................................11
System on chip....................................................................................................................................................................11
Advanced Embedded System.............................................................................................................................................11
Difference Between Microprocessor and Microcontroller.................................................................................................12
Microcontroller...................................................................................................................................................................12
Microcontroller...................................................................................................................................................................12
Microcontroller main components......................................................................................................................................13
Serial communication in ATmega32...................................................................................................................................13
Microprocessor...................................................................................................................................................................13
CPU Structure.....................................................................................................................................................................14
ALU....................................................................................................................................................................................14
FPU.....................................................................................................................................................................................14
Microcontroller CPU architectures.....................................................................................................................................14
Von Neumann architecture.................................................................................................................................................15
Harvard Architecture..........................................................................................................................................................15
CPU main registers.............................................................................................................................................................16
Stack pointer.......................................................................................................................................................................16
Program counter.................................................................................................................................................................16
Processor status word/condition code register (PSW ).......................................................................................................16
Memory unit.......................................................................................................................................................................17
RAM memory (Random Access Memory).........................................................................................................................17
RAM Types.........................................................................................................................................................................18
Stack...................................................................................................................................................................................18
Read Only Memory (ROM)...............................................................................................................................................18
OTP ROM (One Time Programmable ROM):...................................................................................................................18
Masked ROM.....................................................................................................................................................................18
UV EPROM........................................................................................................................................................................19
EEPROM memory (Electrically Erasable Programmable ROM) :....................................................................................19
Flash memory.....................................................................................................................................................................19
ROM contents.....................................................................................................................................................................19
Software..............................................................................................................................................................................19
What is a Program?.............................................................................................................................................................20
Memory Addressing :.........................................................................................................................................................20
Machine Language :...........................................................................................................................................................20
Simulator vs. Emulator.......................................................................................................................................................20
Software Process Activities................................................................................................................................................20
Software Costs....................................................................................................................................................................20
Real-time operating system (RTOS)...................................................................................................................................21
Types Of Real Time Systems..............................................................................................................................................21
OS basic Concepts..............................................................................................................................................................21
Servicing Interrupts............................................................................................................................................................22
Islam Nabil Mahmoud 20130890 3 Electrical&computers Dept Industrial Training 4 ITR 202
Vectored Arbitration System :.............................................................................................................................................22
Non-Vectored Priority System :..........................................................................................................................................22
Chapter 2 C programming..........................................................................................................................................23
Introduction about programming lang........................................................................................................................23
Advantage of C programming....................................................................................................................................25
What is OS. ?..............................................................................................................................................................25
What is file.exe?.........................................................................................................................................................25
Assembly lang............................................................................................................................................................25
Assembler...................................................................................................................................................................26
Linear and structuration programming.......................................................................................................................26
Structuration programming........................................................................................................................................26
IDE (integrated development environment)...............................................................................................................26
Compiler:....................................................................................................................................................................26
Error types..................................................................................................................................................................26
Memory......................................................................................................................................................................27
1 st program................................................................................................................................................................28
Variables.....................................................................................................................................................................28
Data Types..................................................................................................................................................................28
Data types...................................................................................................................................................................29
How to declare a variable ?........................................................................................................................................29
Variable/functions names...........................................................................................................................................29
Variable declaration....................................................................................................................................................30
Printing out variables.................................................................................................................................................30
Example 1...................................................................................................................................................................30
Constants....................................................................................................................................................................30
Operators....................................................................................................................................................................30
Input variables............................................................................................................................................................31
Precedence..................................................................................................................................................................31
Casting........................................................................................................................................................................32
Input function.............................................................................................................................................................33
Output functional........................................................................................................................................................33
Loops..........................................................................................................................................................................33
Nested For..................................................................................................................................................................34
Continue.....................................................................................................................................................................35
Branshing...................................................................................................................................................................35
Switch case.................................................................................................................................................................36
Function......................................................................................................................................................................37
Prototypes...................................................................................................................................................................37
Function types............................................................................................................................................................38
Global variables..........................................................................................................................................................38
Static variables...........................................................................................................................................................38
Array...........................................................................................................................................................................39
How to declare array..................................................................................................................................................39
How array works?(one dimensional).........................................................................................................................40
String function............................................................................................................................................................41
Pointers.......................................................................................................................................................................41
Declarations................................................................................................................................................................41
Pointer advantages......................................................................................................................................................42
Swap function.............................................................................................................................................................42
typedef........................................................................................................................................................................42
structure......................................................................................................................................................................42
Union..........................................................................................................................................................................42
Memory usage............................................................................................................................................................43
Stack Versus Heap......................................................................................................................................................43
Dynamic memory Versus Arrays................................................................................................................................44
How to allocate...........................................................................................................................................................44
Chapter 3 Data structure & Algorithms.............................................................................................................45
Algorithm...........................................................................................................................................................45
Islam Nabil Mahmoud 20130890 4 Electrical&computers Dept Industrial Training 4 ITR 202
Linked list..........................................................................................................................................................45
Why Linked List?..............................................................................................................................................46
Array..................................................................................................................................................................46
Double linked list...............................................................................................................................................46
Circular linked list.............................................................................................................................................47
Single linked list................................................................................................................................................47
Single linked list representation in C.................................................................................................................47
Functions of linked list......................................................................................................................................47
Stack...................................................................................................................................................................48
Sorting algorithm For each algorithm :..............................................................................................................48
Sorting algorithm...............................................................................................................................................48
Searching algorithm...........................................................................................................................................48
Searching algorithm...........................................................................................................................................49
Cahpter 4 Computer Architecture......................................................................................................................50
Computer Architecture.......................................................................................................................................50
History of Computers.........................................................................................................................................50
Generations of computers :................................................................................................................................50
Technology with computer................................................................................................................................51
Measurement of Computer Performance...........................................................................................................51
Measurement of CPU Time...............................................................................................................................51
Measurement of Computer PerformanceBenchmarks :.....................................................................................51
Examples of benchmarks...................................................................................................................................51
Computer Systems.............................................................................................................................................52
Basic block diagram...........................................................................................................................................52
Elements of the basic system.............................................................................................................................52
Key definitions...................................................................................................................................................52
Motherboard:.....................................................................................................................................................52
Bus:....................................................................................................................................................................52
Detailed block diagram for computer system....................................................................................................54
Buses types........................................................................................................................................................54
ISA Bus ISA is Industry Standard Architecture................................................................................................55
PCI Bus..............................................................................................................................................................55
IDE Bus..............................................................................................................................................................55
AGP Bus............................................................................................................................................................55
USB Bus USB Bus (Universal Serial Bus)........................................................................................................55
Internal Buses....................................................................................................................................................56
CPU Structureny CPU is consisting of main components :...............................................................................56
Processor Data-path...........................................................................................................................................56
Processor Data-path...........................................................................................................................................58
CPU Structure....................................................................................................................................................58
ALU...................................................................................................................................................................58
FPU....................................................................................................................................................................59
CPU Registers....................................................................................................................................................59
User-visible registers.........................................................................................................................................59
Control and Status Registers..............................................................................................................................59
Control Unit.......................................................................................................................................................61
Program execution.............................................................................................................................................61
Instruction cycle.................................................................................................................................................61
Two design of control units................................................................................................................................62
Hardwired control unit.......................................................................................................................................62
Micro-programmed control unit Example of micro-programmed control unit.................................................63
Instruction Set Architecture (ISA).....................................................................................................................64
Registers.............................................................................................................................................................64
The instruction set architecture elements...........................................................................................................65
Addressing modes of instructions......................................................................................................................65
Addressing modes types....................................................................................................................................66
Addressing modes..............................................................................................................................................68
Memory architecture..........................................................................................................................................68
Islam Nabil Mahmoud 20130890 5 Electrical&computers Dept Industrial Training 4 ITR 202
Interrupt handling..............................................................................................................................................68
I/O Handling......................................................................................................................................................68
Intel IA32 Architecture......................................................................................................................................69
Pipelining...........................................................................................................................................................69
Single Cycle Processor (No Pipelining)............................................................................................................69
Multiple Cycle Processor...................................................................................................................................70
Advantages of Multiple Cycle Processor...........................................................................................................70
Five Stage Pipelining.........................................................................................................................................71
Load instruction five Stage................................................................................................................................72
Limitation to Pipelining.....................................................................................................................................73
Structural Hazards..............................................................................................................................................73
Structural Hazards..............................................................................................................................................74
Structural hazards..............................................................................................................................................74
Data hazards.......................................................................................................................................................74
Solutions for data hazards include hardware and software methods.................................................................75
Branch hazards...................................................................................................................................................75
Solutions to Branch Hazards..............................................................................................................................75
Pipelining and RISC..........................................................................................................................................75
Memory Types...................................................................................................................................................76
Memory management........................................................................................................................................76
Memory Management Unit................................................................................................................................76
Paged and Cash Technique................................................................................................................................77
Bus arbitration Operation:.................................................................................................................................77
Bank switching..................................................................................................................................................78
Memory protection............................................................................................................................................78
Super Scalar VS Vector Processor.....................................................................................................................78
Multiple Functional Units..................................................................................................................................79
Gantt Chart of a Super Scalar............................................................................................................................80
Instruction Issue Policy......................................................................................................................................80
Limitations.........................................................................................................................................................80
Instruction Level Parallelism (ILP):..................................................................................................................80
Limitations.........................................................................................................................................................80
Vector Processor................................................................................................................................................81
Conceptual View................................................................................................................................................81
Architecture.......................................................................................................................................................81
Semantic advantage...........................................................................................................................................82
Disadvantages....................................................................................................................................................82
Conclusion.........................................................................................................................................................82
Chapter 5 interfacing.........................................................................................................................................83
lab 1....................................................................................................................................................................83
4 swiches pull up with 7 seg..............................................................................................................................83
lab 2....................................................................................................................................................................84
7seg....................................................................................................................................................................84
lab 3....................................................................................................................................................................85
7seg-BCD...........................................................................................................................................................85
lab 4....................................................................................................................................................................86
led paraghraph....................................................................................................................................................86
lab 5 multipressing............................................................................................................................................87
lab 6....................................................................................................................................................................88
single pressing flag............................................................................................................................................88
lab 7....................................................................................................................................................................89
single pressing while..........................................................................................................................................89
lab 8....................................................................................................................................................................90
ext interrupt 0....................................................................................................................................................90
lab 9....................................................................................................................................................................91
ext inter 1...........................................................................................................................................................91
lab 10..................................................................................................................................................................93
ADC...................................................................................................................................................................93
Islam Nabil Mahmoud 20130890 6 Electrical&computers Dept Industrial Training 4 ITR 202
lab 11..................................................................................................................................................................94
pwm...................................................................................................................................................................94
lab 12..................................................................................................................................................................96
timer...................................................................................................................................................................96
lab 13..................................................................................................................................................................97
password............................................................................................................................................................97
Refrences :-......................................................................................................................................................100
Islam Nabil Mahmoud 20130890 7 Electrical&computers Dept Industrial Training 4 ITR 202
Chapter 1 Introduction to Embedded system
Embedded systems: All systems that contain one or more processor to do specific functionalities and give responses
upon receiving inputs. This processor is not general purposes like general purpose Processor in PC’s and notebooks.
Embedded systems are computing systems with tightly coupled hardware and software integration, that are designed to
perform a dedicated function.
systems are usually an integral part of a larger system, known as the embedding system. Multiple embedded systems
can coexist in an embedding system.
Embedded systems applications
Communication:
Mobile Handsets, switches, routers ...etc.
Image processing and consumers:
Audio, video, cameras, printers, Mpeg-2 decoder, Mp3 and Mp4 players, PlayStation...etc.
Automotive:
Motor Engines, Climate control...etc.
Appliances:
Microwave, washing Machines.
Automotive
Telecommunication Electronic devices Computers Home automation
Industrial Military Solar systems Aviation technology Banking
Robotics.
Aircraft electronics. Cinema industry Medical equipment Wearable
technologies Mobile phones
Automotive
Lightning system Air bags ABS Parking system
Computers
Sound cards Ethernet cards Graphic cards Modem cards TV and satellite
cards
Electric devices
Washing machines Microwave ovens Water heater Dishes
washing machine Frigidaire
Air conditioner TV , LCD, LED and satellite receiver
Home automation
Lightening systems Audio and home theater sound systems
Controlling Temperature and humidity levels inside the house
Automatic doors (rooms, garage ..etc)
Industrial
Factories huge robotic arms which assemble car components
or any other machine
Military
Tanks shooting systems Submarines SONAR systems Missiles and target identification systems
Islam Nabil Mahmoud 20130890 8 Electrical&computers Dept Industrial Training 4 ITR 202
Telecommunications
Mobile generations implementation : 3G and LTE
Network : Wi-Fi chips, Routers and Switches
Aviation and aerospace technology
Airplane Navigation systems ,GPS systems
Robotics
Robots for any purpose ( home aid, industrial, playing, security .. etc. )
Banking
Money counting machine ,ATMs
Cinema industry
Cameras ,Theaters , Motion effects
Medical equipment and technologies
ECG is a diagnostic tool that measures and records the electrical activity of the heart Ultrasound Fitness devices
Cardiac peacemaker
Wearable
Google Glasses Smart watches Temperature adjustable clothes
Mobile
Smart phones Tablets IPAD
General Purpose Processors
32 or 64-bit data path. Central processing engine of a mainframe, workstation, PC, RISC and CISC
engines. examples: X86, PowerPC, SPARC, Pentium. Complex in design because these processors provide a full scale
of features and a wide spectrum of functionalities. Modern processors have:
Built-in memory management unit (MMU) to provide memory protection and virtual memory for multitasking-capable.
General-purpose operating systems. Have advanced cache logic.
Built-in math co-processor capable of performing fast floating-point operations.
These processors result in large power consumption, heat production, and size.
Embedded general purpose Processors
Designed for a wide range of application (consumer and communication)
16/32-bit data path
Limited functionality depends on the application
Not Flashable i.e. the program memory is external and have CASH
memory and MMU and support Extended memory
Have main peripherals Like Timers , Ethernet , USP.
Usually integrated into larger dedicated systems in a SoC (System on Chip)
examples: ARM, PowerPC, MIPS, 68K, x86.
ARM has seized the lion’s share of the market.
Islam Nabil Mahmoud 20130890 9 Electrical&computers Dept Industrial Training 4 ITR 202
Digital signal processors
Like embedded general-purpose but Focus on the very efficient execution
of arithmetic operations. DSP has : specialized arithmetic units, optimized design in the memory, addressing and bus
architectures with multiprocessing capability that allow the DSP to perform complex calculations extremely fast in real
time. Used widely in digital signal processing in communications systems such as Cell phones and Image and video
processing Examples: TI (Texas Instruments), Motorola. TI has been the dominant player in the DSP market for several
years.
Microcontrollers
The workhorse of industrial electronics.
Designed for standalone operation.
Include processing unit 8-bit, 16-bit, 32-bit.
Included memories (RAM, ROM), IO, buses and peripherals
depending on the application designed for (LIN , CAN , Ethernet , I2C , SPI and ..).
Many micro controllers are descendants of successful architectures
from the 8-bit and 16-bit microprocessor generations.
Software characteristics
Highly configurable. Shorter development cycle. Easier in versions updates. Cheaper.
Hardware characteristics
Longer development cycle. Customized for specific application. Better performance in high speed real time application.
Long term SW. is more expensive than HW. because of maintenance.
System on board
Level 1: external discrete hardware component on board(SoB)
Islam Nabil Mahmoud 20130890 10 Electrical&computers Dept Industrial Training 4 ITR 202
System on chip
Level 2: hardware integrated with CPU on chip (SoC).
Level 3: done by software running on CPU (VHDL).
Advanced Embedded System
Multi-core system on chip like mobile handset which has one chip contains:
1. DSP processor
2. Embedded processors like ARM
3. Custom hardware for GSM
4. Custom peripherals for board interface (keyboard, touch screen, memory card interface).
Network of embedded microcontrollers on board :
Many microcontrollers on one / many board(s) communicated together
through specific bus protocol like LIN bus, CAN bus in automotive application
Difference Between Microprocessor and Microcontroller
Essentially these two devices are similar, but with a little bit difference.
A microcontroller is not the same as a microprocessor.
A microprocessor is a single chip CPU used within other computer systems.
A microcontroller is itself a single chip computer system.
Microcontroller
Microcontroller is single chip device or single chip computer in a small size that its resources are far more limited than
those of a desktop personal computer. Microcontrollers don’t work alone in the circuit it must interfaces with other on
chip devices.
Islam Nabil Mahmoud 20130890 11 Electrical&computers Dept Industrial Training 4 ITR 202
Microcontroller
A microcontroller is a single chip, self-contained computer which incorporates all the basic components of a personal
computer on a much smaller scale. Microcontrollers are often referred to as single chip devices or single chip
computers. The main consequence of the microcontroller’s small size is that its resources are far more limited than
those of a desktop personal computer. Microcontrollers are typically used as embedded controllers where they control
part of a larger system such as an appliance, automobile, scientific instrument or a computer peripheral.
Microcontrollers are designed to be low cost solutions therefore using them can reduces costs for a project. The
microcontroller can accept inputs from some devices and provide outputs to other devices within any given system. For
example, a microcontroller may accept input from a switch and may send output to an LED. If the switch is pressed the
microcontroller can be instructed to illuminate the LED.
Microcontroller main components
A microcontroller has eight main components:
Central processing unit (CPU)
Input and Output (GPIO general purpose I/O or DIO)
ROM
RAM
Timer
Interrupt circuitry
Buses
Watchdog
Serial communication in ATmega32
Uart is Universal Asynchronous Receiver/Transmitter , SPI is Serial Peripheral Interface
, I2C is Two wires integrated circuits
Microprocessor
Microprocessor is a single chip used within other computer systems Is a typical Personal Computer where devices are
attached to the CPU, using hard-wired connections
which makes the system more flexible. can add more memory, change capacity of
hard drives, add or remove CD-ROMs, sound card. CPU does all the computing: it fetches, decodes and executes
program instructions and directs the flow of data to and from memory. The CPU
performs the calculations required by program instructions and places the results of these calculations, if required, into
memory space. Example like picture
Islam Nabil Mahmoud 20130890 12 Electrical&computers Dept Industrial Training 4 ITR 202
CPU Structure
The basic elements of the CPU are: ALU Arithmetic & Logic Unit Responsible for performing logic and arithmetic
calculations Floating-Point Unit (FPU) performs arithmetic operations on floating point numbers Registers Registers
are used to store data beside the ALU ,Registers are used to transfer data to/from memory , Registers carry the inputs of
ALU, as well as, receiving the output of the ALU Internal CPU Bus It is a special bus It is responsible for transferring
data between registers, ALU, and system memory Control Unit It is responsible for organizing the actions of the CPU.
It can be thought of as the heart of the CPU
ALU
A & B are inputs of the ALU Control
input: Selects the required functionality to be done on A (& B)
Output: Output of the operation performed on operands
Flags: Indicate status of last arithmetic & logic operations performed in the
ALU (E.g. zero flag, overflow flag, sign flag)
FPU
Similar to the ALU is the Floating-Point Unit, or FPU. The FPU performs
arithmetic operations on floating point numbers. An FPU is complicated to design, although the IEEE 754 standard
helps to answer some of the specific questions about implementation.
It isn't always necessary to follow the IEEE standard when designing an FPU, but it certainly does help.
Microcontroller CPU architectures
There are two basic types of architecture: Von Neumann , Harvard
Microcontrollers most often use a Harvard or a modified Harvard- based architecture.
Islam Nabil Mahmoud 20130890 13 Electrical&computers Dept Industrial Training 4 ITR 202
Von Neumann architecture
Von Neumann architecture has a single, common memory space where
both program instructions and data are stored. There is a single data bus which fetches both instructions and data. Each
time CPU fetches a program instruction it may have to perform one or more read/write operation “instruction” from/to
data memory space. It must wait until these subsequent “instruction“ are complete before it can fetch and decode the
next program instruction.
Harvard Architecture
Harvard architecture computers have separate memory areas for program
instructions and data. One bus is a 8-bit wide and connects CPU to RAM memory. The other bus
consists of several lines (12, 14 or 16 -bit) and connects CPU to ROM memory.
The CPU can read an instruction and perform a data memory access at the same time.
This speeds up execution time but increases the cost of more hardware complexity.
Islam Nabil Mahmoud 20130890 14 Electrical&computers Dept Industrial Training 4 ITR 202
CPU main registers
Stack pointer
Contains the address of the next location on the stack
Decremented when data is pushed on the stack and incremented when data is
popped from the stack
Program counter
Most important CPU register
Holds the address of the next instruction in program memory space
Each instruction is fetched and processed by ALU, the CPU increments the PC .
Processor status word/condition code register (PSW )
Contains flags represent the status of the last operation to control the following
instructions. Overflow flag ,Negative flag, Zero flag, Carry flag, Half-carry flag ,Global
Interrupt mask flag
Memory unit
Memory is a part of the microcontroller used for data storage. There are different types of memory within the
microcontroller:
1. ROM memory (Read Only Memory)
2. RAM memory (Random Access Memory).
Memory Hierarchy
Islam Nabil Mahmoud 20130890 15 Electrical&computers Dept Industrial Training 4 ITR 202
RAM memory (Random Access Memory)
Random access refers to the ability to access any memory cell directly. RAM is much faster than ROM. It used to write
and read data values while program running
RAM is Volatile memory: volatile: if you remove the power supply its contents are lost.
Any variable used in a program is allocated into RAM. requires external power to maintain memory content. Used to
store data as long as Microcontroller is powered and the
program is running Modifiable through program instructions “ARM “ Manipulating large data structures : local
variables, pointers, functions, recursive functions results in using large amounts of RAM
RAM Types
Dynamic RAM (DRAM) is a RAM device that requires periodic refreshing to retain its content. Static RAM (SRAM) is
a RAM device that retains its content as long as power is supplied by an external power source. SRAM does not require
periodic refreshing and it is faster than DRAM. Non-Volatile RAM (NVRAM) NVRAM is a special type of SRAM that
has backup battery
power so it can retain its content after the main system power is shut off. Another variation of NVARM combines
SRAM and EEPROM(non volatile) so that its content is written into the EEPROM when power is shut off and is read
back from the EEPROM when power is restored.
Divided virtually to:
1. General purpose registers for CPU acts as accumulators.
2. Special Function Registers(SFR) for any peripheral (Data , Status ,Control registers).
3. Data RAM: all static variables in the program i.e. each variable has a static address and its last value lasts until
microcontroller power off.
4. Stack.
Stack
Is a structure records the chronological ordering of information. It is used mainly in subroutine/function calls and
interrupt servicing. A stack is LIFO (last in, first out)
structure The address is always in the SP register and is automatically updated
during a push or pop instruction.
Read Only Memory (ROM)
ROM is used to permanently save program being executed.
The size of the program that can be written depends on the size of ROM memory
Islam Nabil Mahmoud 20130890 16 Electrical&computers Dept Industrial Training 4 ITR 202
several types of ROM : OTP Mask ROM Flash ROM EEPROM memory UV EPROM
OTP ROM (One Time Programmable ROM):
If the microcontroller contains this memory, you can download a program into
the OTP , but the process of program downloading is “one-way ticket”, meaning that it can be done only once. OTP
(One Time Programmable) devices are microcontrollers where once a program is written into the device it cannot be
erased. one time programming ROM used in products
Masked ROM
Microcontrollers containing this ROM are mainly used by the huge manufacturers. Program is loaded onto the chip by
the manufacturer. In case of large scale manufacturing, the price is very low. ROM whose contents are set by masking
during the manufacturing process. Programmed upon microcontroller production
UV EPROM
(UV Erasable Programmable ROM) the package of microcontroller has recognizable “window” on the upper side. this
It enables surface of the silicon chip to be lit by an UV lamp, which has, as a result , that complete program cleared and
a new program download enabled.
EEPROM memory (Electrically Erasable Programmable ROM) :
The contents of this memory may be changed during operation (similar to RAM), but remains permanently saved even
if the power supply went off (similar to ROM). Accordingly, EEPROM is often used to store values, created during
operation, which must be permanently saved
Flash memory
This type of memory was invented in the 80s in laboratories of INTEL company and were represented as a successor of
the UV EPROM. Since the contents of this memory can be written and cleared practically unlimited number of times,
the microcontrollers with Flash ROM are ideal for learning, experimentation and small-scale manufacturing.
ROM contents
program code or text section in flash memory Is instruction code section. Data section in flash memory Handled
through “const” keyword in C language. Data are used as a constant configuration from prospective system design and
versions configurations. Global , statics, constants,... etc.
Software
Software is the collection of computer programs and related data that provide the instructions telling a computer what to
do. Software products may be developed for a particular customer or may be developed for a general market.
Islam Nabil Mahmoud 20130890 17 Electrical&computers Dept Industrial Training 4 ITR 202
What is a Program?
A collection of such instructions is a called a program and the person who writes
and revises these instructions is known as a programmer or developer.
Memory Addressing :
Computer memory is divided up into addresses. Each address holds an 8 bit (or 1 byte) value.
Machine Language :
Computers only understand one language: machine language. Each family of
computers has its own machine language which can not be understood by any
other family of computers. Machine language is a collection of binary numbers
Simulator vs. Emulator
Simulator : is a software program which allows a developer to run a program . The simulator simulates the running
conditions of the target machine on the development machine.
Emulator or in-circuit emulator : is a hardware device which behaves like a
target machine. It is often called a real time tool because it can react to events as the target microcontroller would.
Emulators are often packaged with monitor programs which allow developers to examine registers and memory
locations and set breakpoints.
Software Process Activities
Software Costs
Software costs often dominate computer system costs. The costs of software on a PC are often greater than the hardware
cost. Software costs more to maintain than it does to develop. Roughly 60% of software costs are development costs,
40% are testing costs. For systems with a long life, maintenance costs may be several times development costs. About
US $250 billions spent per year in the US on application development.
Islam Nabil Mahmoud 20130890 18 Electrical&computers Dept Industrial Training 4 ITR 202
Real-time operating system (RTOS)
A real-time operating system (RTOS) is an operating system (OS) intended for real-time applications. The idea of the
Operating Systems(OS) comes with the definition of the abstraction. Any OS specially RTOS acts as abstraction layer
between application layer, and the hardware abstraction layer (HAL).
Types Of Real Time Systems
Soft real-time system: The system that can operate with the presence of latency at deadline.
It is not considered to have failed if it does not complete its function at deadline but that affects the quality of the output.
Examples: Video Processing Audio processing Digital cameras Mobile phones
Hard real-time system: Also known as an immediate real-time system.
The system that must operate within the confines of a stringent deadline. It is considered to have failed if it does not
complete its function within the allowed time span.
Examples: Car Air bag. anti-lock Braking Systems(ABS). aircraft control systems.
OS basic Concepts
Real Time OS is a multiple Background / Foreground system Multiple Background is Multiple Tasks Interrupt Service
Routines (ISRs) handle asynchronous events (foreground) Kernel is the main part of OS that manage tasks execution
and Communication Scheduler/Dispatcher is the part of Kernel that is Responsible for task execution based on task
priorities Types of schedulers: Non-preemptive Preemptive “So the task level (Background) perform the main
functionality, but the interrupt level (Foreground) perform the Asynchronous events”
Islam Nabil Mahmoud 20130890 19 Electrical&computers Dept Industrial Training 4 ITR 202
Servicing Interrupts
There are two general ways in which microcontrollers service interrupts :
Vectored Arbitration System :
Each interrupt vector contains the address of that interrupt’s service routine. When the compiler allocates program
memory for interrupt handlers, it places the appropriate address for the handler in the appropriate interrupt vector. To
help the compiler you must usually tell it where the interrupt vector for each interrupt is located in program memory.
Non-Vectored Priority System :
When an interrupt occurs, the CPU branches to a specific address. At this address the interrupts must be checked
sequentially to determine which one has caused the interrupt. This scheme can be very slow and there can be a large
delay between the time the interrupt occurs
and the time it is serviced
Islam Nabil Mahmoud 20130890 20 Electrical&computers Dept Industrial Training 4 ITR 202
Chapter 2 C programming
prerequisites : -
1. C compiler : gcc compiler ( preinstalled with linux )
2. IDE free : code::Blocks
Introduction about programming lang.
The earliest computers were often programmed without the help of a programming language, by writing programs in
absolute machine language. The programs, in decimal or binary form, were read in from punched cards or magnetic
tapeor toggled in on switches on the front panel of the computer. Absolute machine languages were later termed first-
generation programming languages (1GL).
The next step was development of so-called second-generation programming languages (2GL) or assembly languages,
which were still closely tied to the instruction set architecture of the specific computer. These served to make the
program much more human-readable and relieved the programmer of tedious and error-prone address calculations.
The first high-level programming languages, or third-generation programming languages (3GL), were written in the
1950s. An early high-level programming language to be designed for a computer was Plankalkül, developed for the
German Z3 by Konrad Zuse between 1943 and 1945. However, it was not implemented until 1998 and 2000.[26]
John Mauchly's Short Code, proposed in 1949, was one of the first high-level languages ever developed for
an electronic computer. Unlike machine code, Short Code statements represented mathematical expressions in
understandable form. However, the program had to be translated into machine code every time it ran, making the
process much slower than running the equivalent machine code.
At the University of Manchester, Alick Glennie developed Autocode in the early 1950s. A programming language, it
used a compiler to automatically convert the language into machine code. The first code and compiler was developed in
1952 for the Mark 1 computer at the University of Manchester and is considered to be the first compiled high-level
programming language.
The second autocode was developed for the Mark 1 by R. A. Brooker in 1954 and was called the "Mark 1 Autocode".
Brooker also developed an autocode for the Ferranti Mercury in the 1950s in conjunction with the University of
Manchester. The version for the EDSAC 2 was devised by D. F. Hartley of University of Cambridge Mathematical
Laboratory in 1961. Known as EDSAC 2 Autocode, it was a straight development from Mercury Autocode adapted for
local circumstances and was noted for its object code optimisation and source-language diagnostics which were
advanced for the time. A contemporary but separate thread of development, Atlas Autocode was developed for the
University of Manchester Atlas 1 machine.
In 1954, FORTRAN was invented at IBM by John Backus. It was the first widely used high-level general purpose
programming language to have a functional implementation, as opposed to just a design on paper. It is still popular
language for high-performance computing and is used for programs that benchmark and rank the world's fastest
supercomputers.
Another early programming language was devised by Grace Hopper in the US, called FLOW-MATIC. It was developed
for the UNIVAC I at Remington Rand during the period from 1955 until 1959. Hopper found that business data
processing customers were uncomfortable with mathematical notation, and in early 1955, she and her team wrote a
specification for an English programming language and implemented a prototype.[34] The FLOW-MATIC compiler
became publicly available in early 1958 and was substantially complete in 1959.[35] Flow-Matic was a major influence
in the design of COBOL, since only it and its direct descendant AIMACO were in actual use at the time
APL introduced array programming and influenced functional programming.
Islam Nabil Mahmoud 20130890 21 Electrical&computers Dept Industrial Training 4 ITR 202
ALGOL refined both structured procedural programming and the discipline of language specification; the "Revised
Report on the Algorithmic Language ALGOL 60" became a model for how later language specifications were written.
Lisp, implemented in 1958, was the first dynamically typed functional programming language
In the 1960s, Simula was the first language designed to support object-oriented programming; in the mid-
1970s, Smalltalk followed with the first "purely" object-oriented language.
C was developed between 1969 and 1973 as a system programming language for the Unix operating system and
remains popular.
Prolog, designed in 1972, was the first logic programming language.
In 1978, ML built a polymorphic type system on top of Lisp, pioneering statically typed functional
programminglanguages.
Advantage of C programming
C programming is standard lang. (ANSI C).
1. Using C in OS.
2. C is Instruction lang.
3. Bit manipulation using
4. Bit field
5. Bit masking
6. Fast execution.
7. Portable
What is OS. ?
An operating system (OS) is software that manages computer hardware and software resources and provides common
services for computer programs. The operating system is an essential component of the system software in a computer
system. Application programs usually require an operating system to function.
What is file.exe?
EXE is a file extension for an executable file format. An executable is a file that contains a program - that is, a particular
kind of file that is capable of being executed or run as a program in the computer
Assembly lang.
assembly language is a low-level programming language for a computer, or other programmable device, in which there
is a very strong (generally one-to- one) correspondence between the language and the architecture's machine code
instructions.
Assembler.
is a program that takes basic computer instructions and converts them into a pattern of bits that the computer's processor
can use to perform its basic operations.
C/C++ is mid level general purpose lang
Linear and structuration programming
he instructions are written sequentially one under the other. We can repeat a
group of statement (looping), we can also making some condition in the program.
1. Linear execution.
2. No (loop, jump,.......).
Islam Nabil Mahmoud 20130890 22 Electrical&computers Dept Industrial Training 4 ITR 202
Structuration programming
divide the program into blocks. All blocks are linked together. Link between blocks used to
transfer data between blocks.
1. C programming is structuration programming.
2. Using (jump, loop,......)
IDE (integrated development environment).
(CodeBlocks, Turbo C, Eclipse ,Cfree ,Devc, Borland,.... ).
Compiler:
the first step is compiling which is done by the compiler. The compiler has 2 main roles :
1. Check that the syntax in the source code is right
2. To make the intermediate file.
3. Gcc is compiler.
In C/C++ programs:
The first step is compiling: in this step, the compiler makes an object file this is
an intermediate file between the source file and the executable file. It has
an extension *.obj
The second step is linking: in this step, the linker links the library file to the
object file to make the executable file.
Error types
1. Compiler error is syntax error.
2. Run time error is like infinite loop or divide by zero.
3. logical error is not error in grammar or run time error.
Memory
Memory is like a big table of numbered slots where bytes can be stored. The number of a slot is its Address. One byte
Value can be stored in each slot. Some “logical” data values span more than one slot, like the character string “Hellon”
Islam Nabil Mahmoud 20130890 23 Electrical&computers Dept Industrial Training 4 ITR 202
1 st program
#include <stdio.h>
#include <stdlib.h>
>>> // #include inserts another file. “.h” files are called
“header” files. They contain stuff needed to interface to
libraries and code in other “.c” files.
/*simple Hello world program*/ >>> This is a comment. The compiler ignores this.
int main() >>>The main() function is always where your program starts running
{ >>> Blocks of code between them I write my program for now
printf("Hello world!n"); >>> Print out a message. ‘n’ means “new line”.
Return 0; >>> exit
}
Variables
A Variable names a place in memory where you store a Value of a certain Type.
A variable name in computer source code is associated with a data storage location
and thus its contents, which generally change during the course of program execution.
Example :
1. var1=2;
2. Var2=5;
3. Var1=4;
name Address Value
0x00
0x01
0x02
0x03
var1 0x04 4
var2 0x05 5
Data Types
Islam Nabil Mahmoud 20130890 24 Electrical&computers Dept Industrial Training 4 ITR 202
Data types
How to declare a variable ?
char x; Initial value of x is undefined
char y=‘A’;
char y = ‘A’ ;
Data Type is single character (char) Initial value Name
Variable/functions names
1. must start with an alphabetic character or “_ “.
2. They may contain numeric digits as well but cannot start with a digit countDown10_1.
3. Variable name is lowercase.
4. not one of C Keywords 32 reserved C keywords
(auto, break, case, char, const, continue, default, do, double, else, enum, extern
,float, for, goto, if, int, long, register, return, short, signed, sizeof, static, struct , switch,
typedef, union, unsigned, void, volatile, while )
Variable declaration
Decelerate variables: Variable_DataType variable_name ;
Ex: Char i=5;
Decelerate multiple variables:
Variable_DataType variableName1, variableName2;
Ex: char x,y,z; //Garbage value
Printing out variables
using printf(“ any word: %d ”, var_name);
%d integer number
%f floating number
%c characters
%o The unsigned octal format specifier.
Islam Nabil Mahmoud 20130890 25 Electrical&computers Dept Industrial Training 4 ITR 202
%s The string format specifier.
%u The unsigned integer format specifier.
%x The unsigned hexadecimal format specifier a b c
%X The unsigned hexadecimal format specifier A B C
Example 1
#include <stdio.h>
int main(void)
{
int var = 'a', nVar =20;
float fl =1.3;
printf("int = %dn", var);
printf("char = %cn", var);
printf("int = %dn", fl);
printf("float= %fn", fl);
printf("int = %dn", nVar);
return 0;
}
Constants
Named constants may be created using const ex:
const int days_in_week = 7;
days_in_week = 5; (x error here )
Operators
1. Arithmetic operators: is binary operators
2. Relational operators
3. Logical operators
Ex:
(10>8 && 9>7)
(10<8||7<8)
!(10==8)
Assignment operators:
EX: if a=6
a=a+5 is a+=5 so a=11
a=a*5 is a*=5 so a=30
NOTE: unary operators is
a=a+1 is a++ increment is ++a(prefix) , a++ (postfix))
a=a-1 is a-- decrement is --a(prefix) , a--(postfix))
Input variables
scanf(”%d”,&x);
&x is the address of x. Don’t use x only this make it save in address of the value that stored in x.
Same format specifier of printf.
Example :
#include <stdio.h>
int main(void)
{
int a, b;
printf("Enter two numbers: ");
Islam Nabil Mahmoud 20130890 26 Electrical&computers Dept Industrial Training 4 ITR 202
Result
int = 97
char = a
int = -1073741824
float= 1.300000
long int = 20
Exmaple 2
#include <stdio.h>
int main(void)
{
int dec = 20, oct = 020, hex = 0x20;
printf("dec=%d, oct=%d, hex=%d, n", dec, oct,
hex);
printf("dec=%d, oct=%o, hex=%xn", dec, oct,
hex);
return 0;
}
Result
dec=20, oct=16,hex=32
dec=20, oct=20, hex=20
+ - / * % > < == |= <= >= && || !
= += -= *=
scanf("%i %i", &a, &b);
printf("%i - %i = %in", a, b, a - b);
return 0;
}
Precedence
Note:
• && ,||, ! Using in condition.
o/p is (true or false)
• Comma operator:
#include<stdio.h>
main()
{
int x=5;
int y=10;
int z=20;
printf("%d n ",(x,y,z));
printf("%d n ",x,y,z);
}
Note
<math.h> :
Sin , cos , tan , pow, abs, sqrt, sizeof().
Example:
X=pow(3,9) so x=3
X=abs(-3) so x=3
X=sqrt(25) so x=5
X=sizeof(int) so x=2 or 4 byte
X=sizeof(char) so x=1 byte
 How to convert float to int ?
Int x;
X=int(3.5);
Printf(“%d”,x);
Islam Nabil Mahmoud 20130890 27 Electrical&computers Dept Industrial Training 4 ITR 202
Casting
Implicit casting :
Int x=17;
Long L=2000;
L=x;
NOTE
1-How to get the ASCI code from character?
#include<stdio.h>
main()
{int x;
x=(int)'a';
printf("%d",x);}
2-How to get char from ASCI?
char x;
x=(char)97;
Printf(“%d”,x);
3-How to convert from the small to capital char?
#include<stdio.h>
main()
{char x='a';
x=(char)((int)'a'-32);
printf("%c",x);}
%.3f is .....
Example:
Int x=256.214587;
Printf(“the value of x = %.3f “,x);
So output will be the value of x =256.214
Input function
Scanf(),getchar(), getche(),getch(),gets()
Scanf();
• Header file is <stdio.h>
• Example:
#include<stdio.h>
main()
{
int a;
char b;
float c;
scanf(" %d %c %f",&a,&b,&c);
printf("%d %c %f",a,b,c);
}
Islam Nabil Mahmoud 20130890 28 Electrical&computers Dept Industrial Training 4 ITR 202
Explicit casting :
Int x=17;
Long L=2000;
X=(int)L;
L=(long)x;
Wide casting :
Int x;
Long L;
L=X;
getchar():
• Header file is <stdio.h>
• Example:
Char a;
a=getchar();
Printf(“%c”,a);
getche():
• Header file is
<conio.h>
• Example:
Char a;
a=getche();
Printf(“%c”,a);
getch():
• Header file is
<conio.h>
• Example:
char a;
a=getch();
Printf(“%c”,a);
gets():
• Header file is<stdio.h>
• Example:
char name[20];
gets(name);
Output functional
Printf();
Putchar();
<Stdio.h>
To print character
Puts():
<stdio.h>
To print string
Loops
1. For loop
2. Nested For
3. Infinite For
4. While loop
5. Difference between For and While
6. Infinite While
7. Do...........While
8. Difference between Do...........While and While
For()
For(initial; condition; update)
{
statements;
}
• Initial
• Condition
• Update
Note that initial, condition and update are optional.
Note: C Keywords 32 reserved C keywords
auto, break, case, char, const, continue, default, do, double, else, enum, extern ,float, for, goto,
if, int, long, register, return, short, signed, sizeof, static, struct , switch, typedef, union, unsigned,
void, volatile, while
Notes in for
Don't confuse the two relational operators (< and <=) and misuse them in the
expressions of loops.
For instance, the following
for (j=1; j<10; j++){
/* statement block */
}
for (j=1; j<=10; j++){
/* statement block */
}
Because the null statement is perfectly legal in C, you should pay attention to
placing semicolons in your for statements.
The initial and update parts may contain multiple comma separated
statements
int i, j, k;
for(i = 0, j = 5, k = -1; i < 10; i++, j++, k--)
 The initial, condition and update parts may contain no statements at all!
for(; i < 10; i++, j++, k--)
for(;i < 10;) //use of a while loop would be clearer here!
Islam Nabil Mahmoud 20130890 29 Electrical&computers Dept Industrial Training 4 ITR 202
Another function
Clrscr():
• <Conio.h>
• To clear screen
gotoxy(x,y);
Example:
Gotoxy(30,10);
for(;;)//creates an infinite loop
Nested For
For(initial 1 ; condition 1 ; update)
{
----------; //statements 1
----------;
For(initial 2 ; condition 2; update)
{
---------------; //statements 2
---------------;
}
----------; //statements 1
----------;
}
For(;;) >> Printf forever
Continue
The continue keyword forces the next iteration of the nearest enclosing loop
for(j = 1; j <= 10; j++)
{
if(j % 3 == 0) if j is exactly divisible by 3, skip
continue;
printf("j = %in", j);
}
note
Comma operator:
#include<stdio.h>
main()
{
int x=5;
int y=10;
Islam Nabil Mahmoud 20130890 30 Electrical&computers Dept Industrial Training 4 ITR 202
EX 2 While()
Initialization
While(cond)
{
statement 1;
statement 2;
.........;
update;
}
EX3 While(1)
 While(1) is for(;;).
 Example:
#include<stdio.h>
main()
{
int i=0;
while(1)
{
printf(“i=%d”,i);
i++;
}
}
Nested While
Initialization 1
While(cond1)
{
Initialization 2
While(cond2)
{
statements;
update;
}
statements;
update;
}
do.............while()
Initialization
do{
statements;
Update;
}while(cond);
Nested do............while()
Initialization1
do{
Initialization2
do{
statements 2;
Update 2;
}while(cond2);
statements 1;
Update 1;
}while(cond1)
j = 1
j = 2
j = 4
j = 5
j = 7
j = 8
j = 10
int z=20;
printf("%d n ",(x,y,z));
printf("%d n ",x,y,z);
}
Branshing
1. If
2. Nested if
3. If........else
4. If...............else if
5. Switch, case, break, default, continue
6. goto
IF
If(condition)
{ statements; }
Condition is ( > , < , >= , <= , == , != , && , || )
Note:
If((c%3==0)||(c%6==3)&&(c%9==0)) means .......... ?
Example :
scanf("%i", &i);
if(i > 0)
printf("a positive number was enteredn");
if(i < 0) {
printf("a negative number was enteredn");
i = -i;
}
note
Example:
X=10
If(x==10)
Printf(“x is equal 10”);
If(x>10)
Printf(“x is longer than 10”);
If(x<10)
Printf(“x is less than 10”);
Switch case
switch (expression) {
case expression1:
statement1;
case expression2:
statement2;
.
.
.
default:
statement-default;
}
Islam Nabil Mahmoud 20130890 31 Electrical&computers Dept Industrial Training 4 ITR 202
Nested if
If(cond1)
if(cond2)
if(cond3)
{
Statements;
}
If.........else
If(condition)
{
statements;
}
else
{
statements;
}
If.........else if
If(cond 1)
{statements;}
else if(cond 2)
{statements;}
else if(cond 3)
{statements;}
else
{statements;}
Example:
scanf(“%d”,&day);
switch (day){
case '1':
printf("Day 1n");
case '2':
printf("Day 2n");
case '3':
printf("Day 3n");
default:
printf("defaultn");
}
Break Statement with switch
the break statements help to exit the switch construct after the statement
in a selected case is executed.
Example :
switch (day){
case '1':
printf("Day 1n");
break;
case '2':
printf("Day 2n");
break;
default:
printf(“defaultn");
}
point out the error, if any, in the following program
main()
{
int i=4,j=2;
switch(i)
{
case 1: printf(“case 1”);
break;
case j: printf(“case 2”); X
break;
}
}
Function
Function is a series of instructions to run.
You pass Arguments to a function and it returns a Value.
main() is a Function. It’s only special because it always gets called first when you run your
program.
It can take no arguments
It can be don’t return any thing (Procedures)
Return_data_type function _name (input_arguments_list)
{
//////fun body
}
Function Example
int add(int x,int y){
int sum;
sum=x+y;
return sum;
}
int main(void){
int sum;
sum=add (4,5);
printf(“4+5=x”,sum);
return 0;
}
Islam Nabil Mahmoud 20130890 32 Electrical&computers Dept Industrial Training 4 ITR 202
x,y are Function Arguments
return value
Function call and passing 4,,5 to it
Calling a Function: printf() is just another function, like main() . It’s defined for you in a
“library”, a collection of functions you can call
from your program.
Prototypes
The (optional) line
int add(int , int ); // is known as a prototype
If the compiler meets a call to an unknown function it “guesses”
Guess 1: the function returns an int, even if it doesn’t
Guess 2: you have passed the correct number of parameters and made sure
they are all of the correct type, even if you haven’t
The prototype provides the compiler with important information about the
return type and parameters
Function types
1. Int Function
2. Float Function
3. String Function
4. Char Function
5. Void Function
6. Struct Function
Global variables
Global variables are created by placing the declaration outside all
functions
They are placed in the data segment
Initial value: 0
Initialization: unnecessary if you like zeros
#include <stdio.h>
double d;
int main(void)
{
printf(“%d”,d);
fun ();
printf(“%d”,d);
}
Static variables
The static keyword instructs the compiler to place a variable into the data
segment
The data segment is permanent (static)
A value left in a static in one call to a function will still be there at
the next
call
Initial value: 0
Initialization: unnecessary if you like zeros
Islam Nabil Mahmoud 20130890 33 Electrical&computers Dept Industrial Training 4 ITR 202
void fun (void)
{
d++;
}
Array
1. A collection of similar variables
2. Each element is of the same type
3. Has a fixed, unchangeable size
4. Accessing by index using [] bracks
How to declare array
Declaration:
data_type Array_Name[Array_Size];
example,
int arr_int[3];
Declaration and initialization :
data-type Array-Name[Array-Size];
example,
int arr_int[3]={1,2,3};
Or
int arr_int[3];
arr_int[0]=1;
arr_int[1]=2;
arr_int[2]=3;
Name address Value
0
1
2
3
arr_int[0] 4
arr_int[1] 5
arr_int[2] 6
7
8
Islam Nabil Mahmoud 20130890 34 Electrical&computers Dept Industrial Training 4 ITR 202
How array works?(one dimensional)
How
array
works?
(multi
dimensional)
String function
Strcmp();
Strlen();
Strcpy();
Strcat();
Islam Nabil Mahmoud 20130890 35 Electrical&computers Dept Industrial Training 4 ITR 202
Pointers
Introduction :
1. Main memory is a sequence of memory locations that are addressed 0, 1,
2,...
2. Pointers are variables that contain memory addresses as their values.
3. A pointer containing an address of some location is said to be a pointer to
that location.
Declarations
Examples of pointer declarations:
int *a;
float *b;
char *c;
Note:
1. format specifier for pointer is p
2. printf("ptr_y: address=0x%p, content=%dn“,ptr,* ptr)
3. Size of pointer is often 2-4 bytes (like size of int )depend on the memory size
Note
How to declare Pointer to integer?
How to declare Pointer to character?
A pointer may be incremented (++) or decremented (--).
An integer may be added to a pointer (+ or +=).
An integer may be subtracted from a pointer (- or -=).
One pointer may be subtracted from another. The result is equal to the
difference between the pointers values divided by data type size.
Pointer advantages
1. Return more than value from function
2. More efficient with array , string , structure.
3. More efficient with addresses
4. Can pass the address of struct ,array to function
Swap function
1. Swap two variables using
2. Reference
3. Pointer
4. Global variables
typedef
typedef int * pti ;
pti p[15];
pti is a pointer to an int
p is an array of 15 pointer to int
Islam Nabil Mahmoud 20130890 36 Electrical&computers Dept Industrial Training 4 ITR 202
structure
A structure is a collection of one of more variables grouped together under a single name for convenient handling The
variables in a structure are called members and may have any type, including arrays or other structures The steps are:
set-up a template (blueprint) to tell the compiler how to build the structure Use the template to create as many instances
of the structure as desired Access the members of an instance as desired
Creating Instances
struct Date
{
int day;
int month;
int year;
} today, tomorrow;
struct Date next_monday;
struct Date next_week[7];
Union
union U
{
short s;
long l;
double d;
char c;
} u;
u.s = 10;
u.l = 10L;
u.d = 10.01;
u.c = '1';
struct S
{
short s;
long l;
double d;
char c;
} s;
s.s = 10;
s.l = 10L;
s.d = 10.01;
s.c = '1';
Islam Nabil Mahmoud 20130890 37 Electrical&computers Dept Industrial Training 4 ITR 202
instances must be declared before the ‘;’ ...
or “struct Date” has to be repeated
an array of 7 date instances
Memory usage
Global data:
Declared outside all C functions
Visible to all C functions
Variables with static storage
Storage space allocated in data sections
Life time is from the start to the end of program execution
Local variables in stack:
Local variables of a function go into stack storage
Dynamically allocated and de-allocated every time the function is called
Variable life time is from the allocation to the deallocation
Stack Versus Heap
Stack: provides storage for local variables, alters size as the program
executes
Heap: “dynamic memory” the heap is available
for us to use and may alter size as the program executes
Dynamic memory Versus Arrays
Arrays
1. Have a fundamental problem – their size must be fixed when the program is
written
2. There is no way to increase (or decrease) the size of an array once the program
is compiled
3. Ex: int a[100];
Dynamic
1. Are different, their size is fixed at run time and may be changed as often as
required, Only a pointer is required
How to allocate
malloc()
#include <stdlib.h>
void *malloc(size_t size);
It return pointer to void
If no available size in memory then it return NULL so we must check it
before using it
free()
Islam Nabil Mahmoud 20130890 38 Electrical&computers Dept Industrial Training 4 ITR 202
Chapter 3 Data structure & Algorithms
Data structure is a particular way of organizing data in a computer so that it
can be used efficiently.
Data structure is a group of data elements grouped together under one
name. These data elements, known as members.
A data structure is a specialized format for organizing and storing data.
General data structure types include the array, the file, the record,
the table, the tree, and so on. Any data structure is designed to organize
data to suit a specific purpose so that it can be accessed and worked with
in appropriate ways. In computer programming, a data structure may be
selected or designed to store data for the purpose of working on it with
various algorithms.
Data structure :array , stack ,queue ,linked list ,binary tree, Hash table
Algorithm
Is a way of solution.
Is set of steps to achieve certain goal.
How to measure the algorithm :
By complexity is the number of steps to achieve certain goal [n --------> infinity].
Can use any programming lang. for implementation like C , C++, java ,.....
Linked list
Linked list is Like arrays, Linked List is a linear data structure. Unlike arrays,
linked list elements are not stored at contiguous location; the elements are
linked using pointers.
Why Linked List?
Arrays can be used to store linear data of similar types, but arrays have
following limitations.
1-The size of the arrays is fixed: So we must know the upper limit on the number of elements in advance. Also,
generally, the allocated memory is equal to the upper limit irrespective of the usage.
2-Inserting a new element in an array of elements is expensive, because room has to be created for the new elements
and to create room existing elements have to shifted
Array
Advantages over arrays
Dynamic size
Ease of insertion/deletion
Drawbacks:
Random access is not allowed. We have to access elements sequentially
starting from the first node. So we cannot do binary search with linked lists.
Islam Nabil Mahmoud 20130890 39 Electrical&computers Dept Industrial Training 4 ITR 202
Extra memory space for a pointer is required with each element of the list.
Double linked list
Doubly-linked list is a linked data structure that consists of a set of sequentially linked records called nodes. Each node
contains two fields, called links, that are references ‘pointers’ to the previous and to the next node in the sequence of
nodes.
Circular linked list
A circular linked list is a linked list in which the head element's previous
pointer points to the tail element and the tail element's next pointer points
to the head element. In the special case of a circular list with only one
element, the element's previous and next pointers point to itself, and it is
both the head and tail of the list.
Single linked list
Singly linked list each node in the list stores the contents of the node and a pointer or reference to the next node in the
list. It does not store any pointer or reference to the previous node. It is called a singly linked list because each node
only has a single link to another node. To store a single linked
list, you only need to store a reference or pointer to the first node in that list. The last node has a pointer to nothingness
to indicate that it is the last node
Islam Nabil Mahmoud 20130890 40 Electrical&computers Dept Industrial Training 4 ITR 202
Single linked list representation in C
A linked list is represented by a pointer to the first node of the linked list. The first
node is called head. If the linked list is empty, then value of head is NULL.
Each node in a list consists of at least two parts:
1. Data
2. pointer to the next node
In C, we can represent a node using structures. Below is an example of a linked
list node with an integer data.
struct node {
int data;
struct node *next;
};
Functions of linked list
Initlist()
Creatlist()
Insert_node()
Append_node()
Search_node()
Delete_node()
Destroy_node()
Isempty()
Stack
Is a structure records the chronological ordering of information. It is used
mainly in subroutine/function calls and interrupt servicing. A stack is LIFO
(last in, first out) structure
The address is always in the SP register and is automatically updated during a
push or pop instruction.
Stack
function
Pop()
Push()
Display()
Islam Nabil Mahmoud 20130890 41 Electrical&computers Dept Industrial Training 4 ITR 202
Sorting algorithm For each algorithm :
Idea of algorithm
Flow chart and pseudo code
Implementation of algorithm using C or any lang.
Sorting algorithm
Bubble sort
Selection sort
Searching algorithm
For each algorithm : Idea of algorithm
Flow chart and pseudo code
Implementation of algorithm using C or any lang.
Searching algorithm
Linear searching
Binary searching
Islam Nabil Mahmoud 20130890 42 Electrical&computers Dept Industrial Training 4 ITR 202
Cahpter 4 Computer Architecture
Computer Architecture
Is the arrangement of computer components and their relationships. The specification of the relation between parts of a
computer system. The theory behind the design of a computer.
History of Computers
Computers date back to 1946 with the first computer made by Eckert, and John Mauchly. It was built using vacuum
tubes. A computer is a programmable machine that receives input, stores
and automatically manipulates data, and provides output in a useful format.
Generations of computers :
Historically computers are classified into generations according to the technology used to build them Four generations
of computers exist
Generations of computers
First Generation (1946-1958) This generation relied on vacuum tubes to provide switching of electric current. Second
Generation (1959-1964) This generation relied on the transistor
to replace the vacuum tubes. Third Generation (1965-1970) This generation relied on Integrated
Circuits (IC) instead of transistors. Fourth Generation (1971-Today) This generation utilizes a microprocessor to
perform all the computation functionality in one integrated circuit (SOC).
Technology with computer
Technology is what changed and moved computers rapidly. Technological break throughs helped computers grow in
size and performance, it also shrunk the size and power requirements of
computers. Technological breakthroughs also helped to prove concepts that were difficult to implement at the time they
were suggested
Measurement of Computer Performance
Several measurements are needed to determine computer performance like:
1. Latency: “How long does it take for my job to run ?”
2. Throughput: “How many jobs can the machine execute at once?
3. Elapsed time: “How long does it take the machine to finish a certain job ?”
4. CPU time: “How much time did it take from the CPU to finish the job ?
We are basically focused on CPU time, and elapsed time throughout this course
Measurement of CPU Time
Many parameters contribute in computer performance, especially CPU time. These parameters include :
1. Processor clock frequency
2. Number of instructions executed per clock cycle
3. Details of what each instruction does (instruction set)
Measurement of Computer PerformanceBenchmarks :
1. is a set of tests performed on a computer system to measure computer performance and to compare this
Islam Nabil Mahmoud 20130890 43 Electrical&computers Dept Industrial Training 4 ITR 202
computer with other computers.
2. Benchmarks are usually synthetic programs that act as real life programs
3. Software benchmarks are run against compilers or database management systems.
Examples of benchmarks
1. Dhrystone: Focuses on integer arithmetic performance
2. Whetstone: Focuses on floating point arithmetic performance
3. SPEC: “Standard Performance Evaluation Corporation” Is a non-profit organization that aims to produce fair
and meaningful benchmarks for computers
In general, the best benchmark :
1. Is written in a high-level language, making it portable across different machines.
2. Is a representative of some programming style or applications (e.g. systems programming, numerical
programming, commercial programming).
3. Can be measured easily.
Computer Systems
Basic block diagram
Elements of the basic system
1. Microprocessor: perform all ALU operations.
2. Memory: Store operating program and data.
3. Input Devices: for user input.
4. Output Devices: Output results to the user.
5. Interfaces (Sub-systems): Making a conditioning for the data before
6. getting into or out from the input or output devices respectively.
7. Buses: Transfer data between system components.
Islam Nabil Mahmoud 20130890 44 Electrical&computers Dept Industrial Training 4 ITR 202
Key definitions
Motherboard:
The motherboard is a PCB that gathers together all the components of a computer system
Bus:
1. A bus, is a set of interconnection lines plus glue logic for transferring data between different components of a
computer system
2. A bus is characterized mainly by Bus bandwidth: The maximum amount of data it can transfer per second
3. Further parameters of a bus are:
Bus width : Number of bits that can be transferred in one clock cycle
Maximum bus Frequency: The maximum frequency that can be used to clock the bus
Motherboard
Islam Nabil Mahmoud 20130890 45 Electrical&computers Dept Industrial Training 4 ITR 202
Detailed block diagram for computer system
Buses types
Two types of buses: Interfacing buses:
These buses are standards used to interface a computer system to a set of peripherals using this bus standard.
1. ISA Bus
2. PCI Bus
3. IDE Bus
4. AGP Bus
5. USB Bus
Internal buses:
These buses are used to transfer data between the components of a computer system. They are internal to the system
itself, they may or may not be following a certain standard
1. Wishbone
2. AMBA
Islam Nabil Mahmoud 20130890 46 Electrical&computers Dept Industrial Training 4 ITR 202
ISA Bus ISA is Industry Standard
Architecture
1. One of the oldest busses in computer systems
2. It is used to connect peripheral cards to computer systems
3. It is16-bit wide.
4. Its bandwidth is 15.6 Mbytes/sec
5. Has simple addressing scheme, needs no special controller
PCI Bus
PCI Bus is Peripheral Component Interconnect.
1. Used to connect fast peripherals to computer systems
2. Faster and wider than ISA Bus
3. 64 Bit wide,max speed of 66 MHz
4. Bus bandwidth is 508.6 Mb/sec
5. Address bits and data bits are multiplexed.
IDE Bus
IDE Bus is used to connect computer systems to storage devices like hard drives and CD Drives
AGP Bus
AGP Bus (Accelerated Graphics Port)
1. This bus is dedicated to display and graphics peripherals It is 32 bits wide, 66 MHz fast
2. Bandwidth of 254.3 Mbytes/sec
3. AGP (x2 Mode) has 66 x 2 MHz speed
4. AGP (x4 Mode) has 66 x 4 MHz speed
USB Bus USB Bus (Universal Serial Bus)
1. It is different from the previous busses in the fact that it is a serial bus
2. It consists only of 4 wires
3. It is used for connecting slow to medium speed peripherals to computer systems
4. Supports data rates of 1.5, 12, and 480 Mbps
5. Supports hot swapping, and plug and play,
which makes USB peripherals popular for their ease of use
Internal Buses
1. Internal busses are less common than interfacing buses because they are hidden inside the computer system
Wishbone: This bus is an open source standard. It is made for open source components to interface with open source
Islam Nabil Mahmoud 20130890 47 Electrical&computers Dept Industrial Training 4 ITR 202
processors
AMBA: This bus is used for embedded systems, especially those using ARM microcontrollers. It was originally
designed by ARM ® Ltd.
CPU Structureny CPU is consisting of main components :
1. Data path :
ALU/FBU
Internal buses
Registers
2. Control Unit:
Hardwired control Unit
Micro-programmed control Unit
Processor Data-path
1. Processor data-path is the hardware part of the processor that performs the processing operations.
2. It is the main components of microprocessor that is responsible for performing the operation.
3. Processor data-path helps to understand how data is manipulated and helps define the tasks required from the
control unit
4. It also helps understand how data is transferred from one component of the processor to another component
Data path consists of three parts:
1. ALU/FBU
2. Internal buses
3. Registers
Islam Nabil Mahmoud 20130890 48 Electrical&computers Dept Industrial Training 4 ITR 202
Processor Data-path
CPU Structure
The basic elements of the CPU are:
1. ALU
Arithmetic & Logic Unit
Responsible for performing logic and arithmetic calculations
2. Floating-Point Unit (FPU)
performs arithmetic operations on floating point numbers
3. Registers
Registers are used to store data beside the ALU
Registers are used to transfer data to/from memory
Registers carry the inputs of ALU, as well as, receiving the output of the ALU
4. Internal CPU Bus
It is a special bus
It is responsible for transferring data between registers, ALU, and system memory
5. Control Unit It is responsible for organizing the actions of the CPU components It can be thought of as the
heart of the CPU
ALU
1. A & B are inputs of the ALU
2. Control input: Selects the required functionality to be done on A (& B)
Islam Nabil Mahmoud 20130890 49 Electrical&computers Dept Industrial Training 4 ITR 202
3. Output: Output of the operation performed on operands
4. Flags: Indicate status of last arithmetic & logic operations performed in the
ALU (E.g. zero flag, overflow flag, sign flag)
FPU
1. Similar to the ALU is the Floating-Point Unit, or FPU. The FPU performs arithmetic operations on floating
point numbers.
2. An FPU is complicated to design, although the IEEE 754 standard helps to answer some of the specific
questions about implementation.
3. It isn't always necessary to follow the IEEE standard when designing an FPU, but it certainly does help.
CPU Registers
CPU Registers are classified into two main categories :
1. User-visible registers
2. Control and status registers
User-visible registers
These are registers that are visible to the programmer to use for programming the processor.
They are further categorized as follows:
1. General purpose: Used by programmer to store data, or perform operations on them (R0,R1,...,R31)
2. Data Registers: Can be used for storage/retrieval of data only, not for operations(instructions)
3. Address Registers: They are dedicated for storing addresses specific to memory operations frequently
required
4. Examples are: Stack pointer register& Segment pointer register
5. Condition Codes Registers: They are flags that are set by the CPU as a result of logic and arithmetic
operations. Examples are: CCR or PSW register.
Control and Status Registers
These are a set of essential registers for proper operation. They are usually not visible to the programmer, although
some of them are so. Examples are:
1. Program Counter (PC): Contains the address of the instruction to be fetched.
2. Instruction Register (IR): Contains the instruction most recently fetched.
3. Memory address register (MAR): Contains the address of the location in the memory to be fetched/stored
4. Memory buffer register (MBR): Contains the data to be loaded/stored in the memory
Islam Nabil Mahmoud 20130890 50 Electrical&computers Dept Industrial Training 4 ITR 202
Final
Final
Final
Final
Final
Final
Final
Final
Final
Final
Final
Final
Final
Final
Final
Final
Final
Final
Final
Final
Final
Final
Final
Final
Final
Final
Final
Final
Final
Final

More Related Content

What's hot

Chapter 8 Embedded Hardware Design and Development (second portion)
Chapter 8 Embedded Hardware Design and Development (second portion)Chapter 8 Embedded Hardware Design and Development (second portion)
Chapter 8 Embedded Hardware Design and Development (second portion)Moe Moe Myint
 
Wireless charger for_low_power_devices_ excellent one same
Wireless charger for_low_power_devices_ excellent one sameWireless charger for_low_power_devices_ excellent one same
Wireless charger for_low_power_devices_ excellent one sameIbrahim Khleifat
 
Electronic Pen and CNC Machine Survey
Electronic Pen and CNC Machine SurveyElectronic Pen and CNC Machine Survey
Electronic Pen and CNC Machine SurveyIRJET Journal
 
Introduction to Embedded Systems I : Chapter 1
Introduction to Embedded Systems I : Chapter 1Introduction to Embedded Systems I : Chapter 1
Introduction to Embedded Systems I : Chapter 1Moe Moe Myint
 
Report it department concord(retyped)
Report it department concord(retyped)Report it department concord(retyped)
Report it department concord(retyped)Arefin Rahman
 
Training Report on embedded Systems and Robotics
Training Report on embedded  Systems and RoboticsTraining Report on embedded  Systems and Robotics
Training Report on embedded Systems and RoboticsNIT Raipur
 
Training Report on Embedded System
Training Report on Embedded SystemTraining Report on Embedded System
Training Report on Embedded SystemRoshan Mani
 
Chapter 4 Embedded System: Application and Domain Specific
Chapter 4 Embedded System: Application and Domain SpecificChapter 4 Embedded System: Application and Domain Specific
Chapter 4 Embedded System: Application and Domain SpecificMoe Moe Myint
 
Design and fabrication of automation for stapling of wooden supports to corru...
Design and fabrication of automation for stapling of wooden supports to corru...Design and fabrication of automation for stapling of wooden supports to corru...
Design and fabrication of automation for stapling of wooden supports to corru...eSAT Journals
 
Low-cost and portable automatic sheet cutter
Low-cost and portable automatic sheet cutterLow-cost and portable automatic sheet cutter
Low-cost and portable automatic sheet cutterIJECEIAES
 
IRJET-Intelligent Saw Cutter
IRJET-Intelligent Saw CutterIRJET-Intelligent Saw Cutter
IRJET-Intelligent Saw CutterIRJET Journal
 
Introduction to Embedded System: Chapter 2 (4th portion)
Introduction to Embedded System:  Chapter 2 (4th portion)Introduction to Embedded System:  Chapter 2 (4th portion)
Introduction to Embedded System: Chapter 2 (4th portion)Moe Moe Myint
 

What's hot (15)

Chapter 8 Embedded Hardware Design and Development (second portion)
Chapter 8 Embedded Hardware Design and Development (second portion)Chapter 8 Embedded Hardware Design and Development (second portion)
Chapter 8 Embedded Hardware Design and Development (second portion)
 
Wireless charger for_low_power_devices_ excellent one same
Wireless charger for_low_power_devices_ excellent one sameWireless charger for_low_power_devices_ excellent one same
Wireless charger for_low_power_devices_ excellent one same
 
Electronic Pen and CNC Machine Survey
Electronic Pen and CNC Machine SurveyElectronic Pen and CNC Machine Survey
Electronic Pen and CNC Machine Survey
 
Introduction to Embedded Systems I : Chapter 1
Introduction to Embedded Systems I : Chapter 1Introduction to Embedded Systems I : Chapter 1
Introduction to Embedded Systems I : Chapter 1
 
Report it department concord(retyped)
Report it department concord(retyped)Report it department concord(retyped)
Report it department concord(retyped)
 
Training Report on embedded Systems and Robotics
Training Report on embedded  Systems and RoboticsTraining Report on embedded  Systems and Robotics
Training Report on embedded Systems and Robotics
 
Training Report on Embedded System
Training Report on Embedded SystemTraining Report on Embedded System
Training Report on Embedded System
 
Chapter 4 Embedded System: Application and Domain Specific
Chapter 4 Embedded System: Application and Domain SpecificChapter 4 Embedded System: Application and Domain Specific
Chapter 4 Embedded System: Application and Domain Specific
 
Design and fabrication of automation for stapling of wooden supports to corru...
Design and fabrication of automation for stapling of wooden supports to corru...Design and fabrication of automation for stapling of wooden supports to corru...
Design and fabrication of automation for stapling of wooden supports to corru...
 
Gx3512131216
Gx3512131216Gx3512131216
Gx3512131216
 
Low-cost and portable automatic sheet cutter
Low-cost and portable automatic sheet cutterLow-cost and portable automatic sheet cutter
Low-cost and portable automatic sheet cutter
 
IRJET-Intelligent Saw Cutter
IRJET-Intelligent Saw CutterIRJET-Intelligent Saw Cutter
IRJET-Intelligent Saw Cutter
 
LBprofibusDP eng
LBprofibusDP engLBprofibusDP eng
LBprofibusDP eng
 
Introduction to Embedded System: Chapter 2 (4th portion)
Introduction to Embedded System:  Chapter 2 (4th portion)Introduction to Embedded System:  Chapter 2 (4th portion)
Introduction to Embedded System: Chapter 2 (4th portion)
 
Vinod cover 1
Vinod cover 1Vinod cover 1
Vinod cover 1
 

Similar to Final

btech embedded systems ppt ES UNIT-1.pptx
btech embedded systems ppt ES UNIT-1.pptxbtech embedded systems ppt ES UNIT-1.pptx
btech embedded systems ppt ES UNIT-1.pptxSattiBabu16
 
final report (parking project).pdf
final report (parking project).pdffinal report (parking project).pdf
final report (parking project).pdfgamefacegamer
 
final project report_full edit
final project report_full editfinal project report_full edit
final project report_full editSayam Roy
 
Embedded system (Chapter 1)
Embedded system (Chapter 1)Embedded system (Chapter 1)
Embedded system (Chapter 1)Ikhwan_Fakrudin
 
EMBEDDED SYSTEMS.pptx
EMBEDDED SYSTEMS.pptxEMBEDDED SYSTEMS.pptx
EMBEDDED SYSTEMS.pptxssuser2d3a09
 
My thesis work on Cognitive automation of Electric appliances
My thesis work on Cognitive automation of Electric appliancesMy thesis work on Cognitive automation of Electric appliances
My thesis work on Cognitive automation of Electric appliancesAkhil Reddy Rondla
 
Report on Enviorment Panel Monitoring
Report on Enviorment Panel MonitoringReport on Enviorment Panel Monitoring
Report on Enviorment Panel MonitoringMohammed Irshad S K
 
Lecture 1 PPT - Introduction to Embedded Systems.pptx
Lecture 1 PPT - Introduction to Embedded Systems.pptxLecture 1 PPT - Introduction to Embedded Systems.pptx
Lecture 1 PPT - Introduction to Embedded Systems.pptxcronydeva
 
IRJET- A Remotely Controlled Home Automation System for Energy Saving
IRJET-  	  A Remotely Controlled Home Automation System for Energy SavingIRJET-  	  A Remotely Controlled Home Automation System for Energy Saving
IRJET- A Remotely Controlled Home Automation System for Energy SavingIRJET Journal
 
IRJET- Monitoring and Control of PLC based Automation System Parameters using...
IRJET- Monitoring and Control of PLC based Automation System Parameters using...IRJET- Monitoring and Control of PLC based Automation System Parameters using...
IRJET- Monitoring and Control of PLC based Automation System Parameters using...IRJET Journal
 
Pdfslide.net summer training-report-on-plc-and-scada11
Pdfslide.net summer training-report-on-plc-and-scada11Pdfslide.net summer training-report-on-plc-and-scada11
Pdfslide.net summer training-report-on-plc-and-scada11GondaliyaAkashkumar
 
Truyen thong
Truyen thongTruyen thong
Truyen thongTan Ngoc
 
shibu KV_ intro slides on embedded systems.pdf
shibu KV_ intro slides on embedded systems.pdfshibu KV_ intro slides on embedded systems.pdf
shibu KV_ intro slides on embedded systems.pdflekha349785
 
PLC based home automation (undergrad thesis)
PLC based home automation (undergrad thesis)PLC based home automation (undergrad thesis)
PLC based home automation (undergrad thesis)Sameer Patel
 
Get the most out of your PC Investment
Get the most out of your PC InvestmentGet the most out of your PC Investment
Get the most out of your PC InvestmentKorcan Erguder
 

Similar to Final (20)

azeem final iot report.docx
azeem final iot report.docxazeem final iot report.docx
azeem final iot report.docx
 
btech embedded systems ppt ES UNIT-1.pptx
btech embedded systems ppt ES UNIT-1.pptxbtech embedded systems ppt ES UNIT-1.pptx
btech embedded systems ppt ES UNIT-1.pptx
 
final report (parking project).pdf
final report (parking project).pdffinal report (parking project).pdf
final report (parking project).pdf
 
final project report_full edit
final project report_full editfinal project report_full edit
final project report_full edit
 
Report (2)
Report (2)Report (2)
Report (2)
 
Embedded system (Chapter 1)
Embedded system (Chapter 1)Embedded system (Chapter 1)
Embedded system (Chapter 1)
 
EMBEDDED SYSTEMS.pptx
EMBEDDED SYSTEMS.pptxEMBEDDED SYSTEMS.pptx
EMBEDDED SYSTEMS.pptx
 
My thesis work on Cognitive automation of Electric appliances
My thesis work on Cognitive automation of Electric appliancesMy thesis work on Cognitive automation of Electric appliances
My thesis work on Cognitive automation of Electric appliances
 
Report on Enviorment Panel Monitoring
Report on Enviorment Panel MonitoringReport on Enviorment Panel Monitoring
Report on Enviorment Panel Monitoring
 
Industrial Automation
Industrial Automation Industrial Automation
Industrial Automation
 
Lecture 1 PPT - Introduction to Embedded Systems.pptx
Lecture 1 PPT - Introduction to Embedded Systems.pptxLecture 1 PPT - Introduction to Embedded Systems.pptx
Lecture 1 PPT - Introduction to Embedded Systems.pptx
 
IRJET- A Remotely Controlled Home Automation System for Energy Saving
IRJET-  	  A Remotely Controlled Home Automation System for Energy SavingIRJET-  	  A Remotely Controlled Home Automation System for Energy Saving
IRJET- A Remotely Controlled Home Automation System for Energy Saving
 
IRJET- Monitoring and Control of PLC based Automation System Parameters using...
IRJET- Monitoring and Control of PLC based Automation System Parameters using...IRJET- Monitoring and Control of PLC based Automation System Parameters using...
IRJET- Monitoring and Control of PLC based Automation System Parameters using...
 
Pdfslide.net summer training-report-on-plc-and-scada11
Pdfslide.net summer training-report-on-plc-and-scada11Pdfslide.net summer training-report-on-plc-and-scada11
Pdfslide.net summer training-report-on-plc-and-scada11
 
Truyen thong
Truyen thongTruyen thong
Truyen thong
 
shibu KV_ intro slides on embedded systems.pdf
shibu KV_ intro slides on embedded systems.pdfshibu KV_ intro slides on embedded systems.pdf
shibu KV_ intro slides on embedded systems.pdf
 
Plc & scada report 2
Plc & scada report 2Plc & scada report 2
Plc & scada report 2
 
PLC based home automation (undergrad thesis)
PLC based home automation (undergrad thesis)PLC based home automation (undergrad thesis)
PLC based home automation (undergrad thesis)
 
UG 2016 Final Project.pdf
UG 2016 Final Project.pdfUG 2016 Final Project.pdf
UG 2016 Final Project.pdf
 
Get the most out of your PC Investment
Get the most out of your PC InvestmentGet the most out of your PC Investment
Get the most out of your PC Investment
 

More from Islam Nabil

More from Islam Nabil (10)

Resume islam-nabil
Resume islam-nabilResume islam-nabil
Resume islam-nabil
 
Islam CV
Islam CV Islam CV
Islam CV
 
Resume 2018
Resume 2018Resume 2018
Resume 2018
 
Resume 2018
Resume 2018Resume 2018
Resume 2018
 
Ros rov talk
Ros rov talk Ros rov talk
Ros rov talk
 
ROS ROV AUV
ROS ROV AUVROS ROV AUV
ROS ROV AUV
 
Islam Bio
Islam Bio Islam Bio
Islam Bio
 
Intro to linux
Intro to linux Intro to linux
Intro to linux
 
Resume
ResumeResume
Resume
 
emb
embemb
emb
 

Recently uploaded

04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 

Recently uploaded (20)

04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 

Final

  • 1. Higher technology institute Electrical & computers Dept Report on / Embedded System Industrial training / ITR 202 Submitted to : Examiners Committee Submitted by : Name / Islam nabil mahmoud mohamed ID / 20130890 Supervised by : Dr / Mohamed Ali Torad ( HTI ) May- August 2017 Islam Nabil Mahmoud 20130890 1 Electrical&computers Dept Industrial Training 4 ITR 202
  • 2. Abstract Embedded system & Its Application Microcontrollers System on chip System on board Difference Between Microprocessor and Microcontroller Microcontroller CPU architectures Memory unit Types Of Real Time Systems Simulator vs. Emulator C programming Data structure & Algorithms Computer Architecture Labs Islam Nabil Mahmoud 20130890 2 Electrical&computers Dept Industrial Training 4 ITR 202
  • 3. Detailed Content Chapter 1 Introduction to Embedded system........................................................................................................................8 Embedded systems applications...........................................................................................................................................8 General Purpose Processors................................................................................................................................................10 Embedded general purpose Processors...............................................................................................................................10 Digital signal processors.....................................................................................................................................................10 Microcontrollers.................................................................................................................................................................10 Software characteristics......................................................................................................................................................10 Hardware characteristics.....................................................................................................................................................11 System on board..................................................................................................................................................................11 System on chip....................................................................................................................................................................11 Advanced Embedded System.............................................................................................................................................11 Difference Between Microprocessor and Microcontroller.................................................................................................12 Microcontroller...................................................................................................................................................................12 Microcontroller...................................................................................................................................................................12 Microcontroller main components......................................................................................................................................13 Serial communication in ATmega32...................................................................................................................................13 Microprocessor...................................................................................................................................................................13 CPU Structure.....................................................................................................................................................................14 ALU....................................................................................................................................................................................14 FPU.....................................................................................................................................................................................14 Microcontroller CPU architectures.....................................................................................................................................14 Von Neumann architecture.................................................................................................................................................15 Harvard Architecture..........................................................................................................................................................15 CPU main registers.............................................................................................................................................................16 Stack pointer.......................................................................................................................................................................16 Program counter.................................................................................................................................................................16 Processor status word/condition code register (PSW ).......................................................................................................16 Memory unit.......................................................................................................................................................................17 RAM memory (Random Access Memory).........................................................................................................................17 RAM Types.........................................................................................................................................................................18 Stack...................................................................................................................................................................................18 Read Only Memory (ROM)...............................................................................................................................................18 OTP ROM (One Time Programmable ROM):...................................................................................................................18 Masked ROM.....................................................................................................................................................................18 UV EPROM........................................................................................................................................................................19 EEPROM memory (Electrically Erasable Programmable ROM) :....................................................................................19 Flash memory.....................................................................................................................................................................19 ROM contents.....................................................................................................................................................................19 Software..............................................................................................................................................................................19 What is a Program?.............................................................................................................................................................20 Memory Addressing :.........................................................................................................................................................20 Machine Language :...........................................................................................................................................................20 Simulator vs. Emulator.......................................................................................................................................................20 Software Process Activities................................................................................................................................................20 Software Costs....................................................................................................................................................................20 Real-time operating system (RTOS)...................................................................................................................................21 Types Of Real Time Systems..............................................................................................................................................21 OS basic Concepts..............................................................................................................................................................21 Servicing Interrupts............................................................................................................................................................22 Islam Nabil Mahmoud 20130890 3 Electrical&computers Dept Industrial Training 4 ITR 202
  • 4. Vectored Arbitration System :.............................................................................................................................................22 Non-Vectored Priority System :..........................................................................................................................................22 Chapter 2 C programming..........................................................................................................................................23 Introduction about programming lang........................................................................................................................23 Advantage of C programming....................................................................................................................................25 What is OS. ?..............................................................................................................................................................25 What is file.exe?.........................................................................................................................................................25 Assembly lang............................................................................................................................................................25 Assembler...................................................................................................................................................................26 Linear and structuration programming.......................................................................................................................26 Structuration programming........................................................................................................................................26 IDE (integrated development environment)...............................................................................................................26 Compiler:....................................................................................................................................................................26 Error types..................................................................................................................................................................26 Memory......................................................................................................................................................................27 1 st program................................................................................................................................................................28 Variables.....................................................................................................................................................................28 Data Types..................................................................................................................................................................28 Data types...................................................................................................................................................................29 How to declare a variable ?........................................................................................................................................29 Variable/functions names...........................................................................................................................................29 Variable declaration....................................................................................................................................................30 Printing out variables.................................................................................................................................................30 Example 1...................................................................................................................................................................30 Constants....................................................................................................................................................................30 Operators....................................................................................................................................................................30 Input variables............................................................................................................................................................31 Precedence..................................................................................................................................................................31 Casting........................................................................................................................................................................32 Input function.............................................................................................................................................................33 Output functional........................................................................................................................................................33 Loops..........................................................................................................................................................................33 Nested For..................................................................................................................................................................34 Continue.....................................................................................................................................................................35 Branshing...................................................................................................................................................................35 Switch case.................................................................................................................................................................36 Function......................................................................................................................................................................37 Prototypes...................................................................................................................................................................37 Function types............................................................................................................................................................38 Global variables..........................................................................................................................................................38 Static variables...........................................................................................................................................................38 Array...........................................................................................................................................................................39 How to declare array..................................................................................................................................................39 How array works?(one dimensional).........................................................................................................................40 String function............................................................................................................................................................41 Pointers.......................................................................................................................................................................41 Declarations................................................................................................................................................................41 Pointer advantages......................................................................................................................................................42 Swap function.............................................................................................................................................................42 typedef........................................................................................................................................................................42 structure......................................................................................................................................................................42 Union..........................................................................................................................................................................42 Memory usage............................................................................................................................................................43 Stack Versus Heap......................................................................................................................................................43 Dynamic memory Versus Arrays................................................................................................................................44 How to allocate...........................................................................................................................................................44 Chapter 3 Data structure & Algorithms.............................................................................................................45 Algorithm...........................................................................................................................................................45 Islam Nabil Mahmoud 20130890 4 Electrical&computers Dept Industrial Training 4 ITR 202
  • 5. Linked list..........................................................................................................................................................45 Why Linked List?..............................................................................................................................................46 Array..................................................................................................................................................................46 Double linked list...............................................................................................................................................46 Circular linked list.............................................................................................................................................47 Single linked list................................................................................................................................................47 Single linked list representation in C.................................................................................................................47 Functions of linked list......................................................................................................................................47 Stack...................................................................................................................................................................48 Sorting algorithm For each algorithm :..............................................................................................................48 Sorting algorithm...............................................................................................................................................48 Searching algorithm...........................................................................................................................................48 Searching algorithm...........................................................................................................................................49 Cahpter 4 Computer Architecture......................................................................................................................50 Computer Architecture.......................................................................................................................................50 History of Computers.........................................................................................................................................50 Generations of computers :................................................................................................................................50 Technology with computer................................................................................................................................51 Measurement of Computer Performance...........................................................................................................51 Measurement of CPU Time...............................................................................................................................51 Measurement of Computer PerformanceBenchmarks :.....................................................................................51 Examples of benchmarks...................................................................................................................................51 Computer Systems.............................................................................................................................................52 Basic block diagram...........................................................................................................................................52 Elements of the basic system.............................................................................................................................52 Key definitions...................................................................................................................................................52 Motherboard:.....................................................................................................................................................52 Bus:....................................................................................................................................................................52 Detailed block diagram for computer system....................................................................................................54 Buses types........................................................................................................................................................54 ISA Bus ISA is Industry Standard Architecture................................................................................................55 PCI Bus..............................................................................................................................................................55 IDE Bus..............................................................................................................................................................55 AGP Bus............................................................................................................................................................55 USB Bus USB Bus (Universal Serial Bus)........................................................................................................55 Internal Buses....................................................................................................................................................56 CPU Structureny CPU is consisting of main components :...............................................................................56 Processor Data-path...........................................................................................................................................56 Processor Data-path...........................................................................................................................................58 CPU Structure....................................................................................................................................................58 ALU...................................................................................................................................................................58 FPU....................................................................................................................................................................59 CPU Registers....................................................................................................................................................59 User-visible registers.........................................................................................................................................59 Control and Status Registers..............................................................................................................................59 Control Unit.......................................................................................................................................................61 Program execution.............................................................................................................................................61 Instruction cycle.................................................................................................................................................61 Two design of control units................................................................................................................................62 Hardwired control unit.......................................................................................................................................62 Micro-programmed control unit Example of micro-programmed control unit.................................................63 Instruction Set Architecture (ISA).....................................................................................................................64 Registers.............................................................................................................................................................64 The instruction set architecture elements...........................................................................................................65 Addressing modes of instructions......................................................................................................................65 Addressing modes types....................................................................................................................................66 Addressing modes..............................................................................................................................................68 Memory architecture..........................................................................................................................................68 Islam Nabil Mahmoud 20130890 5 Electrical&computers Dept Industrial Training 4 ITR 202
  • 6. Interrupt handling..............................................................................................................................................68 I/O Handling......................................................................................................................................................68 Intel IA32 Architecture......................................................................................................................................69 Pipelining...........................................................................................................................................................69 Single Cycle Processor (No Pipelining)............................................................................................................69 Multiple Cycle Processor...................................................................................................................................70 Advantages of Multiple Cycle Processor...........................................................................................................70 Five Stage Pipelining.........................................................................................................................................71 Load instruction five Stage................................................................................................................................72 Limitation to Pipelining.....................................................................................................................................73 Structural Hazards..............................................................................................................................................73 Structural Hazards..............................................................................................................................................74 Structural hazards..............................................................................................................................................74 Data hazards.......................................................................................................................................................74 Solutions for data hazards include hardware and software methods.................................................................75 Branch hazards...................................................................................................................................................75 Solutions to Branch Hazards..............................................................................................................................75 Pipelining and RISC..........................................................................................................................................75 Memory Types...................................................................................................................................................76 Memory management........................................................................................................................................76 Memory Management Unit................................................................................................................................76 Paged and Cash Technique................................................................................................................................77 Bus arbitration Operation:.................................................................................................................................77 Bank switching..................................................................................................................................................78 Memory protection............................................................................................................................................78 Super Scalar VS Vector Processor.....................................................................................................................78 Multiple Functional Units..................................................................................................................................79 Gantt Chart of a Super Scalar............................................................................................................................80 Instruction Issue Policy......................................................................................................................................80 Limitations.........................................................................................................................................................80 Instruction Level Parallelism (ILP):..................................................................................................................80 Limitations.........................................................................................................................................................80 Vector Processor................................................................................................................................................81 Conceptual View................................................................................................................................................81 Architecture.......................................................................................................................................................81 Semantic advantage...........................................................................................................................................82 Disadvantages....................................................................................................................................................82 Conclusion.........................................................................................................................................................82 Chapter 5 interfacing.........................................................................................................................................83 lab 1....................................................................................................................................................................83 4 swiches pull up with 7 seg..............................................................................................................................83 lab 2....................................................................................................................................................................84 7seg....................................................................................................................................................................84 lab 3....................................................................................................................................................................85 7seg-BCD...........................................................................................................................................................85 lab 4....................................................................................................................................................................86 led paraghraph....................................................................................................................................................86 lab 5 multipressing............................................................................................................................................87 lab 6....................................................................................................................................................................88 single pressing flag............................................................................................................................................88 lab 7....................................................................................................................................................................89 single pressing while..........................................................................................................................................89 lab 8....................................................................................................................................................................90 ext interrupt 0....................................................................................................................................................90 lab 9....................................................................................................................................................................91 ext inter 1...........................................................................................................................................................91 lab 10..................................................................................................................................................................93 ADC...................................................................................................................................................................93 Islam Nabil Mahmoud 20130890 6 Electrical&computers Dept Industrial Training 4 ITR 202
  • 7. lab 11..................................................................................................................................................................94 pwm...................................................................................................................................................................94 lab 12..................................................................................................................................................................96 timer...................................................................................................................................................................96 lab 13..................................................................................................................................................................97 password............................................................................................................................................................97 Refrences :-......................................................................................................................................................100 Islam Nabil Mahmoud 20130890 7 Electrical&computers Dept Industrial Training 4 ITR 202
  • 8. Chapter 1 Introduction to Embedded system Embedded systems: All systems that contain one or more processor to do specific functionalities and give responses upon receiving inputs. This processor is not general purposes like general purpose Processor in PC’s and notebooks. Embedded systems are computing systems with tightly coupled hardware and software integration, that are designed to perform a dedicated function. systems are usually an integral part of a larger system, known as the embedding system. Multiple embedded systems can coexist in an embedding system. Embedded systems applications Communication: Mobile Handsets, switches, routers ...etc. Image processing and consumers: Audio, video, cameras, printers, Mpeg-2 decoder, Mp3 and Mp4 players, PlayStation...etc. Automotive: Motor Engines, Climate control...etc. Appliances: Microwave, washing Machines. Automotive Telecommunication Electronic devices Computers Home automation Industrial Military Solar systems Aviation technology Banking Robotics. Aircraft electronics. Cinema industry Medical equipment Wearable technologies Mobile phones Automotive Lightning system Air bags ABS Parking system Computers Sound cards Ethernet cards Graphic cards Modem cards TV and satellite cards Electric devices Washing machines Microwave ovens Water heater Dishes washing machine Frigidaire Air conditioner TV , LCD, LED and satellite receiver Home automation Lightening systems Audio and home theater sound systems Controlling Temperature and humidity levels inside the house Automatic doors (rooms, garage ..etc) Industrial Factories huge robotic arms which assemble car components or any other machine Military Tanks shooting systems Submarines SONAR systems Missiles and target identification systems Islam Nabil Mahmoud 20130890 8 Electrical&computers Dept Industrial Training 4 ITR 202
  • 9. Telecommunications Mobile generations implementation : 3G and LTE Network : Wi-Fi chips, Routers and Switches Aviation and aerospace technology Airplane Navigation systems ,GPS systems Robotics Robots for any purpose ( home aid, industrial, playing, security .. etc. ) Banking Money counting machine ,ATMs Cinema industry Cameras ,Theaters , Motion effects Medical equipment and technologies ECG is a diagnostic tool that measures and records the electrical activity of the heart Ultrasound Fitness devices Cardiac peacemaker Wearable Google Glasses Smart watches Temperature adjustable clothes Mobile Smart phones Tablets IPAD General Purpose Processors 32 or 64-bit data path. Central processing engine of a mainframe, workstation, PC, RISC and CISC engines. examples: X86, PowerPC, SPARC, Pentium. Complex in design because these processors provide a full scale of features and a wide spectrum of functionalities. Modern processors have: Built-in memory management unit (MMU) to provide memory protection and virtual memory for multitasking-capable. General-purpose operating systems. Have advanced cache logic. Built-in math co-processor capable of performing fast floating-point operations. These processors result in large power consumption, heat production, and size. Embedded general purpose Processors Designed for a wide range of application (consumer and communication) 16/32-bit data path Limited functionality depends on the application Not Flashable i.e. the program memory is external and have CASH memory and MMU and support Extended memory Have main peripherals Like Timers , Ethernet , USP. Usually integrated into larger dedicated systems in a SoC (System on Chip) examples: ARM, PowerPC, MIPS, 68K, x86. ARM has seized the lion’s share of the market. Islam Nabil Mahmoud 20130890 9 Electrical&computers Dept Industrial Training 4 ITR 202
  • 10. Digital signal processors Like embedded general-purpose but Focus on the very efficient execution of arithmetic operations. DSP has : specialized arithmetic units, optimized design in the memory, addressing and bus architectures with multiprocessing capability that allow the DSP to perform complex calculations extremely fast in real time. Used widely in digital signal processing in communications systems such as Cell phones and Image and video processing Examples: TI (Texas Instruments), Motorola. TI has been the dominant player in the DSP market for several years. Microcontrollers The workhorse of industrial electronics. Designed for standalone operation. Include processing unit 8-bit, 16-bit, 32-bit. Included memories (RAM, ROM), IO, buses and peripherals depending on the application designed for (LIN , CAN , Ethernet , I2C , SPI and ..). Many micro controllers are descendants of successful architectures from the 8-bit and 16-bit microprocessor generations. Software characteristics Highly configurable. Shorter development cycle. Easier in versions updates. Cheaper. Hardware characteristics Longer development cycle. Customized for specific application. Better performance in high speed real time application. Long term SW. is more expensive than HW. because of maintenance. System on board Level 1: external discrete hardware component on board(SoB) Islam Nabil Mahmoud 20130890 10 Electrical&computers Dept Industrial Training 4 ITR 202
  • 11. System on chip Level 2: hardware integrated with CPU on chip (SoC). Level 3: done by software running on CPU (VHDL). Advanced Embedded System Multi-core system on chip like mobile handset which has one chip contains: 1. DSP processor 2. Embedded processors like ARM 3. Custom hardware for GSM 4. Custom peripherals for board interface (keyboard, touch screen, memory card interface). Network of embedded microcontrollers on board : Many microcontrollers on one / many board(s) communicated together through specific bus protocol like LIN bus, CAN bus in automotive application Difference Between Microprocessor and Microcontroller Essentially these two devices are similar, but with a little bit difference. A microcontroller is not the same as a microprocessor. A microprocessor is a single chip CPU used within other computer systems. A microcontroller is itself a single chip computer system. Microcontroller Microcontroller is single chip device or single chip computer in a small size that its resources are far more limited than those of a desktop personal computer. Microcontrollers don’t work alone in the circuit it must interfaces with other on chip devices. Islam Nabil Mahmoud 20130890 11 Electrical&computers Dept Industrial Training 4 ITR 202
  • 12. Microcontroller A microcontroller is a single chip, self-contained computer which incorporates all the basic components of a personal computer on a much smaller scale. Microcontrollers are often referred to as single chip devices or single chip computers. The main consequence of the microcontroller’s small size is that its resources are far more limited than those of a desktop personal computer. Microcontrollers are typically used as embedded controllers where they control part of a larger system such as an appliance, automobile, scientific instrument or a computer peripheral. Microcontrollers are designed to be low cost solutions therefore using them can reduces costs for a project. The microcontroller can accept inputs from some devices and provide outputs to other devices within any given system. For example, a microcontroller may accept input from a switch and may send output to an LED. If the switch is pressed the microcontroller can be instructed to illuminate the LED. Microcontroller main components A microcontroller has eight main components: Central processing unit (CPU) Input and Output (GPIO general purpose I/O or DIO) ROM RAM Timer Interrupt circuitry Buses Watchdog Serial communication in ATmega32 Uart is Universal Asynchronous Receiver/Transmitter , SPI is Serial Peripheral Interface , I2C is Two wires integrated circuits Microprocessor Microprocessor is a single chip used within other computer systems Is a typical Personal Computer where devices are attached to the CPU, using hard-wired connections which makes the system more flexible. can add more memory, change capacity of hard drives, add or remove CD-ROMs, sound card. CPU does all the computing: it fetches, decodes and executes program instructions and directs the flow of data to and from memory. The CPU performs the calculations required by program instructions and places the results of these calculations, if required, into memory space. Example like picture Islam Nabil Mahmoud 20130890 12 Electrical&computers Dept Industrial Training 4 ITR 202
  • 13. CPU Structure The basic elements of the CPU are: ALU Arithmetic & Logic Unit Responsible for performing logic and arithmetic calculations Floating-Point Unit (FPU) performs arithmetic operations on floating point numbers Registers Registers are used to store data beside the ALU ,Registers are used to transfer data to/from memory , Registers carry the inputs of ALU, as well as, receiving the output of the ALU Internal CPU Bus It is a special bus It is responsible for transferring data between registers, ALU, and system memory Control Unit It is responsible for organizing the actions of the CPU. It can be thought of as the heart of the CPU ALU A & B are inputs of the ALU Control input: Selects the required functionality to be done on A (& B) Output: Output of the operation performed on operands Flags: Indicate status of last arithmetic & logic operations performed in the ALU (E.g. zero flag, overflow flag, sign flag) FPU Similar to the ALU is the Floating-Point Unit, or FPU. The FPU performs arithmetic operations on floating point numbers. An FPU is complicated to design, although the IEEE 754 standard helps to answer some of the specific questions about implementation. It isn't always necessary to follow the IEEE standard when designing an FPU, but it certainly does help. Microcontroller CPU architectures There are two basic types of architecture: Von Neumann , Harvard Microcontrollers most often use a Harvard or a modified Harvard- based architecture. Islam Nabil Mahmoud 20130890 13 Electrical&computers Dept Industrial Training 4 ITR 202
  • 14. Von Neumann architecture Von Neumann architecture has a single, common memory space where both program instructions and data are stored. There is a single data bus which fetches both instructions and data. Each time CPU fetches a program instruction it may have to perform one or more read/write operation “instruction” from/to data memory space. It must wait until these subsequent “instruction“ are complete before it can fetch and decode the next program instruction. Harvard Architecture Harvard architecture computers have separate memory areas for program instructions and data. One bus is a 8-bit wide and connects CPU to RAM memory. The other bus consists of several lines (12, 14 or 16 -bit) and connects CPU to ROM memory. The CPU can read an instruction and perform a data memory access at the same time. This speeds up execution time but increases the cost of more hardware complexity. Islam Nabil Mahmoud 20130890 14 Electrical&computers Dept Industrial Training 4 ITR 202
  • 15. CPU main registers Stack pointer Contains the address of the next location on the stack Decremented when data is pushed on the stack and incremented when data is popped from the stack Program counter Most important CPU register Holds the address of the next instruction in program memory space Each instruction is fetched and processed by ALU, the CPU increments the PC . Processor status word/condition code register (PSW ) Contains flags represent the status of the last operation to control the following instructions. Overflow flag ,Negative flag, Zero flag, Carry flag, Half-carry flag ,Global Interrupt mask flag Memory unit Memory is a part of the microcontroller used for data storage. There are different types of memory within the microcontroller: 1. ROM memory (Read Only Memory) 2. RAM memory (Random Access Memory). Memory Hierarchy Islam Nabil Mahmoud 20130890 15 Electrical&computers Dept Industrial Training 4 ITR 202
  • 16. RAM memory (Random Access Memory) Random access refers to the ability to access any memory cell directly. RAM is much faster than ROM. It used to write and read data values while program running RAM is Volatile memory: volatile: if you remove the power supply its contents are lost. Any variable used in a program is allocated into RAM. requires external power to maintain memory content. Used to store data as long as Microcontroller is powered and the program is running Modifiable through program instructions “ARM “ Manipulating large data structures : local variables, pointers, functions, recursive functions results in using large amounts of RAM RAM Types Dynamic RAM (DRAM) is a RAM device that requires periodic refreshing to retain its content. Static RAM (SRAM) is a RAM device that retains its content as long as power is supplied by an external power source. SRAM does not require periodic refreshing and it is faster than DRAM. Non-Volatile RAM (NVRAM) NVRAM is a special type of SRAM that has backup battery power so it can retain its content after the main system power is shut off. Another variation of NVARM combines SRAM and EEPROM(non volatile) so that its content is written into the EEPROM when power is shut off and is read back from the EEPROM when power is restored. Divided virtually to: 1. General purpose registers for CPU acts as accumulators. 2. Special Function Registers(SFR) for any peripheral (Data , Status ,Control registers). 3. Data RAM: all static variables in the program i.e. each variable has a static address and its last value lasts until microcontroller power off. 4. Stack. Stack Is a structure records the chronological ordering of information. It is used mainly in subroutine/function calls and interrupt servicing. A stack is LIFO (last in, first out) structure The address is always in the SP register and is automatically updated during a push or pop instruction. Read Only Memory (ROM) ROM is used to permanently save program being executed. The size of the program that can be written depends on the size of ROM memory Islam Nabil Mahmoud 20130890 16 Electrical&computers Dept Industrial Training 4 ITR 202
  • 17. several types of ROM : OTP Mask ROM Flash ROM EEPROM memory UV EPROM OTP ROM (One Time Programmable ROM): If the microcontroller contains this memory, you can download a program into the OTP , but the process of program downloading is “one-way ticket”, meaning that it can be done only once. OTP (One Time Programmable) devices are microcontrollers where once a program is written into the device it cannot be erased. one time programming ROM used in products Masked ROM Microcontrollers containing this ROM are mainly used by the huge manufacturers. Program is loaded onto the chip by the manufacturer. In case of large scale manufacturing, the price is very low. ROM whose contents are set by masking during the manufacturing process. Programmed upon microcontroller production UV EPROM (UV Erasable Programmable ROM) the package of microcontroller has recognizable “window” on the upper side. this It enables surface of the silicon chip to be lit by an UV lamp, which has, as a result , that complete program cleared and a new program download enabled. EEPROM memory (Electrically Erasable Programmable ROM) : The contents of this memory may be changed during operation (similar to RAM), but remains permanently saved even if the power supply went off (similar to ROM). Accordingly, EEPROM is often used to store values, created during operation, which must be permanently saved Flash memory This type of memory was invented in the 80s in laboratories of INTEL company and were represented as a successor of the UV EPROM. Since the contents of this memory can be written and cleared practically unlimited number of times, the microcontrollers with Flash ROM are ideal for learning, experimentation and small-scale manufacturing. ROM contents program code or text section in flash memory Is instruction code section. Data section in flash memory Handled through “const” keyword in C language. Data are used as a constant configuration from prospective system design and versions configurations. Global , statics, constants,... etc. Software Software is the collection of computer programs and related data that provide the instructions telling a computer what to do. Software products may be developed for a particular customer or may be developed for a general market. Islam Nabil Mahmoud 20130890 17 Electrical&computers Dept Industrial Training 4 ITR 202
  • 18. What is a Program? A collection of such instructions is a called a program and the person who writes and revises these instructions is known as a programmer or developer. Memory Addressing : Computer memory is divided up into addresses. Each address holds an 8 bit (or 1 byte) value. Machine Language : Computers only understand one language: machine language. Each family of computers has its own machine language which can not be understood by any other family of computers. Machine language is a collection of binary numbers Simulator vs. Emulator Simulator : is a software program which allows a developer to run a program . The simulator simulates the running conditions of the target machine on the development machine. Emulator or in-circuit emulator : is a hardware device which behaves like a target machine. It is often called a real time tool because it can react to events as the target microcontroller would. Emulators are often packaged with monitor programs which allow developers to examine registers and memory locations and set breakpoints. Software Process Activities Software Costs Software costs often dominate computer system costs. The costs of software on a PC are often greater than the hardware cost. Software costs more to maintain than it does to develop. Roughly 60% of software costs are development costs, 40% are testing costs. For systems with a long life, maintenance costs may be several times development costs. About US $250 billions spent per year in the US on application development. Islam Nabil Mahmoud 20130890 18 Electrical&computers Dept Industrial Training 4 ITR 202
  • 19. Real-time operating system (RTOS) A real-time operating system (RTOS) is an operating system (OS) intended for real-time applications. The idea of the Operating Systems(OS) comes with the definition of the abstraction. Any OS specially RTOS acts as abstraction layer between application layer, and the hardware abstraction layer (HAL). Types Of Real Time Systems Soft real-time system: The system that can operate with the presence of latency at deadline. It is not considered to have failed if it does not complete its function at deadline but that affects the quality of the output. Examples: Video Processing Audio processing Digital cameras Mobile phones Hard real-time system: Also known as an immediate real-time system. The system that must operate within the confines of a stringent deadline. It is considered to have failed if it does not complete its function within the allowed time span. Examples: Car Air bag. anti-lock Braking Systems(ABS). aircraft control systems. OS basic Concepts Real Time OS is a multiple Background / Foreground system Multiple Background is Multiple Tasks Interrupt Service Routines (ISRs) handle asynchronous events (foreground) Kernel is the main part of OS that manage tasks execution and Communication Scheduler/Dispatcher is the part of Kernel that is Responsible for task execution based on task priorities Types of schedulers: Non-preemptive Preemptive “So the task level (Background) perform the main functionality, but the interrupt level (Foreground) perform the Asynchronous events” Islam Nabil Mahmoud 20130890 19 Electrical&computers Dept Industrial Training 4 ITR 202
  • 20. Servicing Interrupts There are two general ways in which microcontrollers service interrupts : Vectored Arbitration System : Each interrupt vector contains the address of that interrupt’s service routine. When the compiler allocates program memory for interrupt handlers, it places the appropriate address for the handler in the appropriate interrupt vector. To help the compiler you must usually tell it where the interrupt vector for each interrupt is located in program memory. Non-Vectored Priority System : When an interrupt occurs, the CPU branches to a specific address. At this address the interrupts must be checked sequentially to determine which one has caused the interrupt. This scheme can be very slow and there can be a large delay between the time the interrupt occurs and the time it is serviced Islam Nabil Mahmoud 20130890 20 Electrical&computers Dept Industrial Training 4 ITR 202
  • 21. Chapter 2 C programming prerequisites : - 1. C compiler : gcc compiler ( preinstalled with linux ) 2. IDE free : code::Blocks Introduction about programming lang. The earliest computers were often programmed without the help of a programming language, by writing programs in absolute machine language. The programs, in decimal or binary form, were read in from punched cards or magnetic tapeor toggled in on switches on the front panel of the computer. Absolute machine languages were later termed first- generation programming languages (1GL). The next step was development of so-called second-generation programming languages (2GL) or assembly languages, which were still closely tied to the instruction set architecture of the specific computer. These served to make the program much more human-readable and relieved the programmer of tedious and error-prone address calculations. The first high-level programming languages, or third-generation programming languages (3GL), were written in the 1950s. An early high-level programming language to be designed for a computer was Plankalkül, developed for the German Z3 by Konrad Zuse between 1943 and 1945. However, it was not implemented until 1998 and 2000.[26] John Mauchly's Short Code, proposed in 1949, was one of the first high-level languages ever developed for an electronic computer. Unlike machine code, Short Code statements represented mathematical expressions in understandable form. However, the program had to be translated into machine code every time it ran, making the process much slower than running the equivalent machine code. At the University of Manchester, Alick Glennie developed Autocode in the early 1950s. A programming language, it used a compiler to automatically convert the language into machine code. The first code and compiler was developed in 1952 for the Mark 1 computer at the University of Manchester and is considered to be the first compiled high-level programming language. The second autocode was developed for the Mark 1 by R. A. Brooker in 1954 and was called the "Mark 1 Autocode". Brooker also developed an autocode for the Ferranti Mercury in the 1950s in conjunction with the University of Manchester. The version for the EDSAC 2 was devised by D. F. Hartley of University of Cambridge Mathematical Laboratory in 1961. Known as EDSAC 2 Autocode, it was a straight development from Mercury Autocode adapted for local circumstances and was noted for its object code optimisation and source-language diagnostics which were advanced for the time. A contemporary but separate thread of development, Atlas Autocode was developed for the University of Manchester Atlas 1 machine. In 1954, FORTRAN was invented at IBM by John Backus. It was the first widely used high-level general purpose programming language to have a functional implementation, as opposed to just a design on paper. It is still popular language for high-performance computing and is used for programs that benchmark and rank the world's fastest supercomputers. Another early programming language was devised by Grace Hopper in the US, called FLOW-MATIC. It was developed for the UNIVAC I at Remington Rand during the period from 1955 until 1959. Hopper found that business data processing customers were uncomfortable with mathematical notation, and in early 1955, she and her team wrote a specification for an English programming language and implemented a prototype.[34] The FLOW-MATIC compiler became publicly available in early 1958 and was substantially complete in 1959.[35] Flow-Matic was a major influence in the design of COBOL, since only it and its direct descendant AIMACO were in actual use at the time APL introduced array programming and influenced functional programming. Islam Nabil Mahmoud 20130890 21 Electrical&computers Dept Industrial Training 4 ITR 202
  • 22. ALGOL refined both structured procedural programming and the discipline of language specification; the "Revised Report on the Algorithmic Language ALGOL 60" became a model for how later language specifications were written. Lisp, implemented in 1958, was the first dynamically typed functional programming language In the 1960s, Simula was the first language designed to support object-oriented programming; in the mid- 1970s, Smalltalk followed with the first "purely" object-oriented language. C was developed between 1969 and 1973 as a system programming language for the Unix operating system and remains popular. Prolog, designed in 1972, was the first logic programming language. In 1978, ML built a polymorphic type system on top of Lisp, pioneering statically typed functional programminglanguages. Advantage of C programming C programming is standard lang. (ANSI C). 1. Using C in OS. 2. C is Instruction lang. 3. Bit manipulation using 4. Bit field 5. Bit masking 6. Fast execution. 7. Portable What is OS. ? An operating system (OS) is software that manages computer hardware and software resources and provides common services for computer programs. The operating system is an essential component of the system software in a computer system. Application programs usually require an operating system to function. What is file.exe? EXE is a file extension for an executable file format. An executable is a file that contains a program - that is, a particular kind of file that is capable of being executed or run as a program in the computer Assembly lang. assembly language is a low-level programming language for a computer, or other programmable device, in which there is a very strong (generally one-to- one) correspondence between the language and the architecture's machine code instructions. Assembler. is a program that takes basic computer instructions and converts them into a pattern of bits that the computer's processor can use to perform its basic operations. C/C++ is mid level general purpose lang Linear and structuration programming he instructions are written sequentially one under the other. We can repeat a group of statement (looping), we can also making some condition in the program. 1. Linear execution. 2. No (loop, jump,.......). Islam Nabil Mahmoud 20130890 22 Electrical&computers Dept Industrial Training 4 ITR 202
  • 23. Structuration programming divide the program into blocks. All blocks are linked together. Link between blocks used to transfer data between blocks. 1. C programming is structuration programming. 2. Using (jump, loop,......) IDE (integrated development environment). (CodeBlocks, Turbo C, Eclipse ,Cfree ,Devc, Borland,.... ). Compiler: the first step is compiling which is done by the compiler. The compiler has 2 main roles : 1. Check that the syntax in the source code is right 2. To make the intermediate file. 3. Gcc is compiler. In C/C++ programs: The first step is compiling: in this step, the compiler makes an object file this is an intermediate file between the source file and the executable file. It has an extension *.obj The second step is linking: in this step, the linker links the library file to the object file to make the executable file. Error types 1. Compiler error is syntax error. 2. Run time error is like infinite loop or divide by zero. 3. logical error is not error in grammar or run time error. Memory Memory is like a big table of numbered slots where bytes can be stored. The number of a slot is its Address. One byte Value can be stored in each slot. Some “logical” data values span more than one slot, like the character string “Hellon” Islam Nabil Mahmoud 20130890 23 Electrical&computers Dept Industrial Training 4 ITR 202
  • 24. 1 st program #include <stdio.h> #include <stdlib.h> >>> // #include inserts another file. “.h” files are called “header” files. They contain stuff needed to interface to libraries and code in other “.c” files. /*simple Hello world program*/ >>> This is a comment. The compiler ignores this. int main() >>>The main() function is always where your program starts running { >>> Blocks of code between them I write my program for now printf("Hello world!n"); >>> Print out a message. ‘n’ means “new line”. Return 0; >>> exit } Variables A Variable names a place in memory where you store a Value of a certain Type. A variable name in computer source code is associated with a data storage location and thus its contents, which generally change during the course of program execution. Example : 1. var1=2; 2. Var2=5; 3. Var1=4; name Address Value 0x00 0x01 0x02 0x03 var1 0x04 4 var2 0x05 5 Data Types Islam Nabil Mahmoud 20130890 24 Electrical&computers Dept Industrial Training 4 ITR 202
  • 25. Data types How to declare a variable ? char x; Initial value of x is undefined char y=‘A’; char y = ‘A’ ; Data Type is single character (char) Initial value Name Variable/functions names 1. must start with an alphabetic character or “_ “. 2. They may contain numeric digits as well but cannot start with a digit countDown10_1. 3. Variable name is lowercase. 4. not one of C Keywords 32 reserved C keywords (auto, break, case, char, const, continue, default, do, double, else, enum, extern ,float, for, goto, if, int, long, register, return, short, signed, sizeof, static, struct , switch, typedef, union, unsigned, void, volatile, while ) Variable declaration Decelerate variables: Variable_DataType variable_name ; Ex: Char i=5; Decelerate multiple variables: Variable_DataType variableName1, variableName2; Ex: char x,y,z; //Garbage value Printing out variables using printf(“ any word: %d ”, var_name); %d integer number %f floating number %c characters %o The unsigned octal format specifier. Islam Nabil Mahmoud 20130890 25 Electrical&computers Dept Industrial Training 4 ITR 202
  • 26. %s The string format specifier. %u The unsigned integer format specifier. %x The unsigned hexadecimal format specifier a b c %X The unsigned hexadecimal format specifier A B C Example 1 #include <stdio.h> int main(void) { int var = 'a', nVar =20; float fl =1.3; printf("int = %dn", var); printf("char = %cn", var); printf("int = %dn", fl); printf("float= %fn", fl); printf("int = %dn", nVar); return 0; } Constants Named constants may be created using const ex: const int days_in_week = 7; days_in_week = 5; (x error here ) Operators 1. Arithmetic operators: is binary operators 2. Relational operators 3. Logical operators Ex: (10>8 && 9>7) (10<8||7<8) !(10==8) Assignment operators: EX: if a=6 a=a+5 is a+=5 so a=11 a=a*5 is a*=5 so a=30 NOTE: unary operators is a=a+1 is a++ increment is ++a(prefix) , a++ (postfix)) a=a-1 is a-- decrement is --a(prefix) , a--(postfix)) Input variables scanf(”%d”,&x); &x is the address of x. Don’t use x only this make it save in address of the value that stored in x. Same format specifier of printf. Example : #include <stdio.h> int main(void) { int a, b; printf("Enter two numbers: "); Islam Nabil Mahmoud 20130890 26 Electrical&computers Dept Industrial Training 4 ITR 202 Result int = 97 char = a int = -1073741824 float= 1.300000 long int = 20 Exmaple 2 #include <stdio.h> int main(void) { int dec = 20, oct = 020, hex = 0x20; printf("dec=%d, oct=%d, hex=%d, n", dec, oct, hex); printf("dec=%d, oct=%o, hex=%xn", dec, oct, hex); return 0; } Result dec=20, oct=16,hex=32 dec=20, oct=20, hex=20 + - / * % > < == |= <= >= && || ! = += -= *=
  • 27. scanf("%i %i", &a, &b); printf("%i - %i = %in", a, b, a - b); return 0; } Precedence Note: • && ,||, ! Using in condition. o/p is (true or false) • Comma operator: #include<stdio.h> main() { int x=5; int y=10; int z=20; printf("%d n ",(x,y,z)); printf("%d n ",x,y,z); } Note <math.h> : Sin , cos , tan , pow, abs, sqrt, sizeof(). Example: X=pow(3,9) so x=3 X=abs(-3) so x=3 X=sqrt(25) so x=5 X=sizeof(int) so x=2 or 4 byte X=sizeof(char) so x=1 byte  How to convert float to int ? Int x; X=int(3.5); Printf(“%d”,x); Islam Nabil Mahmoud 20130890 27 Electrical&computers Dept Industrial Training 4 ITR 202
  • 28. Casting Implicit casting : Int x=17; Long L=2000; L=x; NOTE 1-How to get the ASCI code from character? #include<stdio.h> main() {int x; x=(int)'a'; printf("%d",x);} 2-How to get char from ASCI? char x; x=(char)97; Printf(“%d”,x); 3-How to convert from the small to capital char? #include<stdio.h> main() {char x='a'; x=(char)((int)'a'-32); printf("%c",x);} %.3f is ..... Example: Int x=256.214587; Printf(“the value of x = %.3f “,x); So output will be the value of x =256.214 Input function Scanf(),getchar(), getche(),getch(),gets() Scanf(); • Header file is <stdio.h> • Example: #include<stdio.h> main() { int a; char b; float c; scanf(" %d %c %f",&a,&b,&c); printf("%d %c %f",a,b,c); } Islam Nabil Mahmoud 20130890 28 Electrical&computers Dept Industrial Training 4 ITR 202 Explicit casting : Int x=17; Long L=2000; X=(int)L; L=(long)x; Wide casting : Int x; Long L; L=X; getchar(): • Header file is <stdio.h> • Example: Char a; a=getchar(); Printf(“%c”,a); getche(): • Header file is <conio.h> • Example: Char a; a=getche(); Printf(“%c”,a); getch(): • Header file is <conio.h> • Example: char a; a=getch(); Printf(“%c”,a); gets(): • Header file is<stdio.h> • Example: char name[20]; gets(name);
  • 29. Output functional Printf(); Putchar(); <Stdio.h> To print character Puts(): <stdio.h> To print string Loops 1. For loop 2. Nested For 3. Infinite For 4. While loop 5. Difference between For and While 6. Infinite While 7. Do...........While 8. Difference between Do...........While and While For() For(initial; condition; update) { statements; } • Initial • Condition • Update Note that initial, condition and update are optional. Note: C Keywords 32 reserved C keywords auto, break, case, char, const, continue, default, do, double, else, enum, extern ,float, for, goto, if, int, long, register, return, short, signed, sizeof, static, struct , switch, typedef, union, unsigned, void, volatile, while Notes in for Don't confuse the two relational operators (< and <=) and misuse them in the expressions of loops. For instance, the following for (j=1; j<10; j++){ /* statement block */ } for (j=1; j<=10; j++){ /* statement block */ } Because the null statement is perfectly legal in C, you should pay attention to placing semicolons in your for statements. The initial and update parts may contain multiple comma separated statements int i, j, k; for(i = 0, j = 5, k = -1; i < 10; i++, j++, k--)  The initial, condition and update parts may contain no statements at all! for(; i < 10; i++, j++, k--) for(;i < 10;) //use of a while loop would be clearer here! Islam Nabil Mahmoud 20130890 29 Electrical&computers Dept Industrial Training 4 ITR 202 Another function Clrscr(): • <Conio.h> • To clear screen gotoxy(x,y); Example: Gotoxy(30,10);
  • 30. for(;;)//creates an infinite loop Nested For For(initial 1 ; condition 1 ; update) { ----------; //statements 1 ----------; For(initial 2 ; condition 2; update) { ---------------; //statements 2 ---------------; } ----------; //statements 1 ----------; } For(;;) >> Printf forever Continue The continue keyword forces the next iteration of the nearest enclosing loop for(j = 1; j <= 10; j++) { if(j % 3 == 0) if j is exactly divisible by 3, skip continue; printf("j = %in", j); } note Comma operator: #include<stdio.h> main() { int x=5; int y=10; Islam Nabil Mahmoud 20130890 30 Electrical&computers Dept Industrial Training 4 ITR 202 EX 2 While() Initialization While(cond) { statement 1; statement 2; .........; update; } EX3 While(1)  While(1) is for(;;).  Example: #include<stdio.h> main() { int i=0; while(1) { printf(“i=%d”,i); i++; } } Nested While Initialization 1 While(cond1) { Initialization 2 While(cond2) { statements; update; } statements; update; } do.............while() Initialization do{ statements; Update; }while(cond); Nested do............while() Initialization1 do{ Initialization2 do{ statements 2; Update 2; }while(cond2); statements 1; Update 1; }while(cond1) j = 1 j = 2 j = 4 j = 5 j = 7 j = 8 j = 10
  • 31. int z=20; printf("%d n ",(x,y,z)); printf("%d n ",x,y,z); } Branshing 1. If 2. Nested if 3. If........else 4. If...............else if 5. Switch, case, break, default, continue 6. goto IF If(condition) { statements; } Condition is ( > , < , >= , <= , == , != , && , || ) Note: If((c%3==0)||(c%6==3)&&(c%9==0)) means .......... ? Example : scanf("%i", &i); if(i > 0) printf("a positive number was enteredn"); if(i < 0) { printf("a negative number was enteredn"); i = -i; } note Example: X=10 If(x==10) Printf(“x is equal 10”); If(x>10) Printf(“x is longer than 10”); If(x<10) Printf(“x is less than 10”); Switch case switch (expression) { case expression1: statement1; case expression2: statement2; . . . default: statement-default; } Islam Nabil Mahmoud 20130890 31 Electrical&computers Dept Industrial Training 4 ITR 202 Nested if If(cond1) if(cond2) if(cond3) { Statements; } If.........else If(condition) { statements; } else { statements; } If.........else if If(cond 1) {statements;} else if(cond 2) {statements;} else if(cond 3) {statements;} else {statements;} Example: scanf(“%d”,&day); switch (day){ case '1': printf("Day 1n"); case '2': printf("Day 2n"); case '3': printf("Day 3n"); default: printf("defaultn"); }
  • 32. Break Statement with switch the break statements help to exit the switch construct after the statement in a selected case is executed. Example : switch (day){ case '1': printf("Day 1n"); break; case '2': printf("Day 2n"); break; default: printf(“defaultn"); } point out the error, if any, in the following program main() { int i=4,j=2; switch(i) { case 1: printf(“case 1”); break; case j: printf(“case 2”); X break; } } Function Function is a series of instructions to run. You pass Arguments to a function and it returns a Value. main() is a Function. It’s only special because it always gets called first when you run your program. It can take no arguments It can be don’t return any thing (Procedures) Return_data_type function _name (input_arguments_list) { //////fun body } Function Example int add(int x,int y){ int sum; sum=x+y; return sum; } int main(void){ int sum; sum=add (4,5); printf(“4+5=x”,sum); return 0; } Islam Nabil Mahmoud 20130890 32 Electrical&computers Dept Industrial Training 4 ITR 202 x,y are Function Arguments return value Function call and passing 4,,5 to it Calling a Function: printf() is just another function, like main() . It’s defined for you in a “library”, a collection of functions you can call from your program.
  • 33. Prototypes The (optional) line int add(int , int ); // is known as a prototype If the compiler meets a call to an unknown function it “guesses” Guess 1: the function returns an int, even if it doesn’t Guess 2: you have passed the correct number of parameters and made sure they are all of the correct type, even if you haven’t The prototype provides the compiler with important information about the return type and parameters Function types 1. Int Function 2. Float Function 3. String Function 4. Char Function 5. Void Function 6. Struct Function Global variables Global variables are created by placing the declaration outside all functions They are placed in the data segment Initial value: 0 Initialization: unnecessary if you like zeros #include <stdio.h> double d; int main(void) { printf(“%d”,d); fun (); printf(“%d”,d); } Static variables The static keyword instructs the compiler to place a variable into the data segment The data segment is permanent (static) A value left in a static in one call to a function will still be there at the next call Initial value: 0 Initialization: unnecessary if you like zeros Islam Nabil Mahmoud 20130890 33 Electrical&computers Dept Industrial Training 4 ITR 202 void fun (void) { d++; }
  • 34. Array 1. A collection of similar variables 2. Each element is of the same type 3. Has a fixed, unchangeable size 4. Accessing by index using [] bracks How to declare array Declaration: data_type Array_Name[Array_Size]; example, int arr_int[3]; Declaration and initialization : data-type Array-Name[Array-Size]; example, int arr_int[3]={1,2,3}; Or int arr_int[3]; arr_int[0]=1; arr_int[1]=2; arr_int[2]=3; Name address Value 0 1 2 3 arr_int[0] 4 arr_int[1] 5 arr_int[2] 6 7 8 Islam Nabil Mahmoud 20130890 34 Electrical&computers Dept Industrial Training 4 ITR 202
  • 35. How array works?(one dimensional) How array works? (multi dimensional) String function Strcmp(); Strlen(); Strcpy(); Strcat(); Islam Nabil Mahmoud 20130890 35 Electrical&computers Dept Industrial Training 4 ITR 202
  • 36. Pointers Introduction : 1. Main memory is a sequence of memory locations that are addressed 0, 1, 2,... 2. Pointers are variables that contain memory addresses as their values. 3. A pointer containing an address of some location is said to be a pointer to that location. Declarations Examples of pointer declarations: int *a; float *b; char *c; Note: 1. format specifier for pointer is p 2. printf("ptr_y: address=0x%p, content=%dn“,ptr,* ptr) 3. Size of pointer is often 2-4 bytes (like size of int )depend on the memory size Note How to declare Pointer to integer? How to declare Pointer to character? A pointer may be incremented (++) or decremented (--). An integer may be added to a pointer (+ or +=). An integer may be subtracted from a pointer (- or -=). One pointer may be subtracted from another. The result is equal to the difference between the pointers values divided by data type size. Pointer advantages 1. Return more than value from function 2. More efficient with array , string , structure. 3. More efficient with addresses 4. Can pass the address of struct ,array to function Swap function 1. Swap two variables using 2. Reference 3. Pointer 4. Global variables typedef typedef int * pti ; pti p[15]; pti is a pointer to an int p is an array of 15 pointer to int Islam Nabil Mahmoud 20130890 36 Electrical&computers Dept Industrial Training 4 ITR 202
  • 37. structure A structure is a collection of one of more variables grouped together under a single name for convenient handling The variables in a structure are called members and may have any type, including arrays or other structures The steps are: set-up a template (blueprint) to tell the compiler how to build the structure Use the template to create as many instances of the structure as desired Access the members of an instance as desired Creating Instances struct Date { int day; int month; int year; } today, tomorrow; struct Date next_monday; struct Date next_week[7]; Union union U { short s; long l; double d; char c; } u; u.s = 10; u.l = 10L; u.d = 10.01; u.c = '1'; struct S { short s; long l; double d; char c; } s; s.s = 10; s.l = 10L; s.d = 10.01; s.c = '1'; Islam Nabil Mahmoud 20130890 37 Electrical&computers Dept Industrial Training 4 ITR 202 instances must be declared before the ‘;’ ... or “struct Date” has to be repeated an array of 7 date instances
  • 38. Memory usage Global data: Declared outside all C functions Visible to all C functions Variables with static storage Storage space allocated in data sections Life time is from the start to the end of program execution Local variables in stack: Local variables of a function go into stack storage Dynamically allocated and de-allocated every time the function is called Variable life time is from the allocation to the deallocation Stack Versus Heap Stack: provides storage for local variables, alters size as the program executes Heap: “dynamic memory” the heap is available for us to use and may alter size as the program executes Dynamic memory Versus Arrays Arrays 1. Have a fundamental problem – their size must be fixed when the program is written 2. There is no way to increase (or decrease) the size of an array once the program is compiled 3. Ex: int a[100]; Dynamic 1. Are different, their size is fixed at run time and may be changed as often as required, Only a pointer is required How to allocate malloc() #include <stdlib.h> void *malloc(size_t size); It return pointer to void If no available size in memory then it return NULL so we must check it before using it free() Islam Nabil Mahmoud 20130890 38 Electrical&computers Dept Industrial Training 4 ITR 202
  • 39. Chapter 3 Data structure & Algorithms Data structure is a particular way of organizing data in a computer so that it can be used efficiently. Data structure is a group of data elements grouped together under one name. These data elements, known as members. A data structure is a specialized format for organizing and storing data. General data structure types include the array, the file, the record, the table, the tree, and so on. Any data structure is designed to organize data to suit a specific purpose so that it can be accessed and worked with in appropriate ways. In computer programming, a data structure may be selected or designed to store data for the purpose of working on it with various algorithms. Data structure :array , stack ,queue ,linked list ,binary tree, Hash table Algorithm Is a way of solution. Is set of steps to achieve certain goal. How to measure the algorithm : By complexity is the number of steps to achieve certain goal [n --------> infinity]. Can use any programming lang. for implementation like C , C++, java ,..... Linked list Linked list is Like arrays, Linked List is a linear data structure. Unlike arrays, linked list elements are not stored at contiguous location; the elements are linked using pointers. Why Linked List? Arrays can be used to store linear data of similar types, but arrays have following limitations. 1-The size of the arrays is fixed: So we must know the upper limit on the number of elements in advance. Also, generally, the allocated memory is equal to the upper limit irrespective of the usage. 2-Inserting a new element in an array of elements is expensive, because room has to be created for the new elements and to create room existing elements have to shifted Array Advantages over arrays Dynamic size Ease of insertion/deletion Drawbacks: Random access is not allowed. We have to access elements sequentially starting from the first node. So we cannot do binary search with linked lists. Islam Nabil Mahmoud 20130890 39 Electrical&computers Dept Industrial Training 4 ITR 202
  • 40. Extra memory space for a pointer is required with each element of the list. Double linked list Doubly-linked list is a linked data structure that consists of a set of sequentially linked records called nodes. Each node contains two fields, called links, that are references ‘pointers’ to the previous and to the next node in the sequence of nodes. Circular linked list A circular linked list is a linked list in which the head element's previous pointer points to the tail element and the tail element's next pointer points to the head element. In the special case of a circular list with only one element, the element's previous and next pointers point to itself, and it is both the head and tail of the list. Single linked list Singly linked list each node in the list stores the contents of the node and a pointer or reference to the next node in the list. It does not store any pointer or reference to the previous node. It is called a singly linked list because each node only has a single link to another node. To store a single linked list, you only need to store a reference or pointer to the first node in that list. The last node has a pointer to nothingness to indicate that it is the last node Islam Nabil Mahmoud 20130890 40 Electrical&computers Dept Industrial Training 4 ITR 202
  • 41. Single linked list representation in C A linked list is represented by a pointer to the first node of the linked list. The first node is called head. If the linked list is empty, then value of head is NULL. Each node in a list consists of at least two parts: 1. Data 2. pointer to the next node In C, we can represent a node using structures. Below is an example of a linked list node with an integer data. struct node { int data; struct node *next; }; Functions of linked list Initlist() Creatlist() Insert_node() Append_node() Search_node() Delete_node() Destroy_node() Isempty() Stack Is a structure records the chronological ordering of information. It is used mainly in subroutine/function calls and interrupt servicing. A stack is LIFO (last in, first out) structure The address is always in the SP register and is automatically updated during a push or pop instruction. Stack function Pop() Push() Display() Islam Nabil Mahmoud 20130890 41 Electrical&computers Dept Industrial Training 4 ITR 202
  • 42. Sorting algorithm For each algorithm : Idea of algorithm Flow chart and pseudo code Implementation of algorithm using C or any lang. Sorting algorithm Bubble sort Selection sort Searching algorithm For each algorithm : Idea of algorithm Flow chart and pseudo code Implementation of algorithm using C or any lang. Searching algorithm Linear searching Binary searching Islam Nabil Mahmoud 20130890 42 Electrical&computers Dept Industrial Training 4 ITR 202
  • 43. Cahpter 4 Computer Architecture Computer Architecture Is the arrangement of computer components and their relationships. The specification of the relation between parts of a computer system. The theory behind the design of a computer. History of Computers Computers date back to 1946 with the first computer made by Eckert, and John Mauchly. It was built using vacuum tubes. A computer is a programmable machine that receives input, stores and automatically manipulates data, and provides output in a useful format. Generations of computers : Historically computers are classified into generations according to the technology used to build them Four generations of computers exist Generations of computers First Generation (1946-1958) This generation relied on vacuum tubes to provide switching of electric current. Second Generation (1959-1964) This generation relied on the transistor to replace the vacuum tubes. Third Generation (1965-1970) This generation relied on Integrated Circuits (IC) instead of transistors. Fourth Generation (1971-Today) This generation utilizes a microprocessor to perform all the computation functionality in one integrated circuit (SOC). Technology with computer Technology is what changed and moved computers rapidly. Technological break throughs helped computers grow in size and performance, it also shrunk the size and power requirements of computers. Technological breakthroughs also helped to prove concepts that were difficult to implement at the time they were suggested Measurement of Computer Performance Several measurements are needed to determine computer performance like: 1. Latency: “How long does it take for my job to run ?” 2. Throughput: “How many jobs can the machine execute at once? 3. Elapsed time: “How long does it take the machine to finish a certain job ?” 4. CPU time: “How much time did it take from the CPU to finish the job ? We are basically focused on CPU time, and elapsed time throughout this course Measurement of CPU Time Many parameters contribute in computer performance, especially CPU time. These parameters include : 1. Processor clock frequency 2. Number of instructions executed per clock cycle 3. Details of what each instruction does (instruction set) Measurement of Computer PerformanceBenchmarks : 1. is a set of tests performed on a computer system to measure computer performance and to compare this Islam Nabil Mahmoud 20130890 43 Electrical&computers Dept Industrial Training 4 ITR 202
  • 44. computer with other computers. 2. Benchmarks are usually synthetic programs that act as real life programs 3. Software benchmarks are run against compilers or database management systems. Examples of benchmarks 1. Dhrystone: Focuses on integer arithmetic performance 2. Whetstone: Focuses on floating point arithmetic performance 3. SPEC: “Standard Performance Evaluation Corporation” Is a non-profit organization that aims to produce fair and meaningful benchmarks for computers In general, the best benchmark : 1. Is written in a high-level language, making it portable across different machines. 2. Is a representative of some programming style or applications (e.g. systems programming, numerical programming, commercial programming). 3. Can be measured easily. Computer Systems Basic block diagram Elements of the basic system 1. Microprocessor: perform all ALU operations. 2. Memory: Store operating program and data. 3. Input Devices: for user input. 4. Output Devices: Output results to the user. 5. Interfaces (Sub-systems): Making a conditioning for the data before 6. getting into or out from the input or output devices respectively. 7. Buses: Transfer data between system components. Islam Nabil Mahmoud 20130890 44 Electrical&computers Dept Industrial Training 4 ITR 202
  • 45. Key definitions Motherboard: The motherboard is a PCB that gathers together all the components of a computer system Bus: 1. A bus, is a set of interconnection lines plus glue logic for transferring data between different components of a computer system 2. A bus is characterized mainly by Bus bandwidth: The maximum amount of data it can transfer per second 3. Further parameters of a bus are: Bus width : Number of bits that can be transferred in one clock cycle Maximum bus Frequency: The maximum frequency that can be used to clock the bus Motherboard Islam Nabil Mahmoud 20130890 45 Electrical&computers Dept Industrial Training 4 ITR 202
  • 46. Detailed block diagram for computer system Buses types Two types of buses: Interfacing buses: These buses are standards used to interface a computer system to a set of peripherals using this bus standard. 1. ISA Bus 2. PCI Bus 3. IDE Bus 4. AGP Bus 5. USB Bus Internal buses: These buses are used to transfer data between the components of a computer system. They are internal to the system itself, they may or may not be following a certain standard 1. Wishbone 2. AMBA Islam Nabil Mahmoud 20130890 46 Electrical&computers Dept Industrial Training 4 ITR 202
  • 47. ISA Bus ISA is Industry Standard Architecture 1. One of the oldest busses in computer systems 2. It is used to connect peripheral cards to computer systems 3. It is16-bit wide. 4. Its bandwidth is 15.6 Mbytes/sec 5. Has simple addressing scheme, needs no special controller PCI Bus PCI Bus is Peripheral Component Interconnect. 1. Used to connect fast peripherals to computer systems 2. Faster and wider than ISA Bus 3. 64 Bit wide,max speed of 66 MHz 4. Bus bandwidth is 508.6 Mb/sec 5. Address bits and data bits are multiplexed. IDE Bus IDE Bus is used to connect computer systems to storage devices like hard drives and CD Drives AGP Bus AGP Bus (Accelerated Graphics Port) 1. This bus is dedicated to display and graphics peripherals It is 32 bits wide, 66 MHz fast 2. Bandwidth of 254.3 Mbytes/sec 3. AGP (x2 Mode) has 66 x 2 MHz speed 4. AGP (x4 Mode) has 66 x 4 MHz speed USB Bus USB Bus (Universal Serial Bus) 1. It is different from the previous busses in the fact that it is a serial bus 2. It consists only of 4 wires 3. It is used for connecting slow to medium speed peripherals to computer systems 4. Supports data rates of 1.5, 12, and 480 Mbps 5. Supports hot swapping, and plug and play, which makes USB peripherals popular for their ease of use Internal Buses 1. Internal busses are less common than interfacing buses because they are hidden inside the computer system Wishbone: This bus is an open source standard. It is made for open source components to interface with open source Islam Nabil Mahmoud 20130890 47 Electrical&computers Dept Industrial Training 4 ITR 202
  • 48. processors AMBA: This bus is used for embedded systems, especially those using ARM microcontrollers. It was originally designed by ARM ® Ltd. CPU Structureny CPU is consisting of main components : 1. Data path : ALU/FBU Internal buses Registers 2. Control Unit: Hardwired control Unit Micro-programmed control Unit Processor Data-path 1. Processor data-path is the hardware part of the processor that performs the processing operations. 2. It is the main components of microprocessor that is responsible for performing the operation. 3. Processor data-path helps to understand how data is manipulated and helps define the tasks required from the control unit 4. It also helps understand how data is transferred from one component of the processor to another component Data path consists of three parts: 1. ALU/FBU 2. Internal buses 3. Registers Islam Nabil Mahmoud 20130890 48 Electrical&computers Dept Industrial Training 4 ITR 202
  • 49. Processor Data-path CPU Structure The basic elements of the CPU are: 1. ALU Arithmetic & Logic Unit Responsible for performing logic and arithmetic calculations 2. Floating-Point Unit (FPU) performs arithmetic operations on floating point numbers 3. Registers Registers are used to store data beside the ALU Registers are used to transfer data to/from memory Registers carry the inputs of ALU, as well as, receiving the output of the ALU 4. Internal CPU Bus It is a special bus It is responsible for transferring data between registers, ALU, and system memory 5. Control Unit It is responsible for organizing the actions of the CPU components It can be thought of as the heart of the CPU ALU 1. A & B are inputs of the ALU 2. Control input: Selects the required functionality to be done on A (& B) Islam Nabil Mahmoud 20130890 49 Electrical&computers Dept Industrial Training 4 ITR 202
  • 50. 3. Output: Output of the operation performed on operands 4. Flags: Indicate status of last arithmetic & logic operations performed in the ALU (E.g. zero flag, overflow flag, sign flag) FPU 1. Similar to the ALU is the Floating-Point Unit, or FPU. The FPU performs arithmetic operations on floating point numbers. 2. An FPU is complicated to design, although the IEEE 754 standard helps to answer some of the specific questions about implementation. 3. It isn't always necessary to follow the IEEE standard when designing an FPU, but it certainly does help. CPU Registers CPU Registers are classified into two main categories : 1. User-visible registers 2. Control and status registers User-visible registers These are registers that are visible to the programmer to use for programming the processor. They are further categorized as follows: 1. General purpose: Used by programmer to store data, or perform operations on them (R0,R1,...,R31) 2. Data Registers: Can be used for storage/retrieval of data only, not for operations(instructions) 3. Address Registers: They are dedicated for storing addresses specific to memory operations frequently required 4. Examples are: Stack pointer register& Segment pointer register 5. Condition Codes Registers: They are flags that are set by the CPU as a result of logic and arithmetic operations. Examples are: CCR or PSW register. Control and Status Registers These are a set of essential registers for proper operation. They are usually not visible to the programmer, although some of them are so. Examples are: 1. Program Counter (PC): Contains the address of the instruction to be fetched. 2. Instruction Register (IR): Contains the instruction most recently fetched. 3. Memory address register (MAR): Contains the address of the location in the memory to be fetched/stored 4. Memory buffer register (MBR): Contains the data to be loaded/stored in the memory Islam Nabil Mahmoud 20130890 50 Electrical&computers Dept Industrial Training 4 ITR 202