EC6504 Microprocessor and Microcontroller Lecture Notes All 5 Units
EC6504 Microprocessor and Microcontroller Lecture Notes All 5 Units
Microprocessors and
Microcontrollers
DEPARTMENTS: CSE,IT,ECE,ECE,MECH
Regulation : 2013
Presented by
C.GOKUL,AP/EEE
1
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, 0s and 1s)
To process means to manipulate. It describes all
manipulation.
Micro - > extremely small
2
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.
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.
4
Applications
Calculators
Accounting system
Games machine
Instrumentation
Traffic light Control
Multi user, multi-function environments
Military applications
Communication systems
5
MICROPROCESSOR HISTORY
Processor
Slot
Processor
Processor
Slot
7
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
GENERATION OF PROCESSORS
Processor
Bits
Speed
8080
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
9
GENERATION OF PROCESSORS
Processor
Bits
Speed
Pentium
32
60 233
MHz
Pentium
Pro
32
150 200
MHz
Pentium II,
Celeron ,
Xeon
32
233 450
MHz
Pentium
III, Celeron
, Xeon
32
450 MHz
1.4 GHz
Pentium IV,
Celeron ,
Xeon
32
1.3 GHz
3.8 GHz
Itanium
64
800 MHz
3.0 GHz
10
Intel 4004
Introduced in 1971.
It was the first microprocessor
by Intel.
It was a 4-bit P.
Its clock speed was 740KHz.
It had 2,300 transistors.
It could execute around
60,000 instructions per
second.
11
Intel 4040
Introduced in 1971.
It was also 4-bit P.
12
8-bit Microprocessors
13
Intel 8008
Introduced in 1972.
It was first 8-bit P.
Its clock speed was
500 KHz.
Could execute
50,000 instructions
per second.
14
Intel 8080
Introduced in 1974.
It was also 8-bit P.
Its clock speed was
2 MHz.
It had 6,000
transistors.
15
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.
16
16-bit Microprocessors
17
INTEL 8086
Introduced in 1978.
18
INTEL 8088
Introduced in 1979.
It was created as a
cheaper version of
Intels 8086.
It was a 16-bit processor
with an 8-bit external
bus.
19
Introduced in 1982.
20
INTEL 80286
Introduced in 1982.
It was 16-bit P.
It could address 16 MB
of memory.
It had 1,34,000
transistors.
21
32-BIT MICROPROCESSORS
22
INTEL 80386
Introduced in 1986.
23
INTEL 80486
Introduced in 1989.
INTEL PENTIUM
Introduced in 1993.
Introduced in 1995.
It had 21 million
transistors.
Cache memory:
8 KB for instructions.
8 KB for data.
26
INTEL PENTIUM II
Introduced in 1997.
27
Introduced in 1998.
28
Introduced in 1999.
29
INTEL PENTIUM IV
Introduced in 2000.
30
Introduced in 2006.
It is 32-bit or 64-bit P.
31
32
64-BIT MICROPROCESSORS
33
Intel Core 2
Intel Core i3
34
INTEL CORE I5
INTEL CORE I7
35
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
36
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
37
TRISTATE LOGIC
38
Input
Devices
Arithmetic-Arithmetic
Control
Logic
Unit
ProcessingUnit
Data into
Information
Primary
Storage
Unit
Keyboard,
Mouse
etc
Output
Devices
Monitor
Printer
Disks, Tapes,
Optical Disks
39
UNIT
1
THE 8086 MICROPROCESSOR
40
8086 Microprocessor-introduction
INTEL launched 8086 in 1978
8086 is a 16-bit microprocessor with
16-bit Data Bus {D0-D15}
20-bit Address Bus {A0-A19} [can access upto
2^20= 1 MB memory locations] .
8086 Microprocessor
It provides 14, 16-bit registers.
8086 requires one phase clock with a 33%
duty cycle to provide optimized internal
timing.
Range of clock:
5 MHz for 8086
8Mhz for 8086-2
10Mhz for 8086-1
42
43
Power Supply
5V 10%
Ground
Reset
Registers, seg
regs, flags
CS: FFFFH, IP:
0000H
Clock
If high for
minimum 4
clks
Address/Data Bus:
Contains address
bits A15-A0 when ALE
is 1 & data bits D15
D0 when ALE is 0.
45
INTERRUPT
Non - maskable
interrupt
Interrupt
acknowledge
Interrupt request
46
Direct
Memory
Access
Hold
Hold
acknowledge
47
Address/Status Bus
Address bits A19
A16 & Status bits S6
S3
48
BHE#, A0:
Enables most
significant data bits
D15 D8 during read
or write operation.
S7: Always 1.
1,1: No selection
49
Min/Max mode
Minimum Mode: +5V
Maximum Mode: 0V
50
Read Signal
Write Signal
Memory or I/0
Data
Transmit/Receive
Data Bus Enable
51
S2 S1 S0
000: INTA
001: read I/O port
010: write I/O port
011: halt
100: code access
101: read memory
110: write memory
111: none -passive
Status Signal
Inputs to 8288 to
generate eliminated
signals due to max
mode.
52
Lock Output
Used to lock peripherals
off the system
Activated by using the
LOCK: prefix on any
instruction
DMA
Request/Grant
Lock Output
53
QS1 QS0
00: Queue is idle
01: First byte of opcode
10: Queue is empty
11: Subsequent byte of
opcode
Queue Status
Used by numeric
coprocessor (8087)
54
CPU functions
1. Fetch
2. Decode
3. Execute
8086 CPU
Bus Interface
Unit (BIU)
Execution Unit
(EU)
55
56
Execution Unit
Tells BIU (addresses) where to fetch
instructions or data
Decodes & Executes instructions
Dividing the work between BIU & EU
speeds up processing
57
58
Memory
Interface
BIU
Instruction Queue
Instruction
Decoder
AH
AL
BH
BL
CH
CL
DH
DL
ARITHMETIC
LOGIC UNIT
CONTROL
SYSTEM
OPERANDS
FLAGS
EU
59
Execution Unit
Main components are
Instruction Decoder
Control System
Arithmetic Logic Unit
General Purpose Registers
Flag Register
Pointer & Index registers
60
Instruction Decoder
Translates instructions fetched from memory
into a series of actions which EU carries out
Control System
Generates timing and control signals to
perform the internal operations of the
microprocessor
AH
AL
BH
BL
CH
CL
DH
DL
AH
AL
AX
BH
BL
BX
CH
CL
CX
DH
DL
DX
62
Flag Register
8086 has a 16-bit flag register
Contains 9 active flags
There are two types of flags in 8086
Conditional flags six flags, set or reset
by EU on the basis of results of some
arithmetic operations
Control flags three flags, used to control
certain operations of the processor
63
Flag Register
U U U U OF DF IF TF SF ZF U AF U PF U CF
1.
CF
CARRY FLAG
2.
PF
PARITY FLAG
3.
AF
AUXILIARY CARRY
4.
ZF
ZERO FLAG
5.
SF
SIGN FLAG
6.
OF
OVERFLOW FLAG
7.
TF
TRAP FLAG
8.
IF
INTERRUPT FLAG
9.
DF
DIRECTION FLAG
Conditional Flags
(Compatible with 8085,
except OF)
Control Flags
64
Flag Register
Auxiliary Carry Flag
Carry Flag
Sign Flag
Zero Flag
Parity Flag
15
14
13
12
11
10
OF
DF
IF
TF
SF
ZF
Direction Flag
4
AF
2
PF
0
CF
Tarp Flag
If this flag is set, the processor
enters the single step execution
mode by generating internal
interrupts after the execution of
each instruction
Interrupt Flag
Causes the 8086 to recognize
external mask interrupts; clearing IF
disables these interrupts.
65
Registers, Flag
8086 registers
categorized
into 4 groups
Sl.No.
1
Type
General purpose
register
15
14
13
12
11
10
OF
DF
IF
TF
SF
ZF
Register width
4
AF
PF
CF
Name of register
16 bit
8 bit
Pointer register
16 bit
SP, BP
Index register
16 bit
SI, DI
Instruction Pointer
16 bit
IP
Segment register
16 bit
Flag (PSW)
16 bit
Flag register
66
Special Function
AX
16-bit Accumulator
AL
8-bit Accumulator
BX
Base register
CX
Count Register
DX
Data Register
SP
Stack Pointer
BP
Base Pointer
SI
Source Index
DI
Data Index
67
68
Memory
Interface
BIU
Instruction Queue
Instruction
Decoder
AH
AL
BH
BL
CH
CL
DH
DL
ARITHMETIC
LOGIC UNIT
CONTROL
SYSTEM
OPERANDS
FLAGS
EU
69
Instruction Queue
8086 employs parallel processing
When EU is busy decoding or executing
current instruction, the buses of 8086 may
not be in use.
At that time, BIU can use buses to fetch upto
six instruction bytes for the following
instructions
BIU stores these pre-fetched bytes in a FIFO
register called Instruction Queue
When EU is ready for its next instruction, it
simply reads the instruction from the queue
in BIU
70
Pipelining
EU of 8086 does not have to wait in
between for BIU to fetch next
instruction byte from memory
So the presence of a queue in 8086
speeds up the processing
Fetching the next instruction while the
current instruction executes is called
pipelining
71
Memory Segmentation
8086 has a 20-bit address bus
So it can address a maximum of 1MB of
memory
8086 can work with only four 64KB segments
at a time within this 1MB range
These four memory segments are called
Code segment
Stack segment
Data segment
Extra segment
72
Memory
64KB Memory
Segment
00000H
2
3
4
4
5
6
7
8
9
10
1MB
Address
Range
11
12
13
14
15
16
FFFFFH
73
Code Segment
That part of memory from where BIU is
currently fetching instruction code bytes
Stack Segment
A section of memory set aside to store
addresses and data while a subprogram
executes
Memory
Code Segment
00000H
2
3
4
5
6
7
8
9
10
1MB
Address
Range
11
12
13
14
15
Stack Segment
16
FFFFFH
75
Segment Registers
hold the upper 16-bits of the starting
address for each of the segments
The four segment registers are
76
Memory
1
CS
1000 0H
00000H
Code Segment
3
4
DS
ES
4000 0H
5000 0H
Data Segment
Extra Segment
Starting Addresses
of Segments
7
8
9
10
1MB
Address
Range
11
12
13
14
15
SS
F000 0H
Stack Segment
FFFFFH
77
79
348A0H
00000H
Data
Segment
IP = 4214H
Code Byte
Memory
38AB4H
MOV AL, BL
Code
Segment
Extra
Segment
7
8
9
CS
IP
Physical Address
348A0 H
+ 4214 H
38AB4 H
1MB
Address
Range
10
11
12
13
14
15
Stack
Segment
80
FFFFFH
82
ADDRESSING
MODES OF
8086
83
84
AL=ABH, AH=10H
85
86
[SI+3]
89
90
91
[BX+SI+6] ; AH
JMP [BX+DI+6] ;
IP
[BX+SI+7]
[BX+DI+7 : BX+DI+6]
92
[ES:DI]
SI+1
SI-1
[DS:SI]
, DI
, DI
DI+1
DI-1
93
INSTRUCTION
SET of 8086
94
96
97
BEFORE
EXECUTION
AX
AFTER
EXECUTION
MOV BX,AX
2000H
BEFORE
EXECUTION
A
H
AL
B
H
BL
C
H
CL
D
H
DL
2000H
AFTER
EXECUTION
MOV CL,M
40
BX
A
H
AL
B
H
BL
C
H
CL 40
D
H
DL
40
99
Stack Pointer
100
E.g.:
(1). PUSH AX;
(2). PUSH DS;
(3). PUSH [5000H];
101
INITIAL POSITION
(1) STACK
POINTER
DECREMENTS SP & STORES HIGHER
BYTE
(2) STACK POINTER
HIGHER BYTE
LOWER BYTE
HIGHER BYTE
102
BEFORE EXECUTION
SP
2002H
BH
BL
CH
10
DH
CL
50
DL
2000H
2001H
2002H
PUSH CX
AFTER EXECUTION
SP
2000H
BH
CH
DH
BL
10
CL
DL
2000H
50
2001H
10
50
2002H
103
E.g.
(1). POP AX;
(2). POP DS;
(3). POP [5000H];
104
(1) STACK
POINTER
LOWER BYTE
HIGHER BYTE
INCREMENTS SP
LOWER BYTE
HIGHER BYTE
(3) STACK
POINTER
105
BEFORE EXECUTION
SP 2000H
BH
BL
2000H 30
2001H 50
2002H
POP BX
AFTER EXECUTION
SP 2002H
2000H 30
2001H 50
BH 5
2002H
BL 30
106
BEFORE EXECUTION
AFTER EXECUTION
AH 20 AL 40
AH 70
AL 80
BH 70 BL 80
BH 20
BL 40
XCHG AX,BX
108
109
BEFORE EXECUTION
PORT
80H
10
AL
IN AL,80H
AFTER EXECUTION
PORT
80H
10
AL 10
110
OUT 88-bit/16
bit/16--bit port address, AL/AX
It writes to the specified port address.
It copies contents of accumulator to the port
with 8-bit or 16-bit address.
DX is the only register is allowed to carry port
address.
E.g.
(1). OUT 80H,AL;
(2). OUT DX,AX; //DX contains address of 16-bit
port.
111
BEFORE EXECUTION
PORT
50H
10
AL 40
OUT 50H,AL
AFTER EXECUTION
PORT
50H
40
AL 40
112
(7) XLAT
113
8.LEA
8.
LEA 1616-bit register (source), address (dest.)
LEA Also known as Load Effective Address
(LEA).
It loads effective address formed by the
destination into the source register.
E.g.
(1). LEA BX,Address;
(2). LEA SI,Address[BX];
114
E.g.
(1). LDS BX,5000H;
(2). LES BX,5000H;
115
BX 20
10
7
0
10
5000H
20
DS/ES 40
30
5001H
30
5002H
40
5003H
116
Addition,
Subtraction,
Increment,
Decrement.
119
AFTER EXECUTION
BEFORE EXECUTION
AH
10
AL
10
ADD AX,2020H
AH 30
AL 30
1010
+2020
3030
BEFORE EXECUTION
AFTER EXECUTION
AH 10
AL 10
AH 30
AL 30
BH 20
BL
BH 20
BL 20
20
ADD AX,BX
121
BEFORE EXECUTION
AH 10
AL 10
INC AX
BEFORE EXECUTION
5000H
1010
AFTER EXECUTION
AH 10
AL 11
AFTER EXECUTION
INC [5000H]
5000H
1011
124
4. DEC source
This instruction decreases the contents of
source operand by 1.
The source may be memory location or register.
The source can not be immediate data.
The result is stored in the same place.
BEFORE EXECUTION
AH 10
AL 10
DEC AX
BEFORE EXECUTION
5000H
1010
AFTER EXECUTION
AH 10
AL 09
AFTER EXECUTION
DEC [5000H]
5000H
1009
126
127
BEFORE EXECUTION
AH 20
AL 00
AFTER EXECUTION
SUB AX,1000H
AH 10
AL 00
2000
-1000
=1000
BEFORE EXECUTION
AH 20
AL
00
BH 10
BL
00
AFTER EXECUTION
SUB AX,BX
AH 10
AL
00
BH 10
BL
00
128
BEFORE EXECUTION
B 1
AFTER EXECUTION
SBB AX,1000H
AH 10 AL 19
AH 20 AL 20
BEFORE EXECUTION
2020
- 1000
10201=1019
AFTER EXECUTION
B 1
AH
20
AL
20
BH
10
BL
10
SBB AX,BX
AH 10
AL 19
BH 10
BL
10
2050
130
BEFORE EXECUTION
AH
10
AL
00
BH
10
BL
00
D=S: CY=0,Z=1
D>S: CY=0,Z=0
D<S: CY=1,Z=0
CMP AX,BX
BEFORE EXECUTION
AH
10
AL
00
BH
00
BL
10
CMP AX,BX
BEFORE EXECUTION
AH
10
AL
00
BH
20
BL
00
CMP AX,BX
AFTER EXECUTION
CY
AFTER EXECUTION
CY
AFTER EXECUTION
CY
1 Z
132
MUL operand
Unsigned Multiplication.
Operand contents are positively signed.
Operand may be general purpose register or memory
location.
If operand is of 8-bit then multiply it with contents of AL.
If operand is of 16-bit then multiply it with contents of AX.
Result is stored in accumulator (AX).
(2). MUL CX
135
IMUL operand
Signed Multiplication.
Operand contents are negatively signed.
Operand may be general purpose register, memory location
or index register.
If operand is of 8-bit then multiply it with contents of AL.
If operand is of 16-bit then multiply it with contents of AX.
Result is stored in accumulator (AX).
(2). IMUL CX
// AX= AL*BH;
// AX=AX*CX;
136
DIV operand
Unsigned Division.
Operand may be register or memory.
Operand contents are positively signed.
Operand may be general purpose register or
memory location.
AL=AX/Operand (8-bit/16-bit) & AH=Remainder.
MOV BL, 04
IDIV BL
// BL=04
// AL=0203/04=50 (i.e. AL=50 & AH=03)
137
IDIV operand
Signed Division.
Operand may be register or memory.
Operand contents are negatively signed.
Operand may be general purpose register or
memory location.
AL=AX/Operand (8-bit/16-bit) & AH=Remainder.
MOV BL, 04
DIV BL
AH=03)
// AX=-0203
// BL=04
// AL=-0203/04=-50 (i.e. AL=-50 &
138
139
140
141
142
143
OR
Used in setting certain bits
144
XOR
Used in Inverting bits
xxxx xxxx XOR 0000 1111 = xxxxxxxx
-Example:
Clear bits 0 and 1, set bits 6 and 7, invert
bit 5 of register CL:
AND CL, FCH ;
OR CL, C0H ;
XOR CL, 20H ;
145
1111 1100B
1100 0000B
0010 0000B
SHL Instruction
The SHL (shift left) instruction performs a logical left shift
0
CF
mov dl,5d
shl dl,1
146
SHR Instruction
The SHR (shift right) instruction performs a logical right shift
MOV DL,80d
SHR DL,1
SHR DL,2
147
; DL = 40
; DL = 10
SAR Instruction
SAR (shift arithmetic right) performs a right
CF
; DL = -40
; DL = -10
For example, 80 / 23 = 10
149
mov dl,5
Before:
00000101
=5
shl dl,1
After:
00001010
= 10
ROL Instruction
ROL (rotate) shifts each bit to the left
The highest bit is copied into both the Carry flag
CF
150
MOV Al,11110000b
ROL Al,1
; AL = 11100001b
MOV Dl,3Fh
ROL Dl,4
; DL = F3h
ROR Instruction
ROR (rotate right) shifts each bit to the right
The lowest bit is copied into both the Carry flag and
CF
151
MOV AL,11110000b
ROR AL,1
; AL = 01111000b
MOV DL,3Fh
ROR DL,4
; DL = F3h
RCL Instruction
RCL (rotate carry left) shifts each bit to the left
Copies the Carry flag to the least significant bit
Copies the most significant bit to the Carry flag
CF
CLC
MOV BL,88H
RCL BL,1
RCL BL,1
152
;
;
;
;
CF = 0
CF,BL = 0 10001000b
CF,BL = 1 00010000b
CF,BL = 0 00100001b
RCR Instruction
RCR (rotate carry right) shifts each bit to the right
Copies the Carry flag to the most significant bit
Copies the least significant bit to the Carry flag
CF
STC
MOV AH,10H
RCR AH,1
153
; CF = 1
; CF,AH = 00010000 1
; CF,AH = 10001000 0
of instruction.
unconditional.
154
CALL Des:
This instruction is used to call a subroutine or function or
procedure.
RET:
It returns the control from procedure to calling program.
Every CALL instruction should have a RET.
155
Call subroutine A
Next instruction
156
Return
JMP Des:
This instruction is used for unconditional jump from one place to
another.
157
158
Meaning
JA
Jump if Above
JAE
JB
Jump if Below
JBE
JC
Jump if Carry
JE
Jump if Equal
JNC
JNE
JNZ
JPE
JPO
JZ
Jump if Zero
Loop Des:
This is a looping instruction.
The number of times looping is required is placed in the CX
register.
159
String Instructions
String in assembly language is just a sequentially stored bytes or
words.
considerably reduced.
160
SCAS String:
It scans a string.
It compares the String with byte in AL or with word in
AX.
161
SI and DI store the offset values for source and destination index.
162
REP (Repeat):
This is an instruction prefix.
It causes the repetition of the instruction until CX becomes zero.
E.g.: REP MOVSB STR1, STR2
It copies byte by byte contents.
REP repeats the operation MOVSB until CX becomes zero.
163
attached.
164
STC
It sets the carry flag to 1.
CLC
It clears the carry flag to 0.
CMC
It complements the carry flag.
165
STD:
It sets the direction flag to 1.
If it is set, string bytes are accessed from higher memory address to
CLD:
It clears the direction flag to 0.
If it is reset, the string bytes are accessed from lower memory
166
The HLT instruction will cause the 8086 to stop fetching and
executing instructions.
NOP instruction
LOCK instruction
WAIT instruction
this instruction takes 8086 to an idle condition. The CPU
will not do any processing during this.
167
INSTRUCTION SET-summary
1.DATA TRANSFER INSTRUCTIONS
Mnemonic
Meaning
Format
Operation
Move
Mov D,S
(S) (D)
Exchange
XCHG D,S
(S)
LEA Reg16,EA
EA
PUSH BX
POP
POP BX
IN
IN AX,0028
OUT
OUT 0028,BX
MOV
XCHG
LEA
PUSH
(D)
(Reg16)
168
2. ARITHMETIC INSTRUCTIONS
Mnemonic
SUB
Meaning
Subtract
Format
SUB D,S
Operation
(D) - (S)
Borrow
(D)
(CF)
(D)
SBB
Subtract with
borrow
SBB D,S
DEC
Decrement by one
DEC D
NEG
Negate
NEG D
DAS
DAS
AAS
AAS
ADD
Addition
ADD D,S
(S)+(D)
ADC
ADC D,S
(S)+(D)+(CF)
INC
Increment by one
INC D
(D)+1 (D)
AAA
AAA
DAA
DAA
(D) - 1
(D)
(D)
(D)
carry (CF)
carry (CF)
is incremented by 1
Adjust AL for decimal Packed BCD
169
Meaning
Format
Operation
AND
Logical AND
AND D,S
OR
Logical Inclusive OR
OR D,S
(S)+(D) (D)
XOR
Logical Exclusive OR
XOR D,S
(S) + (D)(D)
NOT
LOGICAL NOT
NOT D
(D) (D)
170
Meaning
Format
SAL/SHL D, Count
SHR
SHR D, Count
SAR
Shift arithmetic
right
SAR D, Count
Mnemonic
Meaning
Format
ROL
ROR
Rotate Left
ROL D,Count
Rotate Right
ROR D,Count
RCL
RCL D,Count
RCR
RCR D,Count
171
4. Branching or PROGRAM
EXECUTION TRANSFER INSTRUCTIONS
CALL - call a subroutine
RET - returns the control from procedure to calling
program
172
5. STRING INSTRUCTIONS
CMPS Des, Src - compares the string bytes
SCAS String - scans a string
MOVS / MOVSB / MOVSW - moving of byte or
word
REP (Repeat) - repetition of the instruction
173
Assembler
Directives
175
Directives Expansion
176
177
180
Directives examples
181
Assembly Language
Programming(ALP)
8086
182
183
184
185
191
Detailed coding
16 BIT ADDITION
192
Detailed coding
16 BIT SUBTRACTION
193
16 BIT MULTIPLICATION
194
16 BIT DIVISION
195
SUM of N numbers
L1:
MOV AX,0000
MOV SI,1100
MOV DI,1200
MOV CX,0005
MOV DX,0000
ADD AX,[SI]
INC SI
INC DX
CMP CX,DX
JNZ L1
MOV [1200],AX
HLT
196
Average of N numbers
L1:
MOV AX,0000
MOV SI,1100
MOV DI,1200
MOV CX,0005
MOV DX,0000
ADD AX,[SI]
INC SI
INC DX
CMP CX,DX
JNZ L1
DIV CX
MOV [1200],AX
HLT
AX=AX/5(AVERAGE OF 5 NUMBERS)
197
Presented by C.GOKUL,AP/EEE , Velalar College of Engg & Tech,
Erode
FACTORIAL of N
L1:
ASCENDING ORDER
199
200
DECENDING ORDER
JNB L1 into JB L1
in the LINE 10
201
202
LARGEST NUMBER
203
SMALLEST NUMBER
204
Modular
Programming
205
CHARACTERISTICS of module:
1. Each module is independent of other modules.
2. Each module has one input and one output.
3. A module is small in size.
4. Programming a single function per module is a goal
Advantages of Modular Programming:
It is easy to write, test and debug a module.
Code can be reused.
The programmer can divide tasks.
Re-usable Modules can be re-used within a program
DRAWBACKS:
Modular programming requires extra time and memory
207
MODULAR PROGRAMMING:
1.LINKING & RELOCATION
2.STACKS
3.Procedures
4.Interrupts & Interrupt Routines
5.Macros
208
LINKING &
RELOCATION
209
LINKER
A linker is a program used to join together several
object files into one large object file.
The linker produces a link file which contains the
binary codes for all the combined modules.
The linker program is invoked using the following
options.
C> LINK
or
C>LINK MS.OBJ
210
211
212
Loader
->Loader is a utility program which takes object code as
input prepares it for execution and loads the
executable code into the memory .
->Loader is actually responsible for initializing the
process of execution.
Functions of loaders:
213
Procedures
216
217
m1 PROC
MOV BX, 5
RET ;
return to caller.
m1 ENDP
END
The above example calls procedure m1, does MOV BX, 5 &
returns to the next instruction after CALL: MOV AX, 2.
Presented by C.GOKUL,AP/EEE , Velalar College of Engg & Tech, Erode
218
; AX = AL * BL.
; return to caller.
value of AL register is update every time the
procedure is called.
final result in AX register is 16 (or 10h) 219
220
MACROS
224
MACRO
PUSH AX
PUSH BX
PUSH CX
ENDM
RETREIVE
MACRO
POP CX
POP BX
POP AX
ENDM
226
227
; macro named
COPY with
2 parameters{x, y}
PUSH AX
MOV AX, x
MOV y, AX
POP AX
ENDM
228
INTERRUPTS
&
INTERRUPT SERVICE
ROUTINE(ISR)
229
230
231
232
233
235
236
237
238
239
1. TYPE 0 TO TYPE 4 INTERRUPTSThese Are Used For Fixed Operations And Hence Are Called
Dedicated Interrupts
{AX/0=}
PRIORITY OF INTERRUPTS
Interrupt Type
SINGLE STEP
Priority
Highest
Lowest
242
Byte &
String
Manipulation
243
Move,
compare,
store,
load,
scan
244
Byte Manipulation
Example 1:
MOV AX,[1000]
MOV BX,[1002]
AND AX,BX
MOV [2000],AX
HLT
Example 2:
MOV AX,[1000]
MOV BX,[1002]
OR AX,BX
MOV [2000],AX
HLT
Example 3:
MOV AX,[1000]
MOV BX,[1002]
XOR AX,BX
MOV [2000],AX
HLT
Example 4:
MOV AX,[1000]
NOT AX
MOV [2000],AX
HLT
245
STRING MANIPULATION
1. Copying a string (MOV SB)
L1
MOV CX,0003
MOV SI,1000
MOV DI,2000
CLD
MOV SB
DEC CX
JNZ L1
HLT
decrement CX
246
247
DEPARTMENTS: CSE,IT,ECE,ECE,MECH
Regulation : 2013
UNIT-2
8086 SYSTEM
BUS STRUCTURE
248
249
GND 1
40
0V=0,
AD14
reference
AD13
for all
AD12
voltages
AD11
AD10
AD9
AD8
AD7
INTEL
Time-multiplexed
8086
Address / Data Bus AD6
AD5
(bidirectional)
AD4
AD3
AD2
Hardware
interrupt requests AD1
AD0
(inputs)
NMI
INTR
2...5MHz,
1/3 duty cycle CLK
GND 20
21
(input)
Minmode operation
signals (MN/MX=1)
Timemultiplexed
Address Bus
/Status signals
(outputs)
Vcc
AD15 5V10%
A16/S3
Maxmode operation
A17/S4
signals (MN/MX=0)
A18/S5
A19/S6
___
BHE/S7
Control Operation Mode,
___ (HIGH)
MN/MX
Bus
___
(input):
RD
(in,out)
___ ____
1 = minmode
HOLD (RQ/GT0)
___ ____
(8088 generates all
HLDA
(RQ/GT1)
___
______
the needed control
WR__
(LOCK)
__
signals for a small
IO/M
(S2)
__
__
Status
system),
DT/R
(S1)
____
__
signals
DEN
(S0)
(outputs)
0 = maxmode
ALE
(QS0)
_____
(8288 Bus
INTA
(QS1)
_____
Controller expands
TEST
Interrupt
the status signals to
READY
acknowledge
generate more
250
RESET
(output)
control signals)
251
252
SYSTEM BUS
TIMING
253
T-State
T1
T2
T3
T4
254
255
256
Bus Timing
During T 1 :
The address is placed on the Address/Data bus.
Control signals M/ IO , ALE and DT/ R specify memory or I/O, latch the address
onto the address bus and set the direction of data transfer on data bus.
During T 2 :
8086 issues the RD or WR signal, DEN , and, for a write, the data.
DEN enables the memory or I/O device to receive the data for writes and the 8086 to
receive the data for reads.
During T 3 :
This cycle is provided to allow memory to access data.
READY is sampled at the end of T 2 .
If low, T 3 becomes a wait state.
Otherwise, the data bus is sampled at the end of T 3 .
During T 4 :
All bus signals are deactivated, in preparation for next bus cycle.
Data is sampled for reads, writes occur for writes.
257
Setup time The time before the rising edge of the clock, while the data
must be valid and constant
Hold time The time after the rising edge of the clock during which the data
must remain valid and constant
258
WAIT State
Basic
configurations
260
Maximum mode(MN/MX=GND)
Pin #33 (MN/MX) connect to Ground
Some control signals are generated externally by the 8288
bus controller chip
Max mode is used when math processor is used.
261
262
263
264
265
266
MAXIMUM MODE
267
268
269
270
MULTIPROCESSOR
CONFIGURATIONS
271
Coprocessor 8087
Multiprocessor
configuration
272
Multiprocessor configuration
Multiprocessor Systems refer to the use of multiple
processors that executes instructions simultaneously
and communicate with each other using mail boxes and
Semaphores.
Maximum mode of 8086 is designed to implement 3
basic multiprocessor configurations:
1. Coprocessor (8087)
2. Closely coupled (8089)
3. Loosely coupled (Multibus)
273
274
8087
instructions
are inserted
in the 8086
program
275
276
278
Closely Coupled
processor may take
control of the bus
independently.
Two 8086s cannot
be closely coupled.
279
281
Advantages of Multiprocessor
Configuration
1. High system throughput can be achieved by having more than
one CPU.
2. The system can be expanded in modular form.
INTRODUCTION
TO ADVANCED
PROCESSORS
284
Data bus
width
16
80286
16
24
16M
80386 DX
32
32
4G
80486
32
32
4G
Pentium 4 &
core 2
64
40
1T
285
80186
286
80286
287
80386
288
289
Documents References
8086 SYSTEM BUS STRUCTURE by Prof.L.PETER STANLEY BEBINGTON
( PROFESSOR AND DEAN(ACADEMIC),VCET,Erode)
I/O Interfacing by Prof.P.JAYACHANDAR , ASSOCIATE PROFESSOR and
DEAN(SA),VCET,Erode
8086 Microprocessor by Dr. M. Gopikrishna ,Assistant Professor of
Physics,Maharajas College ,Ernakulam
8086 architecture By Er. Swapnil Kaware
8086 presentations by Gursharan Singh Tatla (Eazynotes.com)
Microprocessor - Ramesh Gaonkar
8086 micro processor prasadpawaskar
8086 class notes-Y.N.M by MURTHY Y.N
Introduction to 8086 Microprocessor by Rajvir Singh
8086 micro processor by Poojith Chowdhary
8086 ASSEMBLY LANGUAGE PROGRAMMING Cutajar & Cutajar
Intel microprocessor history by Ramzi_Alqrainy
290
Website References
http://80864beginner.com/
www.eazynotes.com
www.slideshare.net
www.scribd.com
www.docstoc.com
www.slideworld.com
www.nptel.ac.in
http://opencourses.emu.edu.tr/
http://engineeringppt.blogspot.in/
http://www.pptsearchengine.net/
www.4shared.com
http://8085projects.info/
291
UNIT-3
UNITI/O
INTERFACING
Presented by
C.GOKUL,AP/EEE
293
Data Transfers
294
295
MEMORY DEVICES
I/O DEVICES
296
IO is treated as memory.
16-bit addressing.
More Decoder Hardware.
Can address 216=64k
locations.
Less memory is available.
IO Mapped IO
IO is treated IO.
8- bit addressing.
Less Decoder
Hardware.
Can address 28=256
locations.
Whole memory address
space is available.
297
298
Memory Mapped IO
IO Mapped IO
Special Instructions are
used like IN, OUT.
Special control signals
are used.
Arithmetic and logic
operations can not be
performed on data.
Data transfer b/w
accumulator and IO.
299
Parallel communication
interface
INTEL 8255
300
8255 PPI
301
Signals of 8085
302
8255 PIO/PPI
303
304
305
306
Control Logic
CS
A1
A0
Selected
0
0
0
0
0
0
1
1
0
1
0
1
Port A
Port B
Port C
Control
Register
8255 is not
selected
307
308
309
310
311
312
313
314
I/O Mode
1. BSR Mode
315
B3
B2
B1
0
0
0
0
1
1
1
1
0
0
1
1
0
0
1
1
0
1
0
1
0
1
0
1
Bit/pin of port C
selected
PC0
PC1
PC2
PC3
PC4
PC5
PC6
PC7
316
2. I/O MODE
Features
317
318
Features
319
320
Solution:
1
Program:
MVI A,AEH ; LOAD CONTROL WORD
OUT 23H
= AEH
321
322
Solution:
1
= 80H
323
Solution:
1
= 9BH
324
Parallel Transfer
TRANSMITTER
Receiver
325
Serial communication
interface
INTEL 8251 USART
326
UNIVERSAL SYNCHRONOUS
ASYNCHRONOUS RECEIVER
TRANSMITTER (USART)
(USART)
327
328
BLOCK DIAGRAM
329
Five Sections
330
Input Signals
CS Chip Select
C/D Control/Data
331
332
WR Write
RD Read
RESET - Reset
CLK - Clock
333
CS C/D RD WR
0
Function
MPU writes instruction in the
control register
MPU reads status from the status
register
MPU outputs the data to the Data
Buffer
MPU accepts data from the Data
Buffer
USART is not Selected
334
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
Buffer Register
Output Register
335
336
Receiver Section
Input Register
Buffer Register
337
338
339
Control words
340
341
342
343
344
345
346
11347
Programming 8251
8251 mode register
Number of
Stop bits
00: invalid
01: 1 bit
10: 1.5 bits
11: 2 bits
Parity enable
0: disable
1: enable
Parity
0: odd
1: even
Character length
00: 5 bits
01: 6 bits
10: 7 bits
11: 8 bits
Mode register
Baud Rate
00: Syn. Mode
01: x1 clock
10: x16 clock
11: x64 clock
11348
IR
RTS
ER
SBRK RxE
DTR
TxE
command register
11349
SYNDET
FE
OE
TxRDY:
RxRDY:
TxEMPTY:
PE:
OE:
FE:
SYNDET:
DSR:
PE
TxEMPTY
RxRDY
TxRDY
transmit ready
receiver ready
transmitter empty
parity error
overrun error
framing error
sync. character detected
data set ready
status
register
350
351
352
353
354
355
356
357
358
359
Features:
i. DAC0800 is a monolithic 8-bit DAC manufactured by
National semiconductor.
ii. It has settling time around 100ms
iii. It can operate on a range of power supply voltage i.e.
from 4.5V to +18V. Usually the supply V+ is 5V or +12V.
The V- pin can be kept at a minimum of -12V.
iv. Resolution of the DAC is 39.06mV
360
361
362
TIMER/COUNTER
363
364
365
366
8254 Programming
11-367
8254 Modes
Gate is low the
count will be
paused
Gate is high
Will continue
counting
Gate is
High output
will be high
368
369
370
371
Keyboard/Display
Controller
INTEL 8279
372
373
374
375
Keyboard section
Display section
Scan section
CPU interface section
376
377
378
379
380
381
382
383
384
385
D6
D5
D4
D3
D2
D1
D0
386
SENSOR MATRIX
SENSOR MATRIX
387
B) Programmable clock :
D6
D5
D4
D3
D2
D1
D0
c) Read
below.
D6
D5
D4
D3
D2
D1
D0
AI
389
d) Read
Display RAM :
D6
D5
D4
D3
D2
D1
D0
AI
390
d) Write
Display RAM :
D6
D5
D4
D3
D2
D1
D0
AI
D6
D5
D4
D3
D2
D1
D0
IW
IW
BL
BL
391
g) Clear
Display RAM :
D7
D6
D5
D4
D3
D2
D1
D0
CD2
CD1
CD0
CF
CA
CD2
CD1
CD0
392
h) End
D6
D5
D4
D3
D2
D1
D0
E- Error mode
X- dont care
393
INTERRUPT
CONTROLLER
394
395
396
397
398
399
8237DMA CONTROLLER
400
Introduction:
Direct Memory Access (DMA) is a method of allowing data
0: DRAM refresh
1: Free
2: Floppy disk controller
3: Free
402
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
403
404
1.
2.
3.
4.
5.
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.
406
1.
2.
3.
It contains ,
Control logic
Mode set register and
Status Register.
CONTROL LOGIC:
408
Programming and
applications Case
studies
409
1. TRAFFIC
LIGHT
CONTROL
410
411
LAN Direction
412
8086 LINES
MODULES
413
8086 ALP:
414
Lookup Table
1200
1201
1205
1209
120D
1211
415
80H
21H,09H,10H,00H (SOUTH WAY)
0CH,09H,80H,00H (EAST WAY)
64H,08H,00H,04H (NOURTH WAY)
24H,03H,02H,00H (WEST WAY)
END
2. LED DISPLAY
416
417
418
419
3. LCD DISPLAY
421
422
423
PORTS
Control port
PORT A
PORT B
PORT C
ADDRESS
FF26
FF20
FF22
FF24
ADDRESS
FF36
FF30
FF32
FF34
425
PORTS
Control port
PORT A
PORT B
PORT C
426
ADDRESS
4003
4000
4001
4002
427
428
429
430
431
432
433
MVI A, 00H
OUT 81H
MVI A, 34H
OUT 81H
MVI A, 0BH
SIM
EI
HERE:
JMP HERE
Interrupt service routine
MVI A, 40H
OUT 81H
IN 80H
MVI H, 62H
MOV L, A
MVI A, 80H
OUT 81H
MOV A, M
OUT 80H
EI
RET
434
5. ALARM
CONTROLLER
Relevant
Material
Not exact
435
436
GPIO- I J1 Connecter
PORTS
ADDRESS
Control port
FF26
PORT A
FF20
PORT B
FF22
PORT C
FF24
GPIO- II J1 Connecter
PORTS
ADDRESS
Control port
FF36
PORT A
FF30
PORT B
FF32
PORT C
FF34
Documents References
Website References
http://80864beginner.com/
www.eazynotes.com
www.slideshare.net
www.scribd.com
www.docstoc.com
www.slideworld.com
www.nptel.ac.in
http://opencourses.emu.edu.tr/
http://engineeringppt.blogspot.in/
http://www.pptsearchengine.net/
www.4shared.com
http://8085projects.info/
439
441
Microcontrollers
Introduction
Presented by
C.GOKUL,AP/EEE
442
443
A smaller computer
On-chip RAM, ROM, I/O ports...
Example: Motorolas 6811, Intels 8051, Zilogs
Z8 and PIC
444
Microcontroller
Microprocessor
Expansive
Not Expansive
General-purpose
Single-purpose
445
Home
Office
Auto
446
447
8051 Microcontroller
Intel introduced 8051, developed in the year 1981.
The 8051 is an 8-bit processor
449
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
450
8051 Features
64KB Program Memory address space
64KB Data Memory address space
4K bytes of on-chip Program Memory
128 bytes of on-chip Data RAM
32 bidirectional and individually addressable I/0 lines
Two 16-bit timer/counters
6-source/5-vector interrupt structure with two priority
levels
On-chip clock oscillator
451
452
453
454
455
456
RST
RESET pin is an input and is active high (normally low)
Upon applying a high pulse to this pin, the microcontroller will
reset and terminate all activities
457
EA
EA, external access, is an input pin and
must be connected to Vcc or GND
Normally EA pin is connected to Vcc
EA pin must be connected to GND to
indicate that the code or data is stored
externally.
458
460
Port 0
Port 0 is also designated as AD0-AD7.
When connecting an 8051 to an external
memory, port 0 provides both address
and data.
The 8051 multiplexes address and data
through port 0 to save pins.
ALE indicates if P0 has address or data.
When ALE=0, it provides data D0-D7
When ALE=1, it has address A0-A7
461
Port 3
Port 3 can be used as input or output.
Port 3 has the additional function of
providing some extremely important
signals
463
TYPE
Vss
Ground: 0 V reference.
Vcc
P0.0 - P0.7
I/O
P1.0 - P1.7
I/O
P2.0 - P2.7
I/O
P3.0 - P3.7
I/O
TYPE
RST
Reset: A high on this pin for two machine cycles while the
oscillator is running, resets the device.
ALE
Address Latch Enable: Output pulse for latching the low byte
of the address during an access to external memory.
PSEN*
EA*/VPP
465
4K
ROM
Timer 0
128 B
RAM
Timer 1
CPU
OSC
Bus
Control
Serial
Port
4 I/O Ports
P0
P1
P2
P3
TXD RXD
466
467
8051
Memory Space
468
64K
External
External
60K
64K
SFR
EXT
INT
EA = 0
EA = 1
Program Memory
4K
128
Data Memory
469
470
Special
Function
Register [SFR]
471
MOV 0F0H,#25H
MOV B,#25H
MOV 0E0H,R2
MOV A,R2
MOV 0F0H,R0
MOV B,R0
SFR Addresses ( 1 of 2 )
474
SFR Addresses ( 2 of 2 )
475
Example
476
C AC F0 RS1 RS0 OV F1 P
Carry
Parity
Auxiliary Carry
User Flag 0
User Flag 1
Register Bank Select
Overflow
477
478
General Purpose
Area
BIT Addressable
Area
128 BYTE
INTERNAL RAM
Reg Bank 3
479
480
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
481
482
483
8051 Stack
The stack is a section of RAM used by the CPU to store
information temporarily.
This information could be data or an address
484
8051 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
485
INSTRUCTION
SET OF
8051
486
487
1. Arithmetic Instructions
ADD
8-bit addition between the accumulator (A) and a
second operand.
The result is always in the accumulator.
The CY flag is set/reset appropriately.
ADDC
8-bit addition between the accumulator, a second
operand and the previous value of the CY flag.
488
ADD Instruction
ADD A, source
MOV A, #03H
MOV B,#02H
ADD A,B
489
SUBB
A A - <operand> - CY.
The result is always saved in the
accumulator.
The CY flag is set/reset appropriately.
490
SUBB Instruction
SUBB A, source
MOV A, #03H
MOV B,#02H
SUBB A,B
491
INC
DEC
MUL AB / DIV AB
Multiplication of Numbers
MUL AB
MOV A,#05
MOV B,#03
MUL AB
Operand 1
Operand 2
Result
byte byte
A=low byte,
B=high byte
493
Division of Numbers
MOV A
A,#05
,#05 ;load 05H to reg. A
MOV B,#03
B,#03 ;load 03H in reg. B
DIV AB
;05/03 =>Quotient = 01
01,Reminder
,Reminder = 02
where B = 02 and A = 01
Table 6-2:Unsigned Division Summary (DIV AB)
Division
Numerator
Denominator
Quotient
Remainder
byte / byte
494
495
2. Logical
instructions
496
ANL D,S
-Performs logical AND of destination & source
-Destination : A/memory;
-Source : data/register/memory
- Eg: ANL A,#0FH ANL A,R5
ORL D,S
XRL D,S
-Performs logical XOR of destination & source
-Destination : A/memory;
-Source : data/register/memory
- Eg: XRL A,#28H
XRL A,@R0
CPL A
-Compliment accumulator
-gives 1s compliment of accumulator data
SWAP A
-Exchange the upper & lower nibbles of accumulator
498
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
499
3. Data Transfer
Instructions
500
MOV Instruction
MOV destination, source ; copy source to destination.
MOV A,#55H ;load value 55H into reg. A
MOV R0,A
;copy contents of A into R0
;(now A=R0=55H)
MOV R1,A
;copy contents of A into R1
;(now A=R0=R1=55H)
MOV R2,A
;copy contents of A into R2
;(now A=R0=R1=R2=55H)
MOV R3,#95H ;load value 95H into R3
;(now R3=95H)
MOV A,R3
;copy contents of R3 into A
;now A=R3=95H
501
MOVX
Data transfer between the accumulator and
a byte from external data memory.
MOVX
MOVX
MOVX
MOVX
A, @Ri
A, @DPTR
@Ri, A
@DPTR, A
502
PUSH / POP
Push and Pop a data byte onto the stack.
The data byte is identified by a direct
address from the internal RAM locations.
PUSH
POP
DPL
40H
503
XCH
Exchange accumulator and a byte variable
XCH
XCH
XCH
A, Rn
A, direct
A, @Ri
504
4.Boolean variable
instructions
505
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
506
ANL C,<Source-bit>
-Performs AND bit addressed with the carry bit.
- Eg: ANL C,P2.7 AND carry flag with bit 7 of P2
ORL C,<Source-bit>
507
XORL C,<Source-bit>
-Performs XOR bit addressed with the carry bit.
MOV P2.3,C
MOV C,P3.3
MOV P2.0,C
508
5. Branching
instructions
509
Jump Instructions
All conditional jumps are short jumps
Target address within -128 to +127 of PC
Call Instructions
LCALL (long call): 3-byte instruction
2-byte address
Target address within 64K-byte range
512
513
514
8051
Addressing
Modes
515
1.
2.
3.
4.
5.
Immediate
Register
Direct
Register indirect
External Direct
516
517
519
520
521
522
523
5. External Direct
External Memory is accessed.
There are only two commands that use External Direct
addressing mode:
MOVX A, @DPTR
MOVX @DPTR, A
DPTR must first be loaded with the address of external
memory.
524
8051
Assembly
Language
Programming(ALP)
525
LABEL
START
MNEMONICS
CLR C
MOV R0, #00
MOV A,#05
MOV B,#03
ADD A,B
MOV DPTR,#9200
JNC AHEAD
INC R0
AHEAD
MOV X @DPTR,A
INC DPTR
MOV A,R0
MOV X @DPTR,A
HERE
SJMP HERE
526
LABEL
START
MNEMONICS
CLR C
MOV R0, #00
MOV A,#05
MOV B,#03
SUBB A,B
MOV DPTR,#9200
JNC AHEAD
INC R0
AHEAD
MOV X @DPTR,A
INC DPTR
MOV A,R0
MOV X @DPTR,A
HERE
SJMP HERE
527
Multiplication Concept
MUL AB
MOV A,#25H
MOV B,#65H
MUL AB
Operand 1
Operand 2
Result
byte byte
A=low byte,
B=high byte
528
Division Concept
DIV AB ; divide A by B
MOV A,#95H
MOV B,#10H
DIV AB
;load 95 into A
;load 10 into B
;now A = 09 (quotient) and B = 05 (remainder)
Numerator
Denominator
Quotient
Remainder
byte / byte
529
MULTIPLICATION OF TWO
8 bit Numbers
Address
9000
Label
START
Mnemonics
MOV A,#05
Address
9000
Label
START
MOV A,#05
MOV F0,#03
MOV F0,#03
MUL AB
DIV AB
MOV DPTR,#9200
MOV DPTR,#9200
MOVX @ DPTR,A
MOVX @ DPTR,A
INC DPTR
INC DPTR
MOV A,F0
MOV A,F0
MOVX @DPTR,A
HERE
Mnemonics
MOVX @DPTR,A
SJMP HERE
HERE
SJMP HERE
530
LOOP:
Clear Acc
532
533
534
535
Looping
536
537
538
539
540
Presented by
C.GOKUL,AP/EEE
8051
TIMERS
541
8051 Timer/Counter
OSC
12
C /T 0
C /T 1
TLx
THx
(8 Bit) (8 Bit)
TFx
(1 Bit)
T PIN
TR
INTERRUPT
Gate
INT PIN
542
TMOD Register
GATE:
When set, timer/counter x is enabled, if INTx pin is high
and TRx is set.
When cleared, timer/counter x is enabled, if TRx bit set.
C/T*:
When set, counter operation (input from Tx input pin).
When cleared, timer operation (input from internal clock).
543
TMOD Register
544
TCON Register
545
8051
Timer
Modes
8051 TIMERS
Timer 0
Timer 1
Mode 0
Mode 0
Mode 1
Mode 1
Mode 2
Mode 2
Mode 3
546
TIMER 0
OSC
12
C /T 0
C /T 1
TL0 TH0
TF0
T 0 PIN
TR0
INTERRUPT
Gate
INT 0 PIN
547
TIMER 0 Mode 0
13 Bit Timer / Counter
OSC
12
C /T 0
C /T 1
T 0 PIN
TL0
(5 Bit)
TH0
(8 Bit)
TF0
INTERRUPT
TR 0
Gate
INT 0 PIN
TIMER 0 Mode 1
16 Bit Timer / Counter
OSC
12
C /T 0
C /T 1
T 0 PIN
TL0
(8 Bit)
TH0
(8 Bit)
TF0
INTERRUPT
TR 0
Gate
INT 0 PIN
TIMER 0 Mode 2
8 Bit Timer / Counter with AUTORELOAD
OSC
12
C /T 0
C /T 1
T 0 PIN
TL0
(8 Bit)
TH0
(8 Bit)
TF0
INTERRUPT
TR 0
Reload
Gate
INT 0 PIN
TH0
(8 Bit)
TIMER 0 Mode 3
Two - 8 Bit Timer / Counter
OSC
12
C /T 0
C /T 1
T 0 PIN
TL0
(8 Bit)
TF0
INTERRUPT
TH0
(8 Bit)
TF1
INTERRUPT
TR 0
Gate
INT 0 PIN
OSC
12
TR1
551
TIMER 1
OSC
12
C /T 0
C /T 1
TL1 TH1
TF1
T 1PIN
TR1
INTERRUPT
Gate
INT 1 PIN
552
TIMER 1 Mode 0
13 Bit Timer / Counter
OSC
12
C /T 0
C /T 1
T 1PIN
TL1
(5 Bit)
TH1
(8 Bit)
TF1
INTERRUPT
TR1
Gate
INT 1 PIN
TIMER 1 Mode 1
16 Bit Timer / Counter
OSC
12
C /T 0
C /T 1
T 1PIN
TL1
(8 Bit)
TH1
(8 Bit)
TF1
INTERRUPT
TR1
Gate
INT 1 PIN
TIMER 1 Mode 2
8 Bit Timer / Counter with AUTORELOAD
OSC
12
C /T 0
C /T 1
T 1PIN
TL1
(8 Bit)
TH1
(8 Bit)
TF1
INTERRUPT
TR1
Reload
Gate
INT 1 PIN
TH1
(8 Bit)
Programming Timers
Example: Indicate which mode and which timer are
selected for each of the following.
(a) MOV TMOD, #01H (b) MOV TMOD, #20H (c) MOV
TMOD, #12H
Solution: We convert the value from hex to binary.
(a) TMOD = 00000001, mode 1 of timer 0 is selected.
(b) TMOD = 00100000, mode 2 of timer 1 is selected.
(c) TMOD = 00010010, mode 2 of timer 0, and mode 1 of timer 1
are selected.
556
Programming Timers
Find the timers clock frequency and its period for
various 8051-based system, with the crystal frequency
11.0592 MHz when C/T bit of TMOD is 0.
Solution:
558
8051
Serial
Port
559
560
The start bit is always one bit, but the stop bit can be
one or two bits
The start bit is always a 0 (low) and the stop bit(s) is 1
(high)
562
563
SBUF Register
SBUF is an 8-bit register used solely for serial communication.
For a byte data to be transferred via the TxD line, it must be
placed in the SBUF register.
The moment a byte is written into SBUF, it is framed with the
start and stop bits and transferred serially via the TxD line.
SBUF holds the byte of data when it is received by 8051 RxD
line.
When the bits are received serially via RxD, the 8051 deframes
it by eliminating the stop and start bits, making a byte out of
the data received, and then placing it in SBUF.
567
SBUF Register
Sample Program:
568
SCON Register
SM0 SM1 SM2 REN TB8 RB8
Set to Enable
Serial Data
reception
Enable Multiprocessor
Communication Mode
TI
RI
569
570
577
8051
Interrupts
578
INTERRUPTS
An interrupt is an external or internal event that
interrupts the microcontroller to inform it that a device
needs its service
A single microcontroller can serve several devices by two
ways:
1. Interrupt
2. Polling
579
Interrupt Vs Polling
1. Interrupts
Whenever any device needs its service, the device notifies the
microcontroller by sending it an interrupt signal.
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) or interrupt handler.
2. Polling
The microcontroller continuously monitors the status of a
given device.
When the conditions met, it performs the service.
After that, it moves on to monitor the next device until every
one is serviced.
580
Interrupt Vs Polling
The polling method is not efficient, since it wastes much of
the microcontrollers time by polling devices that do not
need service.
The advantage of interrupts is that the microcontroller can
serve many devices (not all at the same time).
Each devices can get the attention of the microcontroller
based on the assigned priority.
For the polling method, it is not possible to assign priority
since it checks all devices in a round-robin fashion.
The microcontroller can also ignore (mask) a device request
for service in Interrupt.
581
P3.2 and P3.3 are for the external hardware interrupts INT0
(or EX1), and INT1 (or EX2)
Timer 0 Overflow.
Timer 1 Overflow.
Reception/Transmission of Serial Character.
External Event 0.
External Event 1.
585
EA : Global enable/disable.
--- : Reserved for additional interrupt hardware.
MOV IE,#08h
or
SETB ET1
Interrupt Priority
When the 8051 is powered up, the priorities are assigned according
to the following.
In reality, the priority scheme is nothing but an internal polling
sequence in which the 8051 polls the interrupts in the sequence
listed and responds accordingly.
590
Interrupt Priority
We can alter the sequence of interrupt priority by assigning a
higher priority to any one of the interrupts by programming a
register called IP (interrupt priority).
To give a higher priority to any of the interrupts, we make the
corresponding bit in the IP register high.
591
Reserved
PS
PT1 PX1
PT0
PX0
Serial Port
Timer 1 Pin
INT 1 Pin
INT 0 Pin
Timer 0 Pin
593
KEYBOARD
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
594
4x4 matrix
596
597
598
600
601
Stepper Motor
Interfacing
602
603
604
605
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
606
MOV A, #66H
MOV P1,A
ACALL DELAY
MOV P1,A
SJMP TURN
CW: RR A
ACALL DELAY
MOV P1,A
SJMP TURN
607
Full step
608
LCD Interfacing
609
610
611
PORTS
Control port
PORT A
PORT B
PORT C
612
ADDRESS
4003
4000
4001
4002
613
A/D Interfacing
614
615
617
618
Program:
MOV P1,#11111111B
MAIN: CLR P3.7
SETB P3.6
CLR P3.5
SETB P3.5
WAIT:
JB P3.4,WAIT
CLR P3.7
CLR P3.6
MOV A,P1
CPL A
MOV P0,A
SJMP MAIN
619
D/A Interfacing
620
622
623
SENSOR
INTERFACING
take temperature sensor for example
624
625
626
EXTERNAL
MEMORY
INTERFACING
627
629
Presented by C.GOKUL,AP/EEE , Velalar College of Engg & Tech, Erode
Books References
Mohamed Ali Mazidi, Janice Gillispie Mazidi, Rolin McKinlay,
630
Documents References
8051 microcontroller by Suresh P. Nair[ME, (PhD)] MIEEE Professor&Head Department of Electronics and
Communication Engineering Royal College of Engineering and Technology
8051 Microcontroller by Dr. M. Gopikrishna ,Assistant Professor of Physics,Maharajas College ,Ernakulam
8051 Microcontroller By Er. Swapnil Kaware
8051 MICROCONTROLLER by Prathyusha Institute of Technology & Management in Education
8051 MICROCONTROLLER by Prathyusha Institute of Technology & Management in Education
www.pantechsolutions.net/
Embedded systems, 8051 microcontroller by Amandeep Alag in Education
8051 microcontroller features by Tech_MX in Technology
8051 microcontroller by Gaurav Verma in Engineering
8051 (microcontroller)class1 by Nitin Ahire in Education
8051 microcontroller by Bibek Kattel in Education
8051 microcontroller by Jhemi22 in Education
8051 microcontrollers by Chih-Hsiang Tang in Technology
Embedded systems, 8051 microcontroller by Amandeep Alag
Embedded C programming based on 8051 microcontroller by Gaurav Verma
Microcontroller 8051 features & application
MICROCONTROLLER-8051 Features & Applications Dr. Y .Narasimha Murthy Ph.D., Sri Saibaba National
College
8086 ASSEMBLY LANGUAGE PROGRAMMING Cutajar & Cutajar
Intel microprocessor history by Ramzi_Alqrainy
631
Website References
http://amcmp.blogspot.in/2012/06/8051-micro-controller.html
http://www.mikroe.com/chapters/view/65/chapter-2-8051-microcontroller-architecture/
https://www.pantechsolutions.net/project-kits/user-guide-for-lcd-interface-card
http://www.slideshare.net/pantechsolutions/interfacing-stepper-motor-with-8051
LCD DIsplay
stepper motor
www.vtulearning.com
www.eazynotes.com
www.slideshare.net
www.scribd.com
www.docstoc.com
www.slideworld.com
www.nptel.ac.in
http://opencourses.emu.edu.tr/
http://engineeringppt.blogspot.in/
http://www.pptsearchengine.net/
www.4shared.com
http://8085projects.info/
DAC interface
LED Interface
632
633