Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
muthmainnah
FACULTY OF MECHANICAL
ENGINEERING
CHAPTER 5: MICROPROCESSOR
SYSTEMS & APPLICATIONS
MEC523
APPLIED ELECTRONICS &
MICROPROCESSOR
Prepared by Nurul Muthmainnah Mohd
Noor
SLIDE 1
1
CHAPTER 5_PART 1
muthmainnah
Part 1
Part 2
SLIDE 2
2
CHAPTER 5_PART 1
muthmainnah
PART 1
5.1 Microprocessor architecture and overview.
5.2 Assembly Language programming.
SLIDE 3
3
CHAPTER 5_PART 1
muthmainnah
COURSE OUTCOME
SLIDE 4
4
CHAPTER 5_PART 1
muthmainnah
Objectives
◦ To differentiate between
microprocessor and microcontroller
◦ To know the family 8051
◦ To understand and assembly the
programming of 8051
SLIDE 5
5
CHAPTER 5_PART 1
muthmainnah
Introduction
Inside in computer
SLIDE 6
6
CHAPTER 5_PART 1
muthmainnah
Introduction
Inside in computer
The terms used to describe amounts of memory in IBM
PCs and compatibles
Kilobyte (K): 210 bytes
Megabyte (M) : 220 bytes, over 1 million
Gigabyte (G) : 230 bytes, over 1 billion
Terabyte (T) : 240 bytes, over 1 trillion
SLIDE 7
7
CHAPTER 5_PART 1
muthmainnah
Introduction
Internal Organization of Computers
SLIDE 8
8
CHAPTER 5_PART 1
muthmainnah
Introduction
Internal Organization of Computers
SLIDE 9
9
CHAPTER 5_PART 1
muthmainnah
Introduction
The CPU is connected to memory and I/O through strips
of wire called a bus
Carries information from place to place
* Address bus
* Data bus
* Control bus
SLIDE 10
10
CHAPTER 5_PART 1
muthmainnah
Introduction
SLIDE 11
11
CHAPTER 5_PART 1
muthmainnah
Introduction
SLIDE 12
12
CHAPTER 5_PART 1
muthmainnah
Introduction
◦ The more address buses available, the larger the number of devices that can be
addressed.
◦ The number of locations with which a CPU can communicate is always equal to 2x, where
x is the address lines, regardless of the size of the data bus
◦ Example: A CPU with 24 address lines and 16 data lines can provide a total of 224 or 16M
bytes of addressable memory. Each location can have a maximum of 1 byte of data,
since all general-purpose CPUs are byte addressable
◦ The address bus is unidirectional
SLIDE 13
13
CHAPTER 5_PART 1
muthmainnah
Introduction
◦ For the CPU to process information, the data must be stored in RAM or
ROM, which are referred to as primary memory .
◦ ROM provides information that is fixed and permanent
- Tables or initialization program
◦ RAM stores information that is not permanent and can change with
time - Various versions of OS and application packages
- CPU gets information to be processed
* first form RAM (or ROM)
* if it is not there, then seeks it from a mass
storage device, called secondary memory, and
transfers the information to RAM
SLIDE 14
14
CHAPTER 5_PART 1
muthmainnah
Introduction
Registers
The CPU uses registers to store information
temporarily
Values to be processed
Address of value to be fetched from memory
SLIDE 15
15
CHAPTER 5_PART 1
muthmainnah
Introduction
ALU (arithmetic/logic unit)
Performs arithmetic functions such as add, subtract, multiply, and divide,
and logic functions such as AND, OR, and NOT
Program counter
Points to the address of the next instruction to be executed
As each instruction is executed, the program counter is incremented to
point to the address of the next instruction to be executed
Instruction decoder
Interprets the instruction fetched into the CPU
A CPU capable of understanding more instructions requires more
transistors to design
SLIDE 16
16
CHAPTER 5_PART 1
muthmainnah
8051 MICROCONTROLLERS
SLIDE 17
17
CHAPTER 5_PART 1
muthmainnah
8051 MICROCONTROLLERS
Microprocessor Microcontroller
Due to external components, the entire power Since external components are low, total power
consumption is high. Hence it is not suitable to use consumption is less and can be used with devices
with devices running on stored power like batteries. running on stored power like batteries.
Most of the microprocessors do not have power Most of the microcontrollers have power saving
saving features modes like idle mode and power saving mode. This
helps to reduce power consumption even further.
Since memory and I/O components are all external, Since components are internal, most of the
each construction will need external operation, operations are internal instruction, hence speed is
hence it is relatively slower. fast.
Microprocessor have less number of registers, hence Microcontroller have more number of registers,
more operations are memory based. hence the program are easier to write
SLIDE 18
18
CHAPTER 5_PART 1
muthmainnah
8051 MICROCONTROLLERS
Microprocessor Microcontroller
Microprocessors are based on von Neumann Microcontrollers are based on Harvard
model/architecture where program and data are stored in architecture where program and data memory
same memory module are separate
Mainly used in personal computers Mainly used in washing machine, MP3 players
SLIDE 19
19
CHAPTER 5_PART 1
muthmainnah
8051 MICROCONTROLLERS
◦ An embedded product uses a microprocessor (or microcontroller) to do one
task and one task only
◦ There is only one application software that is typically burned into ROM
◦ A PC, in contrast with the embedded system, can be used for any number of
applications
◦ It has RAM memory and an operating system that loads a variety of
applications into RAM and lets the CPU run them
◦ A PC contains or is connected to various embedded products - Each one
peripheral has a microcontroller inside it that performs only one task
SLIDE 20
20
CHAPTER 5_PART 1
muthmainnah
8051 MICROCONTROLLERS
◦ Many manufactures of general-purpose microprocessors have targeted their
microprocessor for the high end of the embedded market
◦ There are times that a microcontroller is inadequate for the task
◦ When a company targets a generalpurpose microprocessor for the embedded
market, it optimizes the processor used for embedded systems
◦ Very often the terms embedded processor and microcontroller are used
interchangeably
SLIDE 21
21
CHAPTER 5_PART 1
muthmainnah
8051 MICROCONTROLLERS
◦ One of the most critical needs of an embedded system is to decrease power
consumption and space
◦ In high-performance embedded processors, the trend is to integrate more
functions on the CPU chip and let designer decide which features he/she wants to
use
◦ In many cases using x86 PCs for the high-end embedded applications
Saves money and shortens development time
A vast library of software already written
Windows is a widely used and well understood platform
SLIDE 22
22
CHAPTER 5_PART 1
muthmainnah
8051 MICROCONTROLLERS
◦ 8-bit microcontrollers
Motorola’s 6811
Intel’s 8051
Zilog’s Z8
Microchip’s PIC
◦ There are also 16-bit and 32-bit microcontrollers made by various chip makers
◦
SLIDE 23
23
CHAPTER 5_PART 1
muthmainnah
8051 MICROCONTROLLERS
Meeting the computing needs of the task at hand
efficiently and cost effectively
-Speed
-Packaging
-Power consumption
-The amount of RAM and ROM on chip
-The number of I/O pins and the timer on chip
- How easy to upgrade to higher performance or
lower power-consumption versions
- Cost per unit
SLIDE 24
24
CHAPTER 5_PART 1
muthmainnah
8051 MICROCONTROLLERS
◦ Availability of software
development tools, such The 8051 family has the largest number of
as compilers, diversified (multiple source) suppliers
- Intel (original)
assemblers, and - Atmel
debuggers - Philips/Signetics
- AMD
◦ Wide availability and - Infineon (formerly Siemens)
reliable sources of the - Matra
- Dallas Semiconductor/Maxim
microcontroller
SLIDE 25
25
CHAPTER 5_PART 1
muthmainnah
8051 MICROCONTROLLERS
Intel introduced 8051, referred as MCS- 51, in 1981
* The 8051 is an 8-bit processor - The CPU can work on only 8
bits of data at a time
SLIDE 26
26
CHAPTER 5_PART 1
muthmainnah
8051 MICROCONTROLLERS
The 8051 became widely popular after allowing other
manufactures to make and market any flavor of the 8051, but
remaining code-compatible
SLIDE 27
27
CHAPTER 5_PART 1
muthmainnah
SLIDE 28
28
CHAPTER 5_PART 1
muthmainnah
SLIDE 29
29
CHAPTER 5_PART 1
muthmainnah
A (Accumulator)
For all arithmetic and logic
instructions
SLIDE 30
30
CHAPTER 5_PART 1
muthmainnah
SLIDE 31
31
CHAPTER 5_PART 1
muthmainnah
SLIDE 32
32
CHAPTER 5_PART 1
muthmainnah
SLIDE 33
33
CHAPTER 5_PART 1
muthmainnah
SLIDE 34
34
CHAPTER 5_PART 1
muthmainnah
SLIDE 35
35
CHAPTER 5_PART 1
muthmainnah
SLIDE 36
36
CHAPTER 5_PART 1
muthmainnah
SLIDE 37
37
CHAPTER 5_PART 1
muthmainnah
Program Counter
The program counter points to the address of the next
instruction to be executed
As the CPU fetches the opcode from the program ROM, the
program counter is increasing to point to the next instruction
SLIDE 38
38
CHAPTER 5_PART 1
muthmainnah
Power up
All 8051 members start at memory address 0000 when
they’re powered up
* Program Counter has the value of 0000
* The first opcode is burned into ROM address 0000H,
since this is where the 8051 looks for the first
instruction when it is booted
* We achieve this by the ORG statement in the source
program
SLIDE 39
39
CHAPTER 5_PART 1
muthmainnah
SLIDE 40
40
CHAPTER 5_PART 1
muthmainnah
SLIDE 41
41
CHAPTER 5_PART 1
muthmainnah
Executing Program
1. When 8051 is powered up, the PC has 0000 and 3. The instruction at location 0004 is executed and now
starts to fetch the first opcode from location 0000 PC = 0006.
of program ROM
* Upon executing the opcode 7D, the CPU 4. After the execution of the 1-byte instruction at location
fetches the value 25 and places it in R5 0006, PC = 0007
* Now one instruction is finished, and then the
PC is incremented to point to 0002, containing 5. Upon execution of this 1-byte instruction at 0007, PC is
opcode 7F. incremented to 0008
* This process goes on until all the instructions are
2. Upon executing the opcode 7F, the value 34H is fetched and executed
moved into R7 * The fact that program counter points at the next
* The PC is incremented to 0004 instruction to be executed explains some
microprocessors call it the instruction pointer
SLIDE 42
42
CHAPTER 5_PART 1
muthmainnah
SLIDE 43
43
CHAPTER 5_PART 1
muthmainnah
SLIDE 44
44
CHAPTER 5_PART 1
muthmainnah
The flag bits affected by the ADD instruction are CY, P, AC, and OV
Example
SLIDE 45
45
CHAPTER 5_PART 1
muthmainnah
The flag bits affected by the ADD instruction are CY, P, AC, and OV
Example
SLIDE 46
46
CHAPTER 5_PART 1
muthmainnah
Stack
The stack is a section of RAM used by the CPU to store information
temporarily
-This information could be data or an address
The register used to access the stack is called the SP (stack pointer)
register
- The stack pointer in the 8051 is only 8 bit wide, which means that it can
take value of 00 to FFH
- When the 8051 is powered up, the SP register contains value 07
- RAM location 08 is the first location begin used for the stack by the 8051
SLIDE 47
47
CHAPTER 5_PART 1
muthmainnah
Stack
The storing of a CPU register in the stack is called a PUSH
- SP is pointing to the last used location of the stack
- As we push data onto the stack, the SP is incremented by one
* This is different from many microprocessors
SLIDE 48
48
CHAPTER 5_PART 1
muthmainnah
Stack
Example
SLIDE 49
49
CHAPTER 5_PART 1
muthmainnah
Stack
Example
SLIDE 50
50
CHAPTER 5_PART 1
muthmainnah
Stack
Example
SLIDE 51
51
CHAPTER 5_PART 1
muthmainnah
Looping
◦
Repeating a sequence of instructions a certain number of times is called
a loop Loop action is performed by
DJNZ reg, Label
◦ The register is decremented
◦ If it is not zero, it jumps to the target
address referred to by the label
◦ Prior to the start of loop the register is
loaded with the counter for the
number of repetitions
◦ Counter can be R0 – R7 or RAM
location
SLIDE 52
52
CHAPTER 5_PART 1
muthmainnah
Nested Loop
If we◦ want to repeat an action more times than 256, we use a loop inside a
loop, which is called nested loop
◦ We use multiple registers to hold the count
SLIDE 53
53
CHAPTER 5_PART 1
muthmainnah
Conditional Jumps
◦ Jump only if a certain condition is met
◦ JZ label ;jump if A = 0
SLIDE 54
54
CHAPTER 5_PART 1
muthmainnah
Conditional Jumps
◦ label
JNC ;jump if no carry, CY = 0
SLIDE 55
55
CHAPTER 5_PART 1
muthmainnah
Conditional Jumps
Call instruction is used to call LCALL (long call
subroutine 3-byte instruction
◦ Subroutines are often used to First byte is the opcode
perform tasks that need to be Second and third bytes are used for
performed frequently address of target subroutine – Subroutine
is located anywhere within 64K byte
◦ This makes a program more address space
structured in addition to saving
memory space ACALL (absolute call)
2-byte instruction
11 bits are used for address within 2K-byte
range
SLIDE 56
56
CHAPTER 5_PART 1
muthmainnah
Conditional Jumps
When a subroutine is called, control is transferred to that subroutine,
the processor
SLIDE 57
57
CHAPTER 5_PART 1
muthmainnah
Unconditional Jumps
The unconditional jump is a jump in which control is transferred
unconditionally to the target location
LJMP (long jump) SJMP (short jump)
3-byte instruction 2-byte instruction
First byte is the opcode First byte is the opcode
Second and third bytes represent Second byte is the relative target
the 16-bit target address – Any address – 00 to FFH (forward +127
memory location from 0000 to and backward -128 bytes from the
FFFFH current PC)
SLIDE 58
58
CHAPTER 5_PART 1
muthmainnah
SLIDE 59
59
CHAPTER 5_PART 1
muthmainnah
SLIDE 60
60
CHAPTER 5_PART 1
muthmainnah
CALL INSTRUCTIONS
Call instruction is used to call subroutine
◦ Subroutines are often used to perform tasks that need to be performed frequently
◦ This makes a program more structured in addition to saving memory space
SLIDE 61
61
CHAPTER 5_PART 1
muthmainnah
SLIDE 62
62
CHAPTER 5_PART 1
muthmainnah
SLIDE 63
63
CHAPTER 5_PART 1
muthmainnah
CALLING SUBROUTINES
SLIDE 64
64
CHAPTER 5_PART 1
muthmainnah
TIME DELAY
◦ CPU executing an instruction takes a certain number
of clock cycles
These are referred as to as machine
cycles
◦ The length of machine cycle depends on the
frequency of the crystal oscillator connected to 8051
◦ In original 8051, one machine cycle lasts 12 oscillator
periods
SLIDE 65
65
CHAPTER 5_PART 1
muthmainnah
TIME DELAY
SLIDE 66
66
CHAPTER 5_PART 1
muthmainnah
DELAY CALCULATION
SLIDE 67
67
CHAPTER 5_PART 1
muthmainnah
END of PART 1
Let's do exercises
SLIDE 68
68