EE6502 MPMC UNIT 1-5 (Read-Only)
EE6502 MPMC UNIT 1-5 (Read-Only)
EE6502 MPMC UNIT 1-5 (Read-Only)
Microprocessors and
Microcontrollers
DEPARTMENTS: EEE {semester 05}
Regulation : 2013
Presented by
C.GOKUL,AP/EEE
Velalar College of Engg & Tech , Erode
1
syllabus
2
Microprocessor
• Microprocessor (µP) is the “brain” of a computer that
has been implemented on one semiconductor chip.
• The word comes from the combination micro and
processor.
• Processor means a device that processes
whatever(binary numbers, 0’s and 1’s)
To process means to manipulate. It describes all
manipulation.
Micro - > extremely small
3
Definition of a Microprocessor.
The microprocessor is a programmable
device that takes in numbers, performs on
them arithmetic or logical operations
according to the program stored in memory
and then produces other numbers as a result.
4
Microprocessor ?
A microprocessor is multi
programmable clock driven
register based semiconductor
device that is used to fetch ,
process & execute a data
within fraction of seconds.
5
Applications
• Calculators
• Accounting system
• Games machine
• Instrumentation
• Traffic light Control
• Multi user, multi-function environments
• Military applications
• Communication systems
6
MICROPROCESSOR HISTORY
7
DIFFERENT PROCESSORS AVAILABLE
Socket
Pinless
Processor
Processor Slot
Processor
ProcessorSl
ot
8
Development of Intel Microprocessors
• 8086 - 1979
• 286 - 1982
• 386 - 1985
• 486 - 1989
• Pentium - 1993
• Pentium Pro - 1995
• Pentium MMX -1997
• Pentium II - 1997
• Pentium II Celeron - 1998
• Pentium II Zeon - 1998
• Pentium III - 1999
• Pentium III Zeon - 1999
• Pentium IV - 2000
• Pentium IV Zeon - 2001
9
GENERATION OF PROCESSORS
Processor Bits Speed
8080 8 2 MHz
8086 16 4.5 – 10
MHz
8088 16 4.5 – 10
MHz
80286 16 10 – 20
MHz
80386 32 20 – 40
MHz
80486 32 40 – 133
MHz
10
GENERATION OF PROCESSORS
13
8-bit Microprocessors
14
Intel 8008
Introduced in 1972.
It was first 8-bit µP.
Its clock speed was
500 KHz.
Could execute
50,000 instructions
per second.
15
Intel 8080
Introduced in 1974.
It was also 8-bit µP.
Its clock speed was 2
MHz.
It had 6,000
transistors.
16
Intel 8085 Introduced in 1976.
It was also 8-bit µP.
Its clock speed was 3 MHz.
Its data bus is 8-bit and
address bus is 16-bit.
It had 6,500 transistors.
Could execute 7,69,230
instructions per second.
It could access 64 KB of
memory.
It had 246 instructions.
17
16-bit Microprocessors
18
Introduced in 1978.
INTEL 8086 It was first 16bit µP.
Its clock speed is 4.77 MHz, 8
MHz and 10 MHz, depending on
the version.
Its data bus is 16bit and address
bus is 20bit.
It had 29,000 transistors.
Could execute 2.5 million
instructions per second.
It could access 1 MB of memory.
It had 22,000 instructions.
It had Multiply and Divide 19
instructions.
INTEL 8088
Introduced in 1979.
It was also 16bit µP.
It was created as a
cheaper version of
Intel’s 8086.
It was a 16bit processor
with an 8bit external
bus.
20
INTEL 80186 & 80188
Introduced in 1982.
They were 16bit µPs.
Clock speed was 6 MHz.
80188 was a cheaper
version of 80186 with an
8bit external data bus.
21
INTEL 80286
Introduced in 1982.
It was 16bit µP.
Its clock speed was 8
MHz.
Its data bus is 16bit and
address bus is 24bit.
It could address 16 MB
of memory.
It had 1,34,000 22
transistors.
32-BIT
MICROPROCESSORS
23
Introduced in 1986.
INTEL 80386 It was first 32bit µP.
Its data bus is 32bit and
address bus is 32bit.
It could address 4 GB of
memory.
It had 2,75,000
transistors.
Its clock speed varied
from 16 MHz to 33 MHz
depending upon the
various versions. 24
Introduced in 1989.
INTEL 80486
It was also 32bit µP.
It had 1.2 million
transistors.
Its clock speed varied
from 16 MHz to 100
MHz depending upon
the various versions.
8 KB of cache memory
was introduced.
25
Introduced in 1993.
INTEL PENTIUM
It was also 32bit µP.
It was originally named
80586.
Its clock speed was 66
MHz.
Its data bus is 32bit
and address bus is 32
bit.
26
INTEL PENTIUM PRO
Introduced in 1995.
It was also 32bit µP.
It had 21 million
transistors.
Cache memory:
8 KB for instructions.
8 KB for data.
27
INTEL PENTIUM II
Introduced in 1997.
It was also 32bit µP.
Its clock speed was 233
MHz to 500 MHz.
Could execute 333
million instructions per
second.
28
INTEL PENTIUM II XEON
Introduced in 1998.
It was also 32bit µP.
It was designed for
servers.
Its clock speed was 400
MHz to 450 MHz.
29
INTEL PENTIUM III
Introduced in 1999.
It was also 32bit µP.
Its clock speed varied
from 500 MHz to 1.4
GHz.
It had 9.5 million
transistors.
30
INTEL PENTIUM IV
Introduced in 2000.
It was also 32bit µP.
Its clock speed was from
1.3 GHz to 3.8 GHz.
It had 42 million
transistors.
31
Introduced in 2006.
INTEL DUAL CORE
It is 32bit or 64bit µP.
32
33
64-BIT
MICROPROCESSORS
34
Intel Core 2 Intel Core i3
35
INTEL CORE
I5 INTEL CORE I7
36
Basic Terms
• Bit: A digit of the binary number { 0 or 1 }
• Nibble: 4 bit Byte: 8 bit word: 16 bit
• Double word: 32 bit
• Data: binary number/code operated by an instruction
• Address: Identification number for memory locations
• Clock: square wave used to synchronize various devices
in µP
• Memory Capacity = 2^n ,
n->no. of address lines
37
BUS CONCEPT
• BUS: Group of conducting lines that carries data ,
address & control signals.
CLASSIFICATION OF BUSES:
1.DATA BUS: group of conducting lines that carries data.
2. ADDRESS BUS: group of conducting lines that carries
address.
3.CONTROL BUS: group of conducting lines that carries
control signals {RD, WR etc}
CPU BUS: group of conducting lines that directly
connected to µP
SYSTEM BUS: group of conducting lines that carries
data , address & control signals in a µP system 38
TRISTATE LOGIC
3 logic levels are:
• High State (logic 1)
• Low state (logic 0)
• High Impedance state
High Impedance: output is not being driven to any defined logic level by
the output circuit.
39
Basic Microprocessors System
Central Processing Unit
Arithmetic-
Control
Logic
Unit
ProcessingUnit
Input Data into Output
Devices Information
Primary Storage Devices
Unit
Keyboard, Monitor
Mouse Printer
etc
1
8085 PROCESSOR
41
UNIT 1 Syllabus
• Hardware Architecture, pinouts
• Functional Building Blocks of Processor
• Memory organization
• I/O ports and data transfer concepts
• Timing Diagram
• Interrupts.
42
8085
PIN DIAGRAM &
ARCHITECTURE
43
PIN CONFIGURATION
44
X1 & X 2
Pin 1 and Pin 2 (Input)
These are also called
Crystal Input Pins.
47
RESET IN and RESET OUT
Pin 36 (Input) and Pin 3 (Output)
RESET OUT:
◦ It is an output signal.
49
SID and SOD
Pin 4 (Input) and Pin 5 (Output)
SOD(Serial Output
Data):
50
Interrupt Pins
Interrupt:
51
Sequence of Steps Whenever
There is an Interrupt
Microprocessor completes execution of current
instruction of the program.
52
Five Hardware Interrupts in
8085
TRAP
RST 7.5
RST 6.5
RST 5.5
INTR
53
Classification of Interrupts
Maskable and Non-Maskable
54
Maskable Interrupts
Maskable interrupts are those
interrupts which can be enabled
or disabled.
55
Maskable Interrupts
List of Maskable Interrupts:
• RST 7.5
• RST 6.5
• RST 5.5
• INTR
56
Non-Maskable Interrupts
The interrupts which are always
in enabled mode are called non-
maskable interrupts.
TRAP is a non-maskable
interrupt. 57
Vectored Interrupts
The interrupts which have fixed
memory location for transfer of
control from normal execution.
58
Vectored Interrupts
List of vectored interrupts:
• RST 7.5
• RST 6.5
• RST 5.5
• TRAP
59
Vectored Interrupts
The addresses to which program
control goes:
RST 6.5
RST 5.5
INTR
64
Priority Based Interrupts
Priority of interrupts:
Interrupt Priority
TRAP 1
RST 7.5 2
RST 6.5 3
RST 5.5 4
INTR 5
65
TRAP
Pin 6 (Input)
Itis an non-maskable
interrupt.
It has the highest priority.
It cannot be disabled.
It is both edge and level
triggered.
Itmeans TRAP signal must go
from low to high.
And must remain high for a
certain period of time.
TRAP is usually used for
power failure and emergency
shutoff.
66
RST 7.5
Pin 7 (Input)
It is a maskable interrupt.
Ithas the second highest
priority.
It is positive edge
triggered only.
The internal flip-flop is
triggered by the rising
edge.
The flip-flop remains high
until it is cleared by
RESET IN.
67
RST 6.5
Pin 8 (Input)
It is a maskable interrupt.
Ithas the third highest
priority.
It is level triggered only.
The pin has to be held
high for a specific period
of time.
RST 6.5 can be enabled
by EI instruction.
Itcan be disabled by DI
instruction.
68
RST 5.5
Pin 9 (Input)
Itis a maskable
interrupt.
Ithas the fourth highest
priority.
It is also level triggered.
The pin has to be held
high for a specific
period of time.
This interrupt is very
similar to RST 6.5.
69
INTR
Pin 10 (Input)
It is a maskable interrupt.
It has the lowest priority.
It is also level triggered.
It is a general purpose
interrupt.
By general purpose we
mean that it can be used
to vector microprocessor
to any specific subroutine
having any address.
70
INTA
Pin 11 (Output)
Itstands for interrupt
acknowledge.
Itis an out going
signal.
Itis an active low
signal.
Low output on this pin
indicates that
microprocessor has
acknowledged the INTR
request.
71
Address and Data Pins
Address Bus:
72
Address and Data Pins
Data Bus:
73
AD0 – AD7
Pin 19-12 (Bidirectional)
These pins serve the dual
purpose of transmitting lower
order address and data byte.
74
A8 – A15
Pin 21-28 (Unidirectional)
These pins carry the
higher order of address
bus.
75
ALE
Pin 30 (Output)
Itis used to enable Address
Latch.
76
S0 and S1
Pin 29 (Output) and Pin 33 (Output)
S0
and S1 are called
Status Pins.
S0 S1 Operation
0 0 Halt
0 1 Write
1 0 Read
1 1 Opcode Fetch
77
IO/M
Pin 34 (Output)
This pin tells whether
I/O or memory operation
is being performed.
79
Table Showing IO/M, S0, S1 and
Corresponding Operations
Operations IO/M S0 S1
Opcode Fetch 0 1 1
Memory Read 0 1 0
Memory Write 0 0 1
I/O Read 1 1 0
I/O Write 1 0 1
Interrupt Ack. 1 1 1
Halt High Impedance 0 0
80
RD
Pin 32 (Output)
RD stands for Read.
It is an active low signal.
Itis a control signal used
for Read operation either
from memory or from
Input device.
A low signal indicates that
data on the data bus must
be placed either from
selected memory location
or from input device.
81
WR
Pin 31 (Output)
WR stands for Write.
It is also active low signal.
Itis a control signal used
for Write operation either
into memory or into
output device.
A low signal indicates that
data on the data bus must
be written into selected
memory location or into
output device.
82
READY
Pin 35 (Input)
This pin is used to
synchronize slower
peripheral devices with
fast microprocessor.
A low value causes the
microprocessor to enter
into wait state.
The microprocessor
remains in wait state
until the input at this
pin goes high.
83
HOLD
Pin 38 (Input)
HOLD pin is used to request
the microprocessor for DMA
transfer.
A high signal on this pin is a
request to microprocessor
to relinquish the hold on
buses.
Thisrequest is sent by DMA
controller.
Intel8257 and Intel 8237
are two DMA controllers.
84
HLDA
Pin 39 (Output)
HLDA stands for Hold
Acknowledge.
The microprocessor uses
this pin to acknowledge the
receipt of HOLD signal.
When HLDA signal goes
high, address bus, data
bus, RD, WR, IO/M pins are
tri-stated.
Thismeans they are cut-off
from external environment.
85
HLDA
Pin 39 (Output)
The control of these
buses goes to DMA
Controller.
Control remains at DMA
Controller until HOLD is
held high.
When HOLD goes low,
HLDA also goes low and
the microprocessor
takes control of the
buses.
86
VSS and VCC
Pin 20 (Input) and Pin 40 (Input)
+5V power supply
is connected to
VCC.
Ground signal is
connected to VSS.
87
THE 8085 AND ITS
The 8085 isBUSSES
an 8-bit general purpose
microprocessor that can address 64K
Byte of memory.
It has 40 pins and uses +5V for
power. It can run at a maximum
frequency of 3 MHz.
-The pins on the chip can be grouped
into 6 groups:
Address Bus.
Data Bus.
Control and Status Signals.
Power supply and frequency.
Externally Initiated Signals. 88
The Address and Data
Busses
The address bus has 8 signal lines A8 –
A15 which are unidirectional.
The other 8 address bits are multiplexed
(time shared) with the 8 data bits.
So, the bits AD0 – AD7 are bi-
directional and serve as A0 – A7 and D0
– D7 at the same time.
During the execution of the
instruction, these lines carry the
address bits during the early part,
then during the late parts of the
execution, they carry the 8 data bits.
In order to separate the address from 89
90
Flag Register
The flags are affected by the arithmetic and logical
instruction
D7 D6 D5 D4 D3 D2 D1 D0
S Z AC P CY
91
Accumulator
It is an 8 bit register
For any arithmetic and logical
instruction one of the data should be
in this register
It is used for storing the result of
any arithmetic and logical
manipulations.
It is also called as A register
93
Sign Flag
If the D7 bit of the
accumulator is set then this
flag is set i.e 1 meaning that
the result is in negative.
Ex. 7-8 = -1
94
Carry flag
During the arithmetic operation if a
carry occurs then this flag is set.
Ex. F1+1F=1 10
Carry
95
Zero flag
During the arithmetic/
logical operation if the
result is zero then this
flag is set.
Ex. FF-FF = 00
96
Parity flag
After the of the arithmetic
and logical operation if the
result is even then this flag is
set.
Ex. 0A-02 = 08
97
Auxiliary carry flag
During BCD arithmetic
operation when a carry is
generated by D3 bit and passed
on to D4 bit then this flag is set.
Ex. 1F+11 = 0001 1111 +
0001 0001
= 0010 0000
98
Timing and control
It
synchronizes all the
operation with the clock
and generates the
communication between
the microprocessor and
peripherals
99
Instruction Register and
decoder
The instruction is loaded
in the instruction register
The decoder decodes them
and establishes the
operation that has to be
performed
100
Register array
The W and Z register are
temporary registers
Used to hold the 8 bit data
during the execution and
it is used internally .
It is not used by the
programmer. 101
Control and status
signals
Machine IO/M S1 S0
Cycle
Opcode 0 1 1
fetch
Memory 0 1 0
read
Memory 0 0 1
write
I/O read 1 1 0
I/O write 1 0 1
102
Arithmetic and Logical
unit
It is an 8 bit register
It is used for performing
addition, subtraction and
logical operation.
AND, OR, NOT, XOR, CMP
are some of the logical
operation. 103
Program Counter
It is a 16 bit register
It is used to point out
the address of the next
instruction which is to
be executed
105
Register Array
B, C, D, E, H and L are
general purpose register
All are 8 bit register
106
Memory
organization
107
8085 Communication with Memory
Involves the following three steps
1. Identify the memory location (with address)
2. Generate Timing & Control signals
3. Data transfer takes place
108
Example: Memory Read Operation
2 109
8085 Interfacing with Memory chips
Address Address
Control Control
110
8085 Interfacing with Memory chips
Data
74LS373 Memory
8085 AD0-AD7 A0 – A7
Chip
ALE
A8-A15 A8-A15
Control
Memory 111
Interface
8085 Interfacing with Memory chips
Data
74LS373 Program
8085 AD0-AD7 A0 – A7
Memory
ALE
A8-A15 A8-A15
CS
IO/M
RD
RD
Memory
Interface
112
I/O ports &
Data transfer
concepts
113
Interfacing I/O devices with 8085
I/O I/O
Interface Devices
System Bus
8085
Memory Memory
Interface Devices
114
Techniques for I/O Interfacing
Memory-mapped I/O
Peripheral-mapped I/O
115
Memory-mapped I/O
8085 uses its 16-bit address bus to identify a
memory location
Memory address space: 0000H to FFFFH
8085 needs to identify I/O devices also
I/O devices can be interfaced using
addresses from memory space
8085 treats such an I/O device as a memory
location
This is called Memory-mapped I/O
116
Peripheral-mapped I/O
8085 has a separate 8-bit addressing scheme
for I/O devices
I/O address space: 00H to FFH
This is called Peripheral-mapped I/O or
I/O-mapped I/O
117
8085 Communication with I/O devices
Involves the following three steps
1. Identify the I/O device (with address)
2. Generate Timing & Control signals
3. Data transfer takes place
8085 communicates with a I/O device only if
there is a Program Instruction to do so
118
1.Identify the I/O device (with address)
1. Memory-mapped I/O (16-bit address)
2. Peripheral-mapped I/O (8-bit address)
119
2.Generate Timing & Control Signals
Memory-mapped I/O
Reading Input: IO/M = 0, RD = 0
Write to Output: IO/M = 0, WR = 0
Peripheral-mapped I/O
Reading Input: IO/M = 1, RD = 0
Write to Output: IO/M = 1, WR = 0
120
8085 Communication with I/O devices
Involves the following three steps
Identify the I/O device (with address)
Generate Timing & Control signals
Data transfer takes place
121
Peripheral I/O Instructions
IN Instruction
Inputs data from input device into the
accumulator
It is a 2-byte instruction
Format: IN 8-bit port address
Example: IN 01H
122
OUT Instruction
Outputs the contents of accumulator to an
output device
It is a 2-byte instruction
Format: OUT 8-bit port address
Example: OUT 02H
123
----------Example Program----------
WAP to read a number from input port (port
address 01H) and display it on ASCII display
connected to output port (port address 02H)
IN 01H ;reads data value 03H (example)into
;accumulator, A = 03H
MVI B, 30H;loads register B with 30H
ADD B ;A = 33H, ASCII code for 3
OUT 02H ;display 3 on ASCII display
124
Memory-mapped I/O Instructions
I/O devices are identified by 16-bit addresses
8085 communicates with an I/O device as if it
were one of the memory locations
Memory related instructions are used
For e.g. LDA, STA
LDA 8000H
Loads A with data read from input device with
16-bit address 8000H
STA 8001H
Stores (Outputs) contents of A to output device
with 16-bit address 8001H
125
----------Example Program----------
WAP to read a number from input port (port
address 8000H) and display it on ASCII
display connected to output port (port
address 8001H)
LDA 8000H;reads data value 03H (example)into
;accumulator, A = 03H
MVI B, 30H;loads register B with 30H
ADD B ;A = 33H, ASCII code for 3
STA 8001H;display 3 on ASCII display
126
Timing
Diagram of
8085
127
Timing Diagram is a graphical representation. It
represents the execution time taken by each
instruction in a graphical format. The execution
time is represented in T-states.
Instruction Cycle:
The time required to execute an instruction .
Machine Cycle:
The time required to access the memory or
input/output devices .
T-State:
•The machine cycle and instruction cycle takes
multiple clock periods.
•A portion of an operation carried out in one
system clock period is called as T-state.
128
129
Timing diagrams
• The 8085 microprocessor has 7 basic machine cycle.
They are
1. Op-code Fetch cycle(4T or 6T).
2. Memory read cycle (3T)
3. Memory write cycle(3T)
4. I/O read cycle(3T)
5. I/O write cycle(3T)
6. Interrupt Acknowledge cycle(6T or 12T)
7. Bus idle cycle
130
131
1.Opcode fetch cycle(4T or 6T)
132
OPCODE FETCH
• The Opcode fetch cycle, fetches the instructions from memory
and delivers it to the instruction register of the microprocessor
• Opcode fetch machine cycle consists of 4 T-states.
T1 State:
During the T1 state, the contents of the program counter are
placed on the 16 bit address bus. The higher order 8 bits are
transferred to address bus (A8-A15) and lower order 8 bits are
transferred to multiplexed A/D (AD0-AD7) bus.
ALE (address latch enable) signal goes high. As soon as
ALE goes high, the memory latches the AD0-AD7 bus. At
the middle of the T state the ALE goes low
133
T2 State:
During the beginning of this state, the RD’ signal goes low
to enable memory. It is during this state, the selected memory
location is placed on D0-D7 of the Address/Data multiplexed
bus.
T3 State:
In the previous state the Opcode is placed in D0-D7 of the A/D
bus. In this state of the cycle, the Opcode of the A/D bus is
transferred to the instruction register of the microprocessor.
Now the RD’ goes high after this action and thus disables the
memory from A/D bus.
T4 State:
In this state the Opcode which was fetched from the memory
is decoded.
134
2. Memory read cycle (3T)
135
• These machine cycles have 3 T-states.
T1 state:
• The higher order address bus (A8-A15) and lower order address
and data multiplexed (AD0-AD7) bus. ALE goes high so that the
memory latches the (AD0-AD7) so that complete 16-bit address
are available.
The mp identifies the memory read machine cycle from the
status signals IO/M’=0, S1=1, S0=0. This condition indicates the
memory read cycle.
T2 state:
• Selected memory location is placed on the (D0-D7) of the A/D
multiplexed bus. RD’ goes LOW
T3 State:
• The data which was loaded on the previous state is transferred
to the microprocessor. In the middle of the T3 state RD’ goes
high and disables the memory read operation. The data which
was obtained from the memory is then decoded. 136
3. Memory write cycle (3T)
137
• These machine cycles have 3 T-states.
T1 state:
• The higher order address bus (A8-A15) and lower order address
and data multiplexed (AD0-AD7) bus. ALE goes high so that the
memory latches the (AD0-AD7) so that complete 16-bit address
are available.
The mp identifies the memory read machine cycle from the
status signals IO/M’=0, S1=0, S0=1. This condition indicates the
memory read cycle.
T2 state:
• Selected memory location is placed on the (D0-D7) of the A/D
multiplexed bus. WR’ goes LOW
T3 State:
• In the middle of the T3 state WR’ goes high and disables the
memory write operation. The data which was obtained from the
memory is then decoded.
138
4.I/O read cycle(3T)
139
5.I/O write cycle(3T)
140
STA instruction
ex: STA 526A
141
It require 4 m/c cycles
13 T states
1.opcode fetch(4T)
2.memory read(3T)
3.memory read(3T)
4.Memory write(3T)
142
143
Timing diagram for IN C0H
• Fetching the Opcode DBH from the memory
4125H.
• Read the port address C0H from 4126H.
• Read the content of port C0H and send it to
the accumulator.
• Let the content of port is 5EH.
144
It require 3 m/c cycles
10 T states
opcode fetch(4T)
memory read(3T)
I/O read(3T)
145
Presented by C.GOKUL,AP/EEE Velalar College of Engg & Tech , Erode
146
OUT
instruction
Machines Cycles(10T):
1.instruction fetch(4T)
2.memory read (3T)
3.IO write (3T)
147
148
Timing diagram for MVI B, 43h
• Fetching the Opcode 06H from the memory
2000H. (OF machine cycle)
• Read (move) the data 43H from memory
2001H. (memory read)
149
150
INR M
151
ADD M
152
8085
Interrupts
153
8085 Interrupts
8085 has five interrupt inputs
1. TRAP
2. RST7.5
3. RST 6.5
4. RST5.5
5. INTR
154
U7
1 40
2 X1 VCC 39
3 X2 HOLD 38
4 RST-OT HLDA 37
5 SOD CLKO 36
6 SID RST-IN 35
7 TRAP READY 34
8 RST7.5 IO /M 33
9 RST6.5 S1 32
10 RST5.5 RD 31
11 IN TR WR 30
12 IN TA ALE 29
13 AD0 S0 28
14 AD1 A15 27
15 AD2 A14 26
16 AD3 A13 25
17 AD4 A12 24
18 AD5 A11 23
19 AD6 A10 22
20 AD7 A9 21
VSS A8
Interrupt
8085 pins of 8085 155
Types of Interrupts
• Interrupts of 8085 can be classified as
– Maskable (RST 7.5, RST 6.5, RST 5.5, INTR)
– Non-maskable (TRAP)
• An interrupt is a request for attention/service
• 8085 may choose to service/not-service a
maskable interrupt
• 8085 cannot ignore a service request from a
non-maskable interrupt
156
Interrupt process
• 8085 is executing its main program
• an interrupt is generated by an external
device
• 8085 pauses execution of main program
• 8085 calls the Interrupt service routine
• 8085 executes the Interrupt service
routine
• 8085 returns to execution of main program
(from where it was paused) 157
Example: Blinking LED Display with
Interrupt-based Display-Pattern change
8085
Input
LED
Switches
Display
(Display-
158
Pattern)
Interrupt Service Routine (ISR)
• It is a subroutine
• 8085 calls an ISR in response to an
interrupt request by an external device
• ISRs must be located in memory at pre-
determined addresses known as Interrupt
Vectors
159
Interrupt Vector Table of 8085
Interrupt Interrupt Vector
TRAP 0024H
RST 7.5 003CH
RST 6.5 0034H
RST 5.5 002CH
160
Using Vectored Interrupts of 8085
• By default, all the vectored interrupts (except
TRAP) of 8085 are disabled
• 8085 vectored interrupts are enabled with
two instructions: EI and SIM
• EI (Enable Interrupt): 1-byte instruction that
sets the Interrupt Enable flip-flop
– It is internal to the processor & can be set or reset
by using software instructions
161
Using Vectored Interrupts
Step-1
• Set Interrupt Enable flip-flop by using EI
instruction to enable the interrupt process
Step-2
• Use SIM (Set Interrupt Mask) instruction to
set mask for RST 7.5, 6.5 and 5.5
interrupts
162
SIM Instruction
• It is a 1-byte instruction
• Reads Accumulator contents
• Enables/Disables interrupts accordingly
• Used for three different functions
– Set mask for RST 7.5, 6.5, 5.5 interrupts
– Additional control for RST 7.5
– Implement serial I/O
163
Accumulator bit pattern for SIM
D7 D6 D5 D4 D3 D2 D1 D0
SOD SDE XXX R7.5 MSE M7.5 M6.5 M5.5
0 = Available, 1 = Masked
If 1, bit 7 is output to
serial output data latch
165
8085 Interrupt process for
Vectored-Interrupts (Cont.)
4. When 8085 detects an interrupt signal from
an external device
• It completes execution of current
instruction
• Disables the Interrupt Enable flip-flop
5. Executes a CALL to Interrupt Vector
location for that interrupt
• Before the CALL is made, 8085 stores
return address in main program on stack
166
8085 Interrupt process for
Vectored-Interrupts (Cont.)
6. 8085 executes the ISR written at the
specified interrupt vector location
• ISR should include the EI instruction to
Enable Interrupt again
• At the end of ISR, RET instruction
transfers the program control back to the
main program
167
Presented by C.GOKUL,AP/EEE Velalar College of Engg & Tech , Erode
UNIT
2
PROGRAMMING OF 8085 PROCESSOR
Presented by
C.GOKUL,AP/EEE
Velalar College of Engg & Tech , Erode
168
UNIT 2 Syllabus
• Instruction -format and addressing
modes
• Assembly language format – Data
transfer, data manipulation& control
instructions
• Programming: Loop structure with
counting & Indexing – Look up table -
Subroutine instructions - stack.
169
Addressing
Modes of
8085
170
Addressing Modes of 8085
• Format of a typical Assembly language instruction is
given below-
[Label:] Mnemonic [Operands] [;comments]
HLT
MVI A, 20H
MOV M, A ;Copy A to memory location whose
address is stored in register pair HL
LOAD: LDA 2050H ;Load A with contents of memory
location with address 2050H
READ: IN 07H ;Read data from Input port with
address 07H
171
• The various formats of specifying operands
are called addressing modes
• Addressing modes of 8085
1. Register Addressing
2. Immediate Addressing
3. Memory Addressing
4. Input/Output Addressing
172
1. Register Addressing
• Operands are one of the internal registers of
8085
• Examples-
MOV A, B
ADD C
173
2. Immediate Addressing
• Value of the operand is given in the instruction
itself
• Example-
MVI A, 20H
LXI H, 2050H
ADI 30H
SUI 10H
174
3. Memory Addressing
• One of the operands is a memory location
• Depending on how address of memory
location is specified, memory addressing is of
two types
– Direct addressing
– Indirect addressing
175
3(a) Direct Addressing
• 16-bit Address of the memory location is
specified in the instruction directly
• Examples-
LDA 2050H ;load A with contents of memory
location with address 2050H
STA 3050H ;store A with contents of memory
location with address 3050H
176
3(b) Indirect Addressing
• A memory pointer register is used to store the
address of the memory location
• Example-
MOV M, A ;copy register A to memory location
whose address is stored in register
pair HL
H L
A 30H 20H 50H 2050H 30H
177
4. Input/Output Addressing
• 8-bit address of the port is directly specified in
the instruction
• Examples-
IN 07H
OUT 21H
178
Instruction
set
179
Instruction set
An instruction is a binary
pattern designed inside a
microprocessor to perform a
specific function.
A group of instruction
together called as instruction
set.
Group of instruction set is
called as a program. 180
Classification of
instruction set
According to word size or
byte size it is classified into
3 types.
1 - byte instruction
2 - byte instruction and
3 - byte instruction
181
1. One-byte Instructions
• Includes Opcode and Operand in the same byte
• Examples-
182
2. Two-byte Instructions
• First byte specifies Operation Code
• Second byte specifies Operand
• Examples-
Opcode Operand Binary Code Hex Code
MVI A, 32H 0011 1110 3EH
0011 0010 32H
MVI B, F2H 0000 0110 06H
1111 0010 F2H
183
3. Three-byte Instructions
• First byte specifies Operation Code
• Second & Third byte specifies Operand
• Examples-
Opcode Operand Binary Code Hex Code
LXI H, 2050H 0010 0001 21H
0101 0000 50H
0010 0000 20H
LDA 3070H 0011 1010 3AH
0111 0000 70H
0011 0000 30H
184
Instruction Set of 8085
An instruction is a binary pattern designed
inside a microprocessor to perform a specific
function.
The entire group of instructions that a
microprocessor supports is called Instruction
Set.
8085 has 246 instructions.
Each instruction is represented by an 8-bit
binary value.
These 8-bits of binary value is called Op-Code
or Instruction Byte.
Presented by C.GOKUL,AP/EEE Velalar College of Engg & Tech , Erode 18
Classification of Instruction
Set
18
1.Data Transfer
Instructions
These instructions move data
between registers, or between
memory and registers.
These instructions copy data
from source to
destination(without changing the
original data ).
18
MOV-Copy from source to destination
Opcode Operand
Rd, Rs
MOV M, Rs
Rd, M
This instruction copies the contents of the
source register into the destination register.
(contents of the source register are not
altered)
A F A F
B 3 C B 3 C
0 MOV M,B 0
D E D E 30
H 2 L 5 H 2 L 5
0 0
A 0 F 0 A F
B C B C 4
D E MOV C,M 0
H 2 L 5 40 D E 40
18
MVI-Move immediate 8-bit
Opcode Operand
Rd, Data
MVI M, Data
19
BEFORE EXECUTION AFTER EXECUTION
A F A F
B C MVI B,60H B 6 C
D E 0
H L D E
H L
BEFORE EXECUTION AFTER EXECUTION
204FH 204F
4
HL=2050 HL=2050
MVI M,40H 0
2051H 2051H
19
LDA-Load accumulator
Opcode Operand
19
BEFORE EXECUTION AFTER EXECUTION
A A 3
3 LDA 0
2000H 2000H 3
0 2000H 0
19
LDAX-Load accumulator indirect
Opcode Operand
LDAX B/D Register Pair
Example: LDAX D
19
BEFORE EXECUTION AFTER EXECUTION
A F A 8 F
0
B C 8 B C 8
2030H
2030H
0 LDAX D 0
D 2 E 3 D 2 E 3
0 0 0 0
19
LXI-Load register pair immediate
Opcode Operand
LXI Reg. pair, 16-bit data
A F A 80 F
B C 3 B C
2030H 0 9030H 50
LXI H,
2030
2031H 9
H L H 9 L 3
0 0 0
M=5
0 19
LHLD-Load H and L registers direct
Opcode Operand
LHLD 16-bit address
A F A 80 F
B C 0
8500H 60
B C
2030H
0 LHLD
H L 8 2030 H 8 L 0
5 5 0
M=6
0 19
STA-Store accumulator direct
Opcode Operand
STA 16-bit address
20
BEFORE EXECUTION AFTER EXECUTION
A 5 A
5
0 0
STA 5
2000H 2000H
2000H 0
20
STAX-Store accumulator indirect
Opcode Operand
Example: STAX B
20
BEFORE EXECUTION AFTER EXECUTION
B 8 C 0
5 0
8500H 1A
A=1A STAX B
H
20
SHLD-Store H and L registers direct
Opcode Operand
SHLD 16-bit address
Example: SHLD 2550H
20
BEFORE EXECUTION AFTER EXECUTION
D E
8500H 8
H 7 L 8 SHLD 0
8501H
0 0 8500 7
0
20
XCHG-Exchange H and L with D and E
Opcode Operand
XCHG None
Example: XCHG
20
BEFORE EXECUTION AFTER EXECUTION
D 2 E 4 D 7 E 8
0 0 0 0
XCHG
H 7 L 8 H 2 L 4
0 0 0 0
20
SPHL-Copy H and L registers to the stack
pointer
Opcode Operand
SPHL None
Example: SPHL
20
BEFORE EXECUTION
SP
H 25 L 00
SPHL
AFTER EXECUTION
SP 2500
H 25 L 00
209
XTHL-Exchange H and L with top of stack
Opcode Operand
XTHL None
Example: XTHL
21
L=SP
H=(SP+1)
SP 2700
50 SP 2700
2700H 2700H 40
H 30 L 40 H L
60 50
2701H 60
2701H 30
XTHL
2702H
2702H
211
Opcod Operan Description
e d
PCHL None Load program counter
with H-L contents
The contents of registers H and L are copied
into the program counter (PC).
Example: PCHL
Presented by C.GOKUL,AP/EEE Velalar College of Engg & Tech , Erode 21
PUSH-Push register pair onto stack
Opcode Operand
PUSH Reg. pair
Example: PUSH B
21
PUSH H
21
POP- Pop stack to register pair
Opcode Operand
POP Reg. pair
Example: POP H
21
POP H
21
IN- Copy data to accumulator from a port with 8-bit address
Opcode Operand
IN 8-bit port
address
The contents of I/O port are copied into
accumulator.
Example: IN 8C H
21
BEFORE EXECUTION
PORT 10 A
80H
IN 80H
AFTER EXECUTION
PORT 10 A 10
80H 218
OUT- Copy data from accumulator to a port with 8-bit address
Opcode Operand
OUT 8-bit port
address
The contents of accumulator are copied into
the I/O port.
Example: OUT 78H
21
BEFORE EXECUTION
PORT 10 A 40
50H
OUT 50H
AFTER EXECUTION
PORT 40 A 40
220
50H
2.Arithmetic Instructions
These instructions perform the
operations like:
◦ Addition
◦ Subtract
◦ Increment
◦ Decrement
22
ADD
BEFORE EXECUTION
AFTER EXECUTION
A 04 ADD M A 14
B C B C
D E A=A+M D E
10
H 20 L 50 10 H 20 L 50
22
BEFORE EXECUTION AFTER EXECUTION
CY
01
A 50 A 56
B C B C 20
05 ADC C D E
D E A=A+C+CY H L
H L
50+05+01=56
CY 1
A 2050H 30 ADC M A 2050H 30
06 37
H 20 L 50 A=A+M+CY
H 20 L 50
06+1+30=37 226
ADI
Example: ADI 45 H
22
BEFORE EXECUTION AFTER EXECUTION
A 03 ADI 05H A 08
A=A+DATA(8)
03+05=08
228
ACI
CY
1 ACI 20H
A 05 A=A+DATA A
26
(8)+CY 05+20+1=26 230
DAD
Opcod Operand Description
e
DAD Reg. pair Add register pair to H-L
pair
The 16-bit contents of the register pair are
added to the contents of H-L pair.
The result is stored in H-L pair.
D 12 E 34 D 12 E 34
H 23 L 45 DAD D H 35 L 79
1234
2345 +
DAD D HL=HL+DE
232
3579 DAD B HL=HL+BC
Subtraction
Any 8-bit number, or the contents of register,
or the contents of memory location can be
subtracted from the contents of accumulator.
The result is stored in the accumulator.
Subtraction is performed in 2’s complement
form.
Ifthe result is negative, it is stored in 2’s
complement form.
No two other 8-bit registers can be
subtracted directly.
23
SUB
Opcod Operan Description
e d
SUB R Subtract register or
M memory from
The contents of the register or memory location
accumulator
are subtracted from the contents of the
accumulator.
BEFORE EXECUTION
AFTER EXECUTION
A 14 SUB M A 04
B C B C
D E A=A-M D E
10
H 20 L 50 10 H 20 L 50
23
BEFORE EXECUTION AFTER EXECUTION
CY
01
A 08 A 02
B C B C 05
05 SBB C D E
D
H
E
L
A=A-C-CY H L
080501=02
CY 1
A
06
2050H 02 SBB M A
03
2050H 02
H 20 L 50 A=A-M-CY H 20 L 50
237
06021=03
SUI
Opcod Operan Description
e d
SUI 8-bit Subtract immediate from
data accumulator
The 8-bit data is subtracted from the contents
of the accumulator.
A 08 SUI 05H A 03
A=A-DATA(8)
0805=03
239
SBI
Opcod Operand Description
e
SBI 8-bit Subtract immediate from
data accumulator with borrow
CY
1 SBI 20H
A 25 A=A-DATA A
04
(8)-CY 241
252001=04
Increment / Decrement
The 8-bit contents of a register or
a memory location can be
incremented or decremented by
1.
The 16-bit contents of a register
pair can be incremented or
decremented by 1.
Increment or decrement can be
performed on any register or a
Presented by C.GOKUL,AP/EEE Velalar College of Engg & Tech , Erode 24
INR
Opcod Operan Description
e d
INR R Increment register or
M memory by 1
The contents of register or memory location are
incremented by 1.
A A
B 10 C INR B B 11 C
D
H
E
L
R=R+1 D
H
E
L
10+1=11
BEFORE EXECUTION AFTER EXECUTION
H
20
L
50 2050H 10 H
20
L
50
11 2050H
INR M
M=M+1 10+1=11 244
INX
24
BEFORE EXECUTION AFTER EXECUTION
SP SP
B C B C
D E INX H D E
H 10 L 20 RP=RP+1 H 10 L 21
1020+1=1021
246
DCR
A A
B C B C
D E 20 DCR E D E
19
H L R=R-1 H L
201=19
BEFORE EXECUTION AFTER EXECUTION
H L
H L 2050H
21
20 50
2050H 20
20 50
DCR M
M=M-1 211=20
248
DCX
24
BEFORE EXECUTION AFTER EXECUTION
SP SP
B C B C
D E DCX H D E
H 10 L 21 RP=RP-1 H 10 L 20
250
3.Logical Instructions
These instructions perform logical operations
on data stored in registers, memory and
status flags.
25
AND, OR, XOR
Any 8-bit data, or the contents of
register, or memory location can
logically have
◦ AND operation
◦ OR operation
◦ XOR operation
25
BEFORE EXECUTION 1010 1010=AAH AFTER EXECUTION
0000 1111=0FH
CY AC CY 0 AC 1
0000 1010=0AH
A AA A 0A
B 10
0F C B 0F C
ANA B
D E D E
A=A and R
H L H L
0101 0101=55H
CY AC 1011 0011=B3H CY 0 AC 1
B3 0001 0001=11H B3
A
A 55 2050H 11 2050H
H 20 L 50 ANA M H 20 L 50
A=A and M 254
Opcod Operand Description
e
ANI 8-bit data Logical AND immediate
with accumulator
The contents of the accumulator are logically
ANDed with the 8-bit data.
The result is placed in the accumulator.
S, Z, P are modified to reflect the result.
CY is reset, AC is set.
Example: ANI 86H.
25
BEFORE EXECUTION AFTER EXECUTION
1011 0011=B3H
0011 1111=3FH
0011 0011=33H
CY AC CY AC 1
ANI 3FH 0
A
B3 A=A and DATA(8) A
33
256
Opcode Operand Description
ORA R Logical OR register or memory
M with accumulator
CY AC CY 0 AC 0
ORA B
A=A or R
A AA A BA
B 12 C B 12 C
D E D E
H L H L
258
0101 0101=55H
1011 0011=B3H
BEFORE EXECUTION AFTER EXECUTION
1111 0111=F7H
CY AC CY AC 0
0
ORA M
B3
A=A or M
B3
A 55 2050H A F7 2050H
H 20 L 50 H 20 L 50
259
Opcod Operan Description
e d
ORI 8-bit Logical OR immediate
data with accumulator
CY AC CY AC
ORI 08H 0 0
A B3 A=A or DATA(8) A BB
261
Opcod Operand Description
e
XRA R Logical XOR register or
M memory with
accumulator
26
1010 1010=AAH
BEFORE EXECUTION 0010 1101=2DH AFTER EXECUTION
1000 0111=87H
CY AC CY 0 AC 0
A AA A 87
B 10 C 2D B C 2D
D E XRA C D E
H L
A=A xor R H L
263
Presented by C.GOKUL,AP/EEE Velalar College of Engg & Tech , Erode
0101 0101=55H
BEFORE EXECUTION 1011 0011=B3H AFTER EXECUTION
1110 0110=E6H
CY AC CY 0 AC 0
B3 XRA M B3
A 55 2050H A E6 2050H
A=A xor M
H 20 L 50 H 20 L 50
264
Opcod Operand Description
e
XRI 8-bit data XOR immediate with
accumulator
CY AC CY AC
XRI 39H 0 0
266
Compare
Any 8-bit data, or the contents of
register, or memory location can be
compares for:
◦ Equality
◦ Greater Than
◦ Less Than
26
BEFORE EXECUTION AFTER EXECUTION
A>R: CY=0
CY Z A=R: ZF=1 CY 01 Z 0
A<R: CY=1
A 10 A 10
B 10 C B C
D 20 E CMP D D 20 E
H L
A-R H L
10<20:CY=01
BEFORE EXECUTION AFTER EXECUTION
A>M: CY=0
A=M: ZF=1
CY Z A<M: CY=1 CY 0 ZF 1
A B8
B8 A B8
B8
2050H 2050H
H 20 L 50
CMP M H 20 L 50
A-M 269
B8=B8 :ZF=01
Opcod Operan Description
e d
CPI 8-bit Compare immediate with
data accumulator
27
BEFORE EXECUTION AFTER EXECUTION
A>DATA: CY=0
A=DATA: ZF=1
A<DATA: CY=1
CY Z CY AC
CPI 30H 0 0
A-DATA
A BA A BA
BA>30 : CY=00 271
Rotate
Each bit in the accumulator can
be shifted either left or right to
the next position.
27
Opcod Operand Description
e
RLC None Rotate accumulator left
CY B7 B6 B5 B4 B3 B2 B1 B0
AFTER EXECUTION
B7 B6 B5 B4 B3 B2 B1 B0 B7
274
Opcod Operan Description
e d
RRC None Rotate accumulator right
B7 B6 B5 B4 B3 B2 B1 B0 CY
AFTER EXECUTION
B0 B7 B6 B5 B4 B3 B2 B1 B0
276
Opcod Operand Description
e
RAL None Rotate accumulator left
through carry
CY B7 B6 B5 B4 B3 B2 B1 B0
AFTER EXECUTION
B7 B6 B5 B4 B3 B2 B1 B0 CY
278
Opcod Operand Description
e
RAR None Rotate accumulator right
through carry
B7 B6 B5 B4 B3 B2 B1 B0 CY
AFTER EXECUTION
CY B7 B6 B5 B4 B3 B2 B1 B0
280
Complement
The contents of accumulator can
be complemented.
Each 0 is replaced by 1 and each
1 is replaced by 0.
28
Opcode Operand Description
A 00 A FF
28
Opcode Operand Description
CMC None Complement carry
C 00 C FF
28
Opcod Operand Description
e
STC None Set carry
Sset (1) Cclear (0)
28
4.Branching
Instructions
The branch group
instructions allows the
microprocessor to change the
sequence of program either
conditionally or under certain
test conditions. The group
includes,
(1) Jump instructions,
(2) Call and Return
28
Opcod Operand Description
e
JMP 16-bit Jump unconditionally
address
28
Opcode Operand Description
28
Jump Conditionally
Opcode Description Status Flags
JC Jump if Carry CY = 1
28
Opcode Operand Description
28
Call Conditionally
Opcode Description Status Flags
CC Call if Carry CY = 1
29
Opcod Operan Description
e d
RET None Return unconditionally
29
Return Conditionally
Opcode Description Status Flags
RC Return if Carry CY = 1
29
Opcod Operand Description
e
RST 0–7 Restart (Software
Interrupts)
29
Opcod Operand Description
e
NOP None No operation
29
Opcod Operand Description
e
HLT None Halt
29
Opcode Operand Description
DI None Disable interrupt
29
Opcod Operand Description
e
RIM None Read Interrupt Mask
30
Opcod Operand Description
e
SIM None Set Interrupt Mask
30
SIM Instruction
30
8085
Assembly
Language
Programmin
g 30
Example Data Transfer (Copy)
Operations / Instructions
1. Load a 8-bit number MVI B, 4FH
4F in register B
2. Copy from Register B MOV A,B
to Register A
LXI H, 2050H
3. Load a 16-bit number
2050 in Register pair MOV M,B
HL
4. Copy from Register B OUT 01H
to Memory Address IN 07H
2050
5. Copy between Input / 305
Example Arithmetic
Operations / Instructions
1. Add a 8-bit number 32H to ADI 32H
Accumulator
2. Add contents of Register B ADD B
to Accumulator
SUI 32H
3. Subtract a 8-bit number
32H from Accumulator SUB C
4. Subtract contents of
Register C from INR D
Accumulator
DCR E
5. Increment the contents of
Register D by 1 306
Example Logical & Bit Manipulation
Operations / Instructions
1. Logically AND Register H ANA H
with Accumulator
2. Logically OR Register L with ORA L
Accumulator
3. Logically XOR Register B XRA B
with Accumulator
4. Compare contents of CMP C
Register C with Accumulator
5. Complement Accumulator CMA
6. Rotate Accumulator Left RAL
307
Example Branching
Operations / Instructions
1. Jump to a 16-bit Address JC 2080H
2080H if Carry flag is SET
JMP 2050H
2. Unconditional Jump
CALL 3050H
3. Call a subroutine with its
16-bit Address RET
4. Return back from the Call CNC 3050H
5. Call a subroutine with its
16-bit Address if Carry flag RZ
is RESET
6. Return if Zero flag is SET
308
Writing a Assembly Language Program
309
Program 8085 in Assembly language to add two 8-
bit numbers and store 8-bit result in register C.
• Copy A to register C
3. Store result • Stop processing
4. Stop
311
4. Make a Flowchart
Start
• Load 1st no. in register D
Load Registers D, E • Load 2nd no. in register E
• Stop processing
Stop
312
5. Assembly Language Program
1. Get two numbers
a) Load 1st no. in register D MVI D, 2H
b) Load 2nd no. in register E MVI E, 3H
2. Add them
a) Copy register D to A MOV A, D
b) Add register E to A ADD E
3. Store result
a) Copy A to register C MOV C, A
4. Stop
a) Stop processing HLT
313
Program 8085 in Assembly language to add two 8-
bit numbers. Result can be more than 8-bits.
314
• How 8085 does it?
– Adds register A and B
– Stores 8-bit result in A
– SETS carry flag (CY) to indicate carry bit
10011001 99H A
+
10011001 99H B
0
1 10011001
00110010 32H
99H A
CY 315
• Storing result in Register memory
CY A
1 10011001 32H
Register B Register C
Step-1 Copy A to C
Step-2
a) Clear register B
b) Increment B by 1
316
2. Program Logic
317
Translation to 8085
3. Algorithm
operations
Copy A to C
Stop
319
Presented by C.GOKUL,AP/EEE Velalar College of Engg & Tech , Erode
5. Assembly Language Program
• Load registers D, E MVI D, 2H
MVI E, 3H
• Copy register D to A
• Add register E to A MOV A, D
• Copy A to register C ADD E
MOV C, A
• Use Conditional
JNC END
Jump instructions
• Clear register B MVI B, 0H
• Increment B INR B
• Stop processing END: HLT
320
8 bit ADDITION
321
322
8 bit Subtraction
323
324
8 bit Multiplication
325
326
8 bit Division
327
328
Ascending & Descending order
329
Ascending Order
330
Descending order
331
Smallest Number in an Array
332
333
Largest Number in an Array
334
335
Presented by C.GOKUL,AP/EEE Velalar College of Engg & Tech , Erode
336
Basics
Microprocessor &
Microcontroller
337
What is Microcontroller?
Micro Controller
Microprocessors
CPU for Computers
No RAM, ROM, I/O on CPU chip itself
Example: Intel's x86, Motorola’s
680x0
Microcontroller
A smaller computer
On-chip RAM, ROM, I/O ports...
Example: Motorola’s 6811, Intel’s 8051,
Zilog’s Z8 and PIC
340
341
Microprocessor Microcontroller
CPU is stand-alone,
CPU, RAM, ROM, I/O and
timer are all on a single
RAM, ROM, I/O, timer chip
are separate
Fix amount of on-chip
Designer can decide ROM, RAM, I/O ports
on the amount of
ROM, RAM and I/O
For applications in which
cost, power and space are
ports. critical
Expansive Not Expansive
General-purpose Single-purpose
342
Microcontrollers Applications
Home
Appliances, intercom, telephones, security systems, garage door
openers, answering machines, fax machines, home computers,
TVs, cable TV tuner, VCR, camcorder, remote controls, video
games, cellular phones, musical instruments, sewing machines,
lighting control, paging, camera, pinball machines, toys, exercise
equipment etc.
Office
Telephones, computers, security systems, fax machines,
microwave, copier, laser printer, color printer, paging etc.
Auto
Trip computer, engine control, air bag, ABS, instrumentation,
security system, transmission control, entertainment, climate
control, cellular phone, keyless entry
343
344
UNIT-3
8051
MICROCONTROLLER
DEPARTMENTS: EEE {semester 05}
Regulation : 2013
Presented by
C.GOKUL,AP/EEE
Velalar College of Engg & Tech ,
Erode
UNIT 3 Syllabus
• Architecture of 8051
• Special Function Registers(SFRs)
• I/O Pins Ports and Circuits {Pin Diagram}
• Instruction set
• Addressing modes
• Assembly language programming
345
346
8051 Family
The 8051 is a subset of the 8052
The 8031 is a ROM-less 8051
Add external ROM to it
You lose two ports, and leave only 2 ports
for I/O operations
347
Introduction to
8051
MICROCONTROLLER
348
8051 Microcontroller
Intel introduced 8051, developed in the year
1981.
The 8051 is an 8-bit controller.
D0-D7 DATA LINES
A0-A15 ADDRESS LINES
External Interrupts
Bus Serial
OSC 4 I/O Ports
Control Port
TXD RXD
P0 P1 P2 P3
8051 Features 350
8 bit CPU
On-chip clock oscillator
4K bytes of on-chip Program Memory-ROM
128 bytes of on-chip Data RAM
64KB Program Memory address space
64KB Data Memory address space
32 bidirectional I/0 lines (Port 0,1,2,3)
Port 0 { P0.0-P0.7 } – 8 pins
Port 1 { P1.0-P1.7 } – 8 pins
Port 2 { P2.0-P2.7 } – 8 pins
Port 3 { P3.0-P3.7 } – 8 pins
351
Two 16-bit timer/counters(Timer 1,Timer 0)
One serial port
UART(Universal Asynchronous Receiver Transmitter)
6-source interrupt structure
1. External interrupt INT0
2. Timer interrupt T0
3. External interrupt INT1
4. Timer interrupt T1
5. Serial communication interrupt
6. Timer Interrupt T2
4 Register Banks (Bank 0, Bank 1, Bank 2, Bank 3)
Pin Description
of the 8051
353
355
Port 3
• Port 3 can be used as input or output.
356
Pin Description Summary
PIN TYPE NAME AND FUNCTION
358
Architecture of
8051
microcontroller
359
360
361
362
External
External
60K
64K 64K
SFR
Bank 3 R0 R1 R2 R3 R4 R5 R6 R7
Bank 2 R0 R1 R2 R3 R4 R5 R6 R7
Bank 1 R0 R1 R2 R3 R4 R5 R6 R7
Bank 0 R0 R1 R2 R3 R4 R5 R6 R7
368
Program Status Word [PSW]
C AC F0 RS1 RS0 OV F1 P
Carry Parity
Auxiliary Carry User Flag 1
00-Bank 0
01-Bank 1
10-Bank 2
11-Bank 3
369
Data Pointer Register (DPTR)
It consists of two separate registers:
DPH (Data Pointer High) &
DPL (Data Pointer Low).
370
Stack Pointer (SP) Register
8 bit
8 bit
8 bit
8 bit
371
8051 Interrupts
373
Interrupt
– Upon receiving an interrupt signal, the
microcontroller interrupts whatever it is doing
and serves the device.
– The program which is associated with the
interrupt is called the interrupt service routine
(ISR) .
378
8051 Interrupt related Registers
• The various registers associated with the use of
interrupts are:
– TCON - Edge and Type bits for External Interrupts 0/1
– IE - interrupt Enable
– IP - Interrupts priority
379
Enabling and Disabling an Interrupt
• The register called IE (interrupt enable) that is
responsible for enabling (unmasking) and disabling
(masking) the interrupts.
380
Interrupt Enable (IE) Register
--
• EA : Global enable/disable.
• --- : Reserved for additional interrupt hardware.
MOV IE,#08h • ES : Enable Serial port interrupt.
or
SETB ET1 • ET1 : Enable Timer 1 control bit.
• EX1 : Enable External 1 interrupt.
• ET0 : Enable Timer 0 control bit.
• EX0 : Enable External 0 interrupt.
381
Interrupt Priority
382
Interrupt Priority (IP) Register
Serial Port
Timer 1 Pin INT 0 Pin
UNIT 2 UNIT 5
NOTE: Refer Unit 2 & Unit 5 385
UNIT-4
386
Peripheral
interfacing
DEPARTMENTS: EEE {semester 05}
Regulation : 2013
Presented by
C.GOKUL,AP/EEE
Velalar College of Engg & Tech ,
Erode
UNIT 4 Syllabus
Introduction: Memory Interfacing & I/O interfacing
• 8255 PPI {Parallel communication interface}
• 8259 {Programmable Interrupt controller }
• 8253/8254 Timer – {Timer {or counter}}
• 8237/8257 {DMA controller}
• 8251 USART {Serial communication interface}
• 8279 {Keyboard /display controller}
• A/D and D/A Interface {ADC 0800/0809,DAC 0800}
[Interfacing with 8085 & 8051]
Introduction to
peripheral
interfacing
388
389
Data Transfers
Synchronous ----- Usually occur
when peripherals are located within
the same computer as the CPU. Close
proximity allows all state bits change
at same time on a common clock.
Asynchronous ----- Do not require
that the source and destination use
the same system clock.
390
Parallel communication
interface
INTEL 8255
8255 PPI
• The 8255 chip is also called as Programmable
Peripheral Interface.
• The Intel’s 8255 is designed for use with Intel’s
8-bit, 16-bit and higher capability
microprocessors
• The 8255 is a 40 pin integrated circuit (IC),
designed to perform a variety of interface
functions in a computer environment.
• It is flexible and economical.
396
Signals of 8085
8255 PIO/PPI
398
Control Logic
CS signal is the master Chip Select
A0 and A1 specify one of the two I/O
Ports
CS A1 A0 Selecte
d
0 0 0 Port A
0 0 1 Port B
0 1 0 Port C
0 1 1 Control
Register
1 X X 8255 is
not
Block Diagram of 8255A 402
403
CS , RD , WR , RESET , A1 , A0
406
1. BSR Mode
411
Bit/pin of port C
B3 B2 B1
selected
0 0 0 PC0
0 0 1 PC1
0 1 0 PC2
0 1 1 PC3
1 0 0 PC4
1 0 1 PC5
1 1 0 PC6
1 1 1 PC7
interrupt capability
413
414
Solution:
1 0 1 0 1 1 1 0 = AEH
Solution:
1 0 0 0 0 0 0 0 = 80H
Solution:
1 0 0 1 1 0 1 1 = 9BH
INTERRUPT
CONTROLLER
INTEL 8259
8259 Programmable Interrupt Controller (PIC)
1. This IC is designed to simplify the implementation of the interrupt interface in the 8088
and 8086 based microcomputer systems.
2. This device is known as a ‘Programmable Interrupt Controller’ or PIC.
3. It is manufactured using the NMOS technology and It is available in 28-pin DIP.
4. The operation of the PIC is programmable under software control (Programmable)and it
can be configured for a wide variety of applications.
5. 8259A is treated as peripheral in a microcomputer system.
6. 8259A PIC adds eight vectored priority encoded interrupts to the microprocessor.
7. This controller can be expanded without additional hardware to accept up to 64
interrupt request inputs. This expansion required a master 8259A and eight 8259A
slaves.
8. Some of its programmable features are:
· The ability to accept level-triggered or edge-triggered inputs.
· The ability to be easily cascaded to expand from 8 to 64 interrupt-inputs.
· Its ability to be configured to implement a wide variety of priority schemes.
8259A PIC- PIN DIGRAM
8259
ASSINGMENT OF SIGNALS FOR 8259:
1. D7- D0 is connected to microprocessor data bus D7-D0 (AD7-AD0).
2. IR7- IR0, Interrupt Request inputs are used to request an interrupt and to connect to a slave in a
system with multiple 8259As.
3. WR - the write input connects to write strobe signal of microprocessor.
4. RD - the read input connects to the IORC signal.
5. INT - the interrupt output connects to the INTR pin on the microprocessor from the master, and is
connected to a master IR pin on a slave.
6. INTA - the interrupt acknowledge is an input that connects to the INTA signal on the system. In a
system with a master and slaves, only the master INTA signal is connected.
7. A0 - this address input selects different command words within the 8259A.
8. CS - chip select enables the 8259A for programming and control.
9. SP/EN - Slave Program/Enable Buffer is a dual-function pin.
When the 8259A is in buffered mode, this pin is an
output that controls the data bus transceivers in a
large microprocessor-based system.
When the 8259A is not in buffered mode, this pin
programs the device as a master (1) or a slave (0).
CAS2-CAS0, the cascade lines are used as outputs from
the master to the slaves for cascading multiple 8259As
in a system.
8259A PIC- BLOCK DIAGRAM
Presented by C.GOKUL,AP/EEE Velalar College of Engg & Tech , Erode
Presented by C.GOKUL,AP/EEE Velalar College of Engg & Tech , Erode
Programming the 8259A: -
The 82C59A accepts two types of command words generated by the
CPU:
1. Initialization Command Words (ICWs):
Before normal operation can begin, each 82C59A in the
system must be brought to a starting point - by a sequence of 2 to
4 bytes timed by WR pulses.
2. Operational Command Words (OCWs):
These are the command words which command the 82C59A
to operate in various interrupt modes. Among these modes are:
a. Fully nested mode.
b. Rotating priority mode.
c. Special mask mode.
d. Polled mode.
The OCWs can be written into the 82C59A anytime after
initialization.
ICW1:
Selects the vector number used with the interrupt request inputs.
For example, if we decide to program the 8259A so that it functions at vector
locations 08H-0FH, we place a 08H into this command word.
Likewise, if we decide to program the 8259A for vectors 70H-77H, we place a
70H in this ICW.
ICW3:
Is used only when ICW1 indicates that the system is operated in cascade mode.
This ICW indicates where the slave is connected to the master.
For example, if we connected a slave to IR2, then to program ICW3 for this
connection, in both master and slave, we place a 04H in ICW3.
Suppose we have two slaves connected to a master using IR0 and IR1. The
master is programmed with an ICW3 of 03H; one slave is programmed with an
ICW3 of 01H and the other with an ICW3 of 02H.
ICW4:
Is programmed only when the AEOI mod is not selected for the 8259A.
In this case, this OCW selects how the 8259A responds to an interrupt.
The modes are listed as follows in next slide:
OCW3:
Selects the register to be read, the operation of the special mask register, and
the poll command.
If polling is selected, the P-bit must be set and then output to the 8259A. The
next read operation would read the poll word. The rightmost three bits of the
poll word indicate the active interrupt request with the highest priority.
The leftmost bit indicates whether there is an interrupt, and must be checked
to determine whether the rightmost three bits contain valid information.
452
TIMER/COUNTER
INTEL 8253/8254
453
Pin diagram
RD: read signal 454
11-457
8254 Modes
Gate is low the
count will be Mode 0: An events counter enabled with G.
paused
N 1 2 2 2 3 4 5
CLK
Gate is high
OUT
Will continue
counting
GATE
count of 5 load
Mode 1: One-shot mode. s Counter will be reloaded
After gate high.
1 2 3 4 5
CLK Gate is
High output
GATE will be high
458
OUT trigger with count of 5
Mode 2: Counter generates a series of pulses 1 clock
pulse wide
1 2 3 4 5 1 2 3 4 5 1
CLK
1 2 3 4 1 2 3 4
CLK
OUT
If count is even, 50% duty cycle
count of 6 loaded otherwise OUT is high 1 cycle 459
longer
Mode 4: Software triggered one-shot.
1 2 3 4 5 6 7 8
CLK
OUT
Trigger with count of 8 In the last counting
Will be stop
(not repeated)
GATE
461
Presented by C.GOKUL,AP/EEE Velalar College of Engg & Tech , Erode
Introduction:
Direct Memory Access (DMA) is a method of allowing
data to be moved from one location to another in a
computer without intervention from the central
processor (CPU).
It is also a fast way of transferring data within (and
sometimes between) computer.
The DMA I/O technique provides direct access to the
memory while the microprocessor is temporarily
disabled.
The DMA controller temporarily borrows the address
bus, data bus and control bus from the microprocessor
and transfers the data directly from the external devices
to a series of memory locations (and vice versa).
462
The 8237 DMA controller
• Supplies memory and I/O with control signals and addresses during DMA
transfer
• 4-channels (expandable)
– 0: DRAM refresh
– 1: Free
– 2: Floppy disk controller
– 3: Free
• 1.6MByte/sec transfer rate
• 64 KByte section of memory address capability with single programming
• “fly-by” controller (data does not pass through the DMA-only memory to I/O
transfer capability)
• Initialization involves writing into each channel:
• i) The address of the first byte of the block of data that must be transferred (called
the base address).
• ii) The number of bytes to be transferred (called the word count).
463
8237 pins
• CLK: System clock
• CS΄: Chip select (decoder output)
• RESET: Clears registers, sets mask register
• READY: 0 for inserting wait states
• HLDA: Signals that the μp has relinquished buses
• DREQ3 – DREQ0: DMA request input for each channel
• DB7-DB0: Data bus pins
• IOR΄: Bidirectional pin used during programming
and during a DMA write cycle
• IOW΄: Bidirectional pin used during programming
and during a DMA read cycle
• EOP΄: End of process is a bidirectional signal used as input to terminate a DMA process or
as output to signal the end of the DMA transfer
• A3-A0: Address pins for selecting internal registers
• A7-A4: Outputs that provide part of the DMA transfer address
• HRQ: DMA request output
• DACK3-DACK0: DMA acknowledge for each channel.
• AEN: Address enable signal
• ADSTB: Address strobe
• MEMR΄: Memory read output used in DMA read cycle
• MEMW΄: Memory write output used in DMA write cycle
464
8237 block diagram
465
Block Diagram Description
466
DATA BUS BUFFER:
It contain tristate ,8 bit bi-directional buffer.
Slave mode ,it transfer data between
microprocessor and internal data bus.
Master mode ,the outputs A8-A15 bits of
memory address on data lines
(Unidirectional).
READ/CONTROL LOGIC:
It control all internal Read/Write operation.
Slave mode ,it accepts address bits and control
signal from microprocessor.
Master mode ,it generate address bits and control
signal.
467
Control logic block
It contains ,
1. Control logic
2. Mode set register and
3. Status Register.
CONTROL LOGIC:
Master mode ,It control the sequence of DMA
operation during all DMA cycles.
It generates address and control signals.
It increments 16 bit address and decrement 14 bit
counter registers.
It activate a HRQ signal on DMA channel Request.
Slave ,mode it is disabled.
468
DMA controller details
469
Basics of serial communication
1. Transmitter:
- A parallel-in, serial-out
shift register
- A serial-in, parallel-out
shift register.
-
470
Presented by C.GOKUL,AP/EEE Velalar College of Engg & Tech , Erode
TRANSMITTER 471
Receiver
472
Serial communication
interface
INTEL 8251 USART
473
Five Sections
– Read/Write Control Logic
• Interfaces the chip with MPU
– Transmitter
• Converts parallel word received from MPU into serial bits
– Receiver
• Receives serial bits from peripheral
telephone line
477
Input Signals
CS – Chip Select
When this signal goes low, 8251 is selected by
MPU for communication
C/D – Control/Data
When this signal is high, the control register
or status register is addressed
When it is low, the data buffer is addressed
Control and Status register is differentiated by
WR and RD signals, respectively
478
• WR – Write
– writes in the control register or sends outputs
to the data buffer.
– This connected to IOW or MEMW
• RD – Read
– Either reads a status from status register or
accepts data from the data buffer
– This is connected to either IOR or MEMR
• RESET - Reset
• CLK - Clock
– Connected to system clock
– Necessary for communication with
microprocessor.
479
CS C/ RD WR Function
D
0 1 1 0 MPU writes instruction in the
control register
0 1 0 1 MPU reads status from the status
register
0 0 1 0 MPU outputs the data to the Data
Buffer
0 0 0 1 MPU accepts data from the Data
Buffer
1 X X X USART is not Selected
480
• Control Register
– 16-bit register
– This register can be accessed an output port
when the C/D pin is high
• Status Register
– Checks ready status of a peripheral
• Data Buffer
Transmitter Section
register is empty
483
Receiver Section
Control words
487
488
489
490
491
Interfacing of 8255(PPI) with 8085 processor
492
11-
493
Programming 8251
8251 mode register
7 6 5 4 3 2 1 0 Mode register
Keyboard/Display
Controller
INTEL 8279
497
Introduction
The INTEL 8279 is specially
developed for interfacing
keyboard and display devices to
8085/8086 microprocessor based
system
498
Features of 8279
Simultaneous keyboard and
display operations
Scanned keyboard mode
Scanned sensor mode
8-character keyboard FIFO
1 6-character display
499
Pin Diagram
500
4 sections
Keyboard section
Display section
Scan section
Keyboard section
The keyboard section consists of
8 return lines RL0 - RL7 that can
be used to form the columns of a
keyboard matrix.
It has two additional input : shift
and control/strobe. The keys are
automatically debounced.
The two operating modes of
keyboard section are 2-key
lockout and N-key rollover.
In the 2-key lockout mode, if two 504
Display section
Scan section
The scan section has a scan counter
and four scan lines, SL0 to SL3.
In decoded scan mode, the output of
scan lines will be similar to a 2-to-4
decoder.
In encoded scan mode, the output of
scan lines will be binary count, and so
an external decoder should be used
to convert the binary count to
decoded output.
The scan lines are common for
508
SENSOR MATRIX
SENSOR MATRIX
512
B) Programmable clock :
0 0 1 P P P P P
513
c)Read FIFO / Sensor RAM : The format of this
command is given below.
D7 D6 D5 D4 D3 D2 D1 D0
0 1 0 AI X A A A
E- Error mode
X- don’t care
527
Interfacing ADC to 8051
ADC0804 is an 8 bit successive approximation analogue to digital
converter from National semiconductors. The features of ADC0804 are
differential analogue voltage inputs, 0-5V input voltage range, no zero
adjustment, built in clock generator, reference voltage can be externally
adjusted to convert smaller analogue voltage span to 8 bit resolution etc.
528
ADC Interfacing
529
D/A Interfacing
{using 8051 microcontroller}
530
8051 Connection to DAC808
531
program to send data to the DAC to generate
a stair-step ramp
532
Presented by C.GOKUL,AP/EEE Velalar College of Engg & Tech , Erode
UNIT-5
533
MICRO CONTROLLER
PROGRAMMING &
APPLICATIONS
DEPARTMENTS: EEE {semester 05}
Regulation : 2013
Presented by
C.GOKUL,AP/EEE
Velalar College of Engg & Tech ,
Erode
UNIT 5 Syllabus
• Data Transfer, Manipulation, Control
Algorithms& I/O instructions
• Simple programming exercises:
1. Key board & display interface
2. Closed loop control of servo motor
3. Stepper motor control
4. Washing Machine Control.
534
INSTRUCTION
SET OF
8051
535
8051 Instruction Set
• The instructions are grouped into 5 groups
– Arithmetic
– Logic
– Data Transfer
– Boolean
– Branching
536
1. Arithmetic Instructions
• ADD A, source
A A + <operand>.
• ADDC A, source
A A + <operand> + CY.
• SUBB A, source
A A - <operand> - CY{borrow}.
537
• INC
– Increment the operand by one. Ex: INC DPTR
• DEC
– Decrement the operand by one. Ex: DEC B
• MUL AB
Multiplication
A*B
Result
8 byte * 8 byte A=low byte,
B=high byte
• DIV AB
Division Quotient Remainder
8 byte /8 byte
A/B A B
538
Multiplication of Numbers
MUL AB ; A B, place 16-bit result in B
and A
A=07 , B=02
MUL AB ;07 * 02 = 000E where B = 00 and A = 0E
Division of Numbers
DIV AB ; A / B , 8-bit Quotient result in A &
8-bit Remainder result in B
A=07 , B=02
DIV AB ;07 / 02 = Quotient 03(A) Remainder 01 (B)
539
2. Logical
instructions
540
• ANL D,S
-Performs logical AND of destination & source
- Eg: ANL A,#0FH ANL A,R5
• ORL D,S
-Performs logical OR of destination & source
- Eg: ORL A,#28H ORL A,@R0
• XRL D,S
-Performs logical XOR of destination & source
- Eg: XRL A,#28H XRL A,@R0
541
• CPL A
-Compliment accumulator
-gives 1’s compliment of accumulator data
• RL A
-Rotate data of accumulator towards left without carry
• RLC A
- Rotate data of accumulator towards left with carry
• RR A
-Rotate data of accumulator towards right without carry
• RRC A
- Rotate data of accumulator towards right with carry
542
3. Data Transfer
Instructions
543
MOV Instruction
• MOV destination, source ; copy source to destination.
544
• MOVX
– Data transfer between the accumulator and
a byte from external data memory.
• MOVX A, @DPTR
• MOVX @DPTR, A
545
• PUSH / POP
– Push and Pop a data byte onto the stack.
• PUSH DPL
• POP 40H
546
• XCH
– Exchange accumulator and a byte variable
• XCH A, Rn
• XCH A, direct
• XCH A, @Ri
547
4.Boolean variable
instructions
548
CLR:
• The operation clears the specified bit indicated in
the instruction
• Ex: CLR C clear the carry
SETB:
• The operation sets the specified bit to 1.
CPL:
• The operation complements the specified bit
indicated in the instruction
549
• ANL C,<Source-bit>
• ORL C,<Source-bit>
550
• XORL C,<Source-bit>
• MOV P2.3,C
• MOV C,P3.3
• MOV P2.0,C
551
5. Branching
instructions
552
Jump Instructions
• LJMP (long jump):
– Original 8051 has only 4KB on-chip ROM
553
Call Instructions
• LCALL (long call):
– Target address within 64K-byte range
554
• 2 forms for the return instruction:
– Return from subroutine – RET
– Return from ISR – RETI
555
556
8051
Addressing
Modes
Presented by C.GOKUL,AP/EEE Velalar College of Engg & Tech , Erode
8051 Addressing Modes
• The CPU can access data in various ways, which are
called addressing modes
1. Immediate
2. Register
3. Direct
4. Indirect
5. Relative
6. Absolute
7. Long
8. Indexed
558
1. Immediate Addressing Mode
• The immediate data sign, “#”
• Data is provided as a part of instruction.
559
2. Register Addressing Mode
• In the Register Addressing mode, the instruction involves
transfer of information between registers.
560
3. Direct Addressing Mode
• This mode allows you to specify the operand by giving its
actual memory address
561
4. Indirect Addressing Mode
• A register is used as a pointer to the data.
• Only register R0 and R1 are used for this purpose.
• R2 – R7 cannot be used to hold the address of an
operand located in RAM.
• When R0 and R1 hold the addresses of RAM locations,
they must be preceded by the “@” sign.
MOVX A,@DPTR
562
5. Relative Addressing
• This mode of addressing is used with some type of jump
instructions, like SJMP (short jump) and conditional
jumps like JNZ
563
6. Absolute Addressing
• In Absolute Addressing mode, the absolute
address, to which the control is transferred, is
specified by a label.
• Two instructions associated with this mode
of addressing are ACALL and AJMP
instructions.
• These are 2-byte instructions
564
7. Long Addressing
• This mode of addressing is used with the
LCALL and LJMP instructions.
• It is a 3-byte instruction
• It allows use of the full 64K code space.
565
8. Indexed Addressing
• The Indexed addressing is useful when there is a
need to retrieve data from a look-up table (LUT).
566
8051
Assembly
Language
Programming(ALP)
567
ADDITION OF TWO 8 bit Numbers
ADDRESS LABEL MNEMONICS
9100: MOV A,#05
MOV B,#03
ADD A,B
MOV DPTR,#9200
MOVX @DPTR,A
HERE SJMP HERE
MUL AB DIV AB
572
573
1.Keyboard &
Display
Interfacing
KEYBOARD INTERFACING
• Keyboards are organized in a matrix of rows
and columns
The CPU accesses both rows and columns
through ports .
• Therefore, with two 8-bit ports, an 8 x 8
matrix of keys can be connected to a
microprocessor
When a key is pressed, a row and a
column make a contact
574
• Otherwise, there is no connection
between rows and columns
• A 4x4 matrix connected to two ports
The rows are connected to an
output port and the columns are
connected to an input port
575
4x4 matrix
576
577
Connection with keyboard matrix
Final Circuit
586
Stepper Motor Interfacing
• Stepper motor is used in applications such as;
dot matrix printer, robotics etc
587
588
589
Full step
590
Step angle:
• Step angle is defined as the minimum degree of rotation
with a single step.
• No of steps per revolution = 360° / step angle
• Steps per second = (rpm x steps per revolution) / 60
• Example: step angle = 2°
• No of steps per revolution = 180
591
A switch is connected to pin P2.7. Write an ALP to
monitor the status of the SW.
If SW = 0, motor moves clockwise and
If SW = 1, motor moves anticlockwise
SETB P2.7
MOV A, #66H
MOV P1,A
TURN: JNB P2.7, CW
RL A DELAY: MOV
ACALL DELAY
R1,#20
MOV P1,A
L2: MOV
SJMP TURN
R2,#50
CW: RR A
L1:DJNZ
ACALL DELAY
R2,L2
MOV P1,A
592 DJNZ
SJMP TURN
4. Washing
machine
control using
8051
A washing
machine is an electronic device that is
designed to wash laundry like clothes,
sheets, towels and other bedding. A
washing machine is built with two steel
tubs which are the inner tub and the
outer tub whose main role is to prevent
water from spilling to other parts of the
machine.
Control knobs in washing machine:
• Load select knob
• Water inlet select knob
• Mode select knob
• Program select knob
low
medium
Load select
high
Water inlet select knob:-
hot
Water inlet
cold
both-mixed
Mode select knob:-
Save mode
Mode
Normal mode
Program select knob:-
Low
Agitator rmotor
drive P2.4
Drain level
Spin motor
drive
P2.6
P0.3 Hot
P2.5 P0.4 Normal
Operation Signal Input/output Port pin no.
Load / water level Water level low Input P0.0
select Water level med Input P0.1
Water level high Input P0.2
Water inlet Hot water knob Input P0.3
Normal water knob Input P0.4
Program select Heavy Input P1.0
Normal Input P1.1
Light Input P1.2
Dedicate Input P1.3
Machine ON Machine on indic Output P2.0
Fill water Hot water inlet Output P2.1
Normal water inlet Output P2.2
Agitation control Motor rotate in cloc Output P2.3
direction
Motor rotate in Output P2.4
anticlock direc
Drain Drain valve open Output P2.5
Spin Spin motor ON/OFF Output P2.6
Washing ccomplete Washing comp indic Output P2.7
Put machine ON