0% found this document useful (0 votes)
22 views24 pages

Embedded System

Embedded systems are specialized computer systems designed to perform specific tasks, such as controlling machines. They are found in devices like alarm systems, washing machines, and traffic lights. The main components of an embedded system are a microcontroller, memory, sensors, and actuators. A key difference between embedded systems and general purpose computers is that embedded systems are designed to perform pre-defined tasks and do not require heavy user interaction.

Uploaded by

mai elsayed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views24 pages

Embedded System

Embedded systems are specialized computer systems designed to perform specific tasks, such as controlling machines. They are found in devices like alarm systems, washing machines, and traffic lights. The main components of an embedded system are a microcontroller, memory, sensors, and actuators. A key difference between embedded systems and general purpose computers is that embedded systems are designed to perform pre-defined tasks and do not require heavy user interaction.

Uploaded by

mai elsayed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 24

1

Embedded Systems

Introduction:
System
For example, a watch is a time displaying system. Its components follow
a set of rules to show time. If one of its parts fails, the watch will stop
working. So we can say, in a system, all its subcomponents depend on
each other.
Embedded system (ES)
An embedded system can be thought of as a computer hardware system
having software embedded in it (CPU, RAM, ROM, I/O Ports, and Timers
are components to be embedded together on a single chip). An embedded
system can be an independent system or it can be a part of a large system.
An ES is a microcontroller based system which is designed to perform a
specific task. For example, a fire alarm is an embedded system, it will
sense only smoke.

Applications of Embedded systems

Some applications of ES: Medical equipment, Home devices (digital


alarm, air conditioner, washing machines), Automobiles (lighting
system, door locks, air bags, anti-stealing alarms), Industrial control
(robots, control system), Traffic lights, Mobile phones.

The main parts of embedded system are: sensor, microcontroller,


memory, and actuator (motor).

The most important part of ES is a microcontroller, as the name


suggests that it is controls all the operations required from it.

For an embedded system designer, it is necessary to have the knowledge


of both microprocessors and microcontrollers.
Note: An embedded system is a microcontroller based system (special
purpose), but personal computer (PC) is a microprocessor based system
(general purpose).
2

PC Assembly Language and Architecture

*) Instruction categories: -
-
1. Arithmetic, logic, and shift instructions (INC, DEC, ADD, SUB,
MUL, DIV, AND, OR, XOR, SHR, SHL);
2. Instructions for moving information to and from memory and
processor registers (MOV, LDA, STA, PUSH, POP);
3. control instructions (JMP (BUN), JZ, JNZ, SKI, SKO, CALL
(BSA), RET);
4. Input / output (I / O) instructions (INP, OUT).

*) Some directives (pseudo – op):

- The define statement is the main pseudo – op (directive) used to


allocate storage in data segment (DB, DW, DD).

- The DUP (…) pseudo – op: is used to multiple the store of the same
value in memory (data segment).

- The ORG (origin) pseudo – op: It tells MASM to reach the required
offset address.

*) Computer instruction (instruction code): is a binary code that


specifies a sequence of micro-operations for the computer (instructs the
computer to perform a specific operation). It is organized according to a
certain instruction format.

compiling
Program instruction (add AX , BX) ------------- machine instruction

Mode Op. code Address


field
"Instruction code format"

* Instruction fields:
3

Instruction fields:
- Op code field (operation part): is a group of bits that specifies the
operation such as add, sub, mul, shift, complement, … . If op. code
contains n bits, then it is capable of representing 2 n different operations.

- Address field (address part): the addresses of processor registers or


memory words (where the operands are to be found, as well as where the
result is to be stored) must be specified.

- Mode field - specifies the way the operand or the effective address is
determined.

* Addressing modes:
tafser
Specifies a rule for interpreting the address field of the instruction before
the operand is actually referenced.

1- Implied addressing mode:


Address of the operands are specified implicitly in the definition of the
instruction. No need to specify address in the instruction (CBW --).

Mode Op. code --


field

2- Immediate addressing mode:


Instead of specifying the address of the operand, operand itself is
specified. No need to specify address in the instruction.

Mode Op. code Operand


field

3- Direct addressing mode:


Instruction specifies the memory address which can be used directly to
the physical memory.

Mode Op. code Address of operand in memory


field

4- Indirect addressing mode:

The address field of an instruction specifies the address of a memory


location that contains the address of the operand.
4

Mode Op. code Address of memory word, where the effective


field address of the operand is to be found

5- Register addressing mode: moaen


Address specified in the instruction is the register Address. Designated
operand need to be in a register.

Mode Op. code Address of register


field

6- Register indirect addressing mode: add AX, [ BX ] ; BX points to


operand in memory. Instruction specifies a register which contains the
memory address of the operand.

Mode Op. code Address of BX pointer


field register

7- Relative addressing mode: MOV reg., [ BP + n ] ;


The address field of an instruction specifies the part of the address
(abbreviated address) which can be used along with a designated base
pointer register (BP) to calculate the address of the operand.

Mode Op. code n = -128 → +127 (8 bits) , which is


field added to BP of 16 bits

* General registers:

The simplest way to organize a computer is to have one processor register


(Accumulator: AC).

Any type of organization requires the following registers:


1- A program counter ( PC ): to calculate and hold the address
of the next instruction to be read from memory after the current
instruction is executed .
2- Instruction register ( IR ): is necessary in the control unit for
storing the instruction code after it is read from memory.
3- The address register (AR): to store the address of the operand.
4- The data register (DR): holds the operand which is read from
memory.
5- The accumulator register (AC): is a general - purpose
5

processing register to hold one of the operands and to store the result .
6- The temporary register (TR): to hold temporary data during
Processing.
7- The input register (INPR): receives an 8-bit character from an
input device.
8- The output register (OUTR): holds an 8-bit character for an
output device.

*) Modes of transfer:

There are three modes of transfer:

1- Programmed I / O ;

2- Interrupt I / O ;

3- DMA (direct memory access).

1- Programmed I / O:

- The computer keeps checking the status of I / O devices, checking the


flag bits (FGI, FGO) during inputting or outputting operation (wasting a
time) instead of doing any other useful processing task.

2- Interrupt I / O:

Program interrupt refers to transfer of program control from running


program to another service program as a result of an external or internal
generated request.
It is useful in multiprogramming for taking care of data transfer of one
program while another program is being executed. The running program
must include an ION instruction to turn the interrupt on. If the interrupt
facility is not used, the program must include an IOF instruction to turn it
off.

Types of interrupts:
a- Hardware interrupts (external): come from I / O devices, timing
device, power supply, … etc.
b- Software interrupts (internal): come from error conditions such as
register overflow, divide by zero, stack overflow, … etc., and from
call instruction.
6

3- DMA:

During DMA the CPU is idle (doesn't use memory buses) and has no
control of the memory buses. DMA controller takes over the buses to
manage the transfer directly between I / O device and memory (removing
the CPU from the path).
7

CH. 1: INTRODUCTION TO EMBEDDED SYSTEMS CH. 1: INTRODUCTION TO EMBEDDED SYSTEMS

GENERAL-PURPOSE COMPUTERS GENERAL-PURPOSE COMPUTERS


• Able to run a variety of • Designed for heavy user • Several implement data
software. interaction. memory and program
storage.
• Contain relatively high- • Uses a variety of peripherals
performance hardware (displays, keyboards, mice, • Possesses a distributed
components (fast processors, internet connections, wireless architecture (full functionality of
data & program storage). communication capability). the computer is spread across
multiple IC chips).
• Expensive ($100s - $1000s).
• Require an operating system
(OS). • Use a group of integrated
circuits or chips (ICs).
• One implements the
central processing unit
Image Courtesy of Image Courtesy of
Recording Connection of Canada (CPU). Recording Connection of Canada

1.1 WHAT IS AN EMBEDDED SYSTEM ? 1.1 WHAT IS AN EMBEDDED SYSTEM ?

CH. 1: INTRODUCTION TO EMBEDDED SYSTEMS CH. 1: INTRODUCTION TO EMBEDDED SYSTEMS

EMBEDDED COMPUTERS EMBEDDED COMPUTERS


• Resources can be • Contains firmware (only
implemented on a single the needed software
IC. which is not intended to
be changed frequently).
• Include a variety of
peripherals (timers, • May contain Real Time
analog-to-digital Operating Systems
converters, digital-to- (RTOS) which are used
analog converters, serial as a task scheduler.
interfaces).
• Low cost (10s of cents to
• Small size makes them Image Courtesy of
a few dollars). Image Courtesy of

very versatile. Recording Connection of Canada Recording Connection of Canada

1.1 WHAT IS AN EMBEDDED SYSTEM ? 1.1 WHAT IS AN EMBEDDED SYSTEM ?

CH. 1: INTRODUCTION TO EMBEDDED SYSTEMS

EMBEDDED COMPUTERS

Image Courtesy of
Recording Connection of Canada

1.1 WHAT IS AN EMBEDDED SYSTEM ?


8

 ES - Overview
 ES – Microprocessor and Microcontroller Architecture
 ES - 8051 Microcontroller
 ES - I/O Programming
 ES - Assembly Language
 ES - Registers
 ES - Registers Bank/Stack
 ES - Instructions
 ES - Addressing Modes
 ES - Timer/Counter
 ES - Interrupts

Embedded Systems - Overview

Embedded System (ES)


An embedded system can be thought of as a computer hardware system
having software embedded in it. An embedded system is a microcontroller
based system which is designed to perform a specific task.

Applications of Embedded systems

Some applications of ES: Home devices (TVs, digital alarm, air


conditioner, DVD video player, cameras, washing machines),
Automobiles (lighting system, door locks, air bags, windows, anti-
stealing alarms), robots, and others.

- Real Life Example of Embedded System. # #

Automatic Washing Machine:

 This is one of the famous application of real life examples of


embedded systems.
 You out all the dirty clothes inside the machine and push start button
(you input data).
 WM is there to measure the weight of the laundry you have put
inside.
 WM opens the valve to enable the clean water go inside.
 On the basis of load and water level, the valve gets closed.
9

 The rotating drum of the Washing Machine starts rotating and that’s
how washing starts.
 After washing cycle, the outlet valve opens to release all the dirty
water.
 The sensor detects whether all the dirty water has been removed or
not and opens or close the outlet valve.
 This whole process repeats and we get our clothed washed. # #

Components of embedded system

An embedded system has three components:


 It has hardware.
 It has application software.
 It has Real Time Operating system (RTOS), which defines the way
the system works.
A real-time operating system (RTOS) is any operating system (OS)
intended to serve real-time applications that process data as it comes in,
typically without buffer delays.
Processing must be done within the defined constraints or the system will
fail. OS either event driven or time sharing. Event driven systems switch
between tasks based on their priorities while time sharing systems switch
the task based on clock interrupts.
A real-time OS is valued more for how quickly it can respond than 
for the amount of work it can perform in a given period of time.
So we can define an embedded system as a microcontroller based,
software driven, real - time control system.
10

Characteristics of an Embedded System


 Single-functioned – An embedded system usually performs a
specialized operation and does the same repeatedly.
 Tightly constrained − It must be of a size to fit on a single chip,
must perform fast enough to process data in real time and consume
minimum power to extend battery life.
 Reactive and Real time − Many embedded systems must
continually react to changes in the system's environment and must
compute certain results in real time without any delay. A delayed
computation can result in failure to control of the object.
 Microcontroller based − It must be microcontroller based.
 Memory − It must have a memory, as its software usually embeds
in ROM. It does not need any secondary memories in the computer.

Basic Structure of an Embedded System


The following illustration shows the basic structure of an embedded
system:

 Sensor − It measures the physical quantity and converts it to an


electrical signal which can be read by any electronic instrument like
an A-D converter. A sensor stores the measured quantity to the
memory.
 A-D Converter – An analog-to-digital converter converts the
analog signal sent by the sensor into a digital signal.
11

 Controller − processes the data to measure the output and store it


to the memory.
 Memory - is used to store information. ES contains two memory
cells: RAM (to store data) and ROM (to store program).
 D-A Converter − A digital-to-analog converter converts the digital
data fed by the processor to analog data.
 Actuator − is a component that turns the control signal into
movement. Examples of actuators include: Electric motors.
 # # A relay is an electrically operated switch. They commonly use
an electromagnet (coil) to operate their internal contacts. When a
relay contact is open, this will switch power ON for a circuit when
the coil is activated. Relays allow a low current circuit to control
one or more higher current circuits.
 Platform: is an open-source electronic board (such as Arduino)
based on easy to use hardware and software. Boards are able to
read inputs (light on a sensor, a finger on a button) and turn it into
an output (activating a motor, turning on a LED). You can tell your
board what to do by sending a set of instructions to the
microcontroller on the board (upload a control program from PC to
writable ROM in microcontroller on the board). To do so you can
use the programming languages (Python, C / C++, and Assembly).
##

Procedure (steps to solve a control problem in general):

1. Data gathering (through sensor);

2. Data processing (compare entered data with the value in the control
program);

3. Decision making and sending an order to actuator.


12

Embedded Systems – Microprocessor and Microcontroller


Architecture

For an embedded system designer, it is necessary to have the knowledge


of both microprocessors and microcontrollers.
Microprocessor
A microprocessor is a single VLSI chip having a CPU. In addition, it may
also have other units such as pipelining units that help in faster processing
of instructions.

Microcontroller
A microcontroller is a single-chip VLSI unit, which although having
limited computational capabilities, possesses enhanced input/output
capability and a number of on-chip functional units.

CPU RAM ROM

I/O Port Timer Serial COM Port

A SIMPLE BLOCK DIAGRAM OF A MICROCONTROLLER

Microcontrollers are particularly used in embedded systems for real-time


control applications with on-chip program memory and devices.
13

Microprocessor vs (versus) Microcontroller


Let us now take a look at the most notable differences between a
microprocessor and a microcontroller.

Microprocessor Microcontroller

Microprocessors are multitasking Single task oriented. For example, a


in nature. Can perform multiple washing machine is designed for
tasks at a time. washing clothes only.

CPU, RAM, ROM, I/O Ports, and CPU, RAM, ROM, I/O Ports, and
Timers are components on Timers are components to be embedded
different chips and can vary in together on a single chip and are fixed in
numbers. numbers.

Microprocessors are heavier and Microcontrollers are lightweight and


costlier. cheaper than a microprocessor.

Microprocessor-based system A microcontroller-based system


require more space and their power consumes less power and takes less
consumption is higher. space.
14

Embedded Systems - 8051 Microcontroller

The main part of ES is a microcontroller, as the name suggests that it is


controls all the operations required from it.
# # Criteria for Choosing Microcontroller
We must see whether an 8-bit, 16-bit or 32-bit microcontroller can best
handle the computing needs of a task. In addition, the following points
should be kept in mind while choosing a microcontroller:
Speed, Power Consumption, Amount of RAM and ROM on the chip,
Count of I/O pins and Timers on the chip, Cost per Unit.
Further, make sure you have tools such as compilers, and assemblers,
available with the microcontroller.
Compiler
A program that can translate the source code from a high level
programming language to a low-level language (assembly language or
machine code).
De-compiler
A program that can translate a program from a low-level language to a
high-level language.
Assembler
A program that translates a symbolic version of Instruction into
binary version.
- The most common used microcontrollers are: 8051 microcontroller and
PIC microcontroller (Peripheral Interface Controller, or Programmable
Intelligent Computer). # #
- The first microprocessors 8085 and 8086 were invented by Intel
Corporation. Intel also introduced an 8-bit microcontroller called
the 8051. It was referred as system on a chip because it had 128 bytes of
RAM, 4K byte of on-chip ROM, two timers, one serial port, and 4 ports
(8-bit wide), all on a single chip.
8051 Family Members (8051, 8052, and 8031): they have different features.
15

Features of 8051 Microcontroller


An 8051 microcontroller comes with the following features:

 4K bytes on-chip program memory (ROM)


 128 bytes on-chip data memory (RAM)
 Four register banks (each bank has 8 registers)
 32 general purpose registers each of 8 bits
 8-bit Accumulator register
 128 user defined software flags
 8-bit bidirectional data bus
 16-bit unidirectional address bus
 16 bit Timers (usually 2, but may have more or less)
 Three internal and two external Interrupts
 Four 8-bit ports (short model have two 8-bit ports)
 16-bit program counter and data pointer
Note: The 8051 microcontrollers work with 8-bit data bus. So they can
support external data memory up to 64K and external program memory
of 64k at best. Collectively, 8051 microcontrollers can address 128k of
external memory.

Embedded Systems - I/O Programming

The following pin diagram shows the details of the 40 pins. In 8051, I/O
operations are done using four ports, where each port has 8 pins (32 pins).
The other 8 pins are designated as Vcc (power supply), Vss (GND: ground),
XTAL1, XTAL2 (crystal-frequency), RST (reset), EA (external access),
ALE / PROG (address latch enable), and PSEN (program store enable).
It is a 40-Pin PDIP (Plastic Dual Inline Package):
16

I/O Ports and their Functions


The four ports P0, P1, P2, and P3, each use 8 pins, making them 8-bit
ports. Upon RESET, all the ports are configured as inputs, ready to be
used as input ports. When the first 0 is written to a port, it becomes as an
output. To reconfigure it as an input, a 1 must be sent to a port.
Port 0 (Pin No 32 – Pin No 39)
It has 8 pins (32 to 39). It can be used for input or output. It is also
designated as AD0-AD7, allowing it to be used as both address and data.
When we need to access the external ROM, then P0 will be used for both
Address and Data Bus. ALE (Pin 30) indicates if P0 has address or data.
When ALE = 0, it provides data D0-D7, but when ALE = 1, it has address
A0-A7.
We can use the following instructions with ports:
MOV A , P n ; where n = 0, 1, 2, 3 (the number of port)
MOV P n , A ; where A is an 8-bit accumulator register
17

MOV A, #0FFH ; (comments: A = FFH = 1111 1111B)

MOV P0, A ; (Port 0 has 1 on every pin so that it works as input)

Port 1 (Pin 1 through 8)


It is an 8-bit port (pin 1 through 8) and can be used either as input or
output. Upon reset, Port 1 is configured as an input port. The following
code can be used to send alternating values of 55H and AAH to Port 1
continuously (consider that P1 connected to LEDs):

MOV A, #00H ; A = 00H = 0000 0000B


MOV P1, A ; (Port 1 has 0 on every pin so that it works as output)

MOV A , #55H ; A = 0101 0101

BACK : MOV P1 , A ; P1 connected to LEDs


(half on-half off)

ACALL DELAY ; wait (we can do a delay by making a


subroutine with no operation: NOP in loop)

CPL A ; complement reg. A , then A = 1010 1010


(invert 55H = AAH and invert AAH = 55H)

SJMP BACK ; keep jump (short) to label BACK


If Port 1 is configured to be used as an output port, then to use it as an
input port again, program it by writing 1 to all of its bits. The following
code is used to get data from P1 as input port and to save it one time in R7,
another time in R6, lastly in R5:

MOV A , #0FFH ; A = FF hex


MOV P1, A ; Make P1 as an input port
MOV A , P1 ; get data from P1 to Accumulator
MOV R7, A ; save it in reg. R7
ACALL DELAY ; wait

MOV A , P1 ; get another data from P1 to A


MOV R6 , A ; save it in R6
18

ACALL DELAY ; wait

MOV A , P1 ; get another data from P1 to A


MOV R5 , A ; save it in R5

Port 2 (Pins 21 through 28)


It has 8 pins (pins 21 through 28) and can be used for both input and output
operations. It must be used along with P0 to provide the 16-bit address for
the external memory. So it is also designated as (A8–A15) as shown in the
pin diagram. In other words, we can say that when an 8051 is connected
to an external memory (ROM) which can be maximum up to 64KB (this
is possible by 16 bit address bus because we know 2^16 = 64KB), Port2 is
used for the upper 8-bit of the 16 bits address, and it cannot be used for
I/O and this is the way any Program code of external ROM is addressed.
Ex. Get a byte from P2 as input port and send it to P1 continuously.

MOV A , #0FFH ; A = FF hex

MOV P2 , A ; make P2 an input port

BACK: MOV A , P2 ; get data from P2

MOV P1 , A ; send it to Port 1

SJMP BACK ; keep doing that

Port 3 (Pins 10 through 17)


This port provides some extremely important signals. P3.0 and P3.1 are
RxD (Receiver) and TxD (Transmitter) respectively and are collectively
used for Serial Communication. P3.2 (INT0) and P3.3 (INT1) pins are
used for external interrupts. P3.4 and P3.5 are used for timers T0 and T1
respectively. P3.6 and P3.7 are Write (WR) and Read (RD) pins
respectively.
19

# # Hardware Connection of Pins (read only)

 Vcc (Pin 40) – provides supply to the Chip and it is +5 V.


 Gnd (Pin 20) − provides ground for the Reference.
 XTAL1, XTAL2 (Pin 18 & Pin 19) − this crystal for generating a
signal of desired frequency. For example, a 20 MHz
microcontroller requires a crystal with a frequency no more than 20
MHz.
 RST (Pin 9) − It is an active high pin. Upon applying a high pulse
on this pin, that is 1, the microcontroller will reset and terminate all
activities. This process is known as Power-On Reset. Activating a
power-on reset will cause all values in the register to be lost. It will
set a program counter to all 0's.
 EA or External Access (Pin 31) − this pin is an active low pin,
upon applying a low pulse, it gets activated. EA is to indicate that
the program code is stored externally (in an external ROM).
 PSEN or Program store Enable (Pin 29) − this is also an active
low pin. It is used along with the EA pin to allow storage of
program code in external ROM.
 ALE or Address Latch Enable (Pin 30) − this is an active high.
When ALE = 0, then the P0 pins work as Data bus and when ALE
= 1, then the P0 pins act as Address bus. # #

I/O Ports and Bit Addressability


Sometimes we need to access only 1 or 2 bits of the port instead of the
entire 8-bits. 8051 provides the capability to access individual bits of the
ports.
While accessing a port in a single-bit manner, we use the syntax "SETB
X. Y" where X is the port number (0 to 3), and Y is a bit number (0 to 7).
For example, "SETB P1.5" sets high bit 5 of port 1.
The following code shows how we can toggle the bit P1.2 continuously
(for ex., when P1.2 connected to LED).
20

AGAIN: SETB P1.2


ACALL DELAY
CLR P1.2
ACALL DELAY
SJMP AGAIN

Single-Bit Instructions
Instructions Function

SETB bit Set the bit (bit = 1)

CLR bit clear the bit (bit = 0)

CPL bit complement the bit (bit = NOT bit)

JB bit, target jump to target (label) if bit = 1 (jump if bit)

JNB bit, target jump to target if bit = 0 (jump if no bit)

JBC bit, target jump to target if bit = 1, clear bit (jump if bit, then clear)
21
22
23
24

You might also like