Documente Academic
Documente Profesional
Documente Cultură
General-purpose microprocessor
CPU
GeneralPurpose
Microprocessor
Data Bus
RAM
ROM
I/O
Port
Address Bus
General-Purpose Microprocessor System
Timer
Serial
COM
Port
Microcontroller :
A smaller computer
On-chip RAM, ROM, I/O ports...
Example Motorolas 6811, Intels 8051, Zilogs Z8 and PIC 16X
CPU
I/O
Port
RAM ROM
Serial
Timer COM
Port
A single chip
Microcontroller
Block Diagram
External interrupts
Interrupt
Control
On-chip
ROM for
program
code
Timer/Counter
On-chip
RAM
Timer 1
Timer 0
CPU
OSC
Bus
Control
4 I/O Ports
P0 P1 P2 P3
Address/Data
Serial
Port
TxD RxD
Counter
Inputs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
8051
(8031)
40
39
38
37
36
35
34
33
32
31
30
29
28
27
26
25
24
23
22
21
Vcc
P0.0(AD0
P
) 0.1(AD1)
P0.2(AD2
P
) 0.3(AD3)
P0.4(AD4)
P0.5(AD5)
P0.6(AD6)
P0.7(AD7)
EA/VPP
ALE/PROG
PSEN
P2.7(A15)
P2.6(A14
)P2.5(A13
P
) 2.4(A12
)P2.3(A11)
P2.2(A10)
P2.1(A9)
P2.0(A8)
+
10 uF
31
30 pF
8.2 K
30 pF
11.0592 MHz
19
18
EA/VPP
X1
X2
9 RST
Registers
A
B
R0
DPTR
DPH
DPL
R1
R2
PC
PC
R3
R4
R5
R6
R7
Some 8-bitt Registers of
the 8051
Addressing Modes
Addressing Modes
1.
2.
3.
4.
5.
1.
2.
For example;
ADD A, Rn (This is general
instruction).
ADD A, R5 (This instruction will
add the contents of register R5
with the accumulator contents).
1.
For example;
MOV A, 25H (This instruction will
read/move the data from internal
RAM address 25H and store it in
the accumulator.
Register Indirect
Addressing Mode
Register Indirect
Addressing Mode
1.
For example;
MOV A,@R0 This instruction
moves the data from the register
whose address is in the R0
register into the accumulator.
Immediate Addressing
Mode
Immediate Addressing
Mode
1.
For example;
1.
For example;
MOVC A, @ A + DPTR ( This
instruction moves the data from
the memory to accumulator;
whose address is computed by
adding the contents of
accumulator and DPTR)
Types Of Instructions
1.
2.
3.
4.
5.
MNEMONIC
BYTES
DESCRIPTION
MOV A,Rn
(A)
(Rn)
MOV A,Rx
(A)
(Rx)
MOV A,@Ri
(A)
(Ri)
MOV A,#X
(A)
Data
MOV Rn,A
(Rn)
(A)
MOV Rn, Rx
(Rn)
(Rx)
MOV Rn, #X
(Rn)
Data
MOV Rx, A
(Rx)
(A)
MOV Rx, Rn
(Rx)
(Rn)
MOV Rx, Ry
(RX)
MOV Rx, @ Ri
(Rx)
MOV Rx, # X
(Rx)
(Ry)
(Ri)
Data
MOV @ Ri, A
(Ri)
(A)
MOV @ Ri, Rx
(Ri)
(Rx)
MOV @ Ri, #X
(Ri)
Data
XCH A, Rn
(A)
(Rn)
XCH A, Rx
(A)
(Rx)
XCH A, @Ri
(A)
(Ri)
Arithmetic Instructions
Arithmetic Instructions
MNEMONICS
BYTE
ADD A, Rn
A = A + Rn
ADD A, Rx
A = A + Rx
AAD A, @ Ri
A = A+ Ri
DESCRIPTION
Arithmetic Instructions
ADD A, # X
A = A + Byte
ADDC A, Rn
A = A + Rn + C
ADDC A , Rx
A = A + Rx + C
Arithmetic Instructions
ADDC A, @ Ri
ADDC A, # X
SUBB A, Rn
A = A + Ri + C
A = A + Byte + C
A = A Rn 1
Arithmetic Instructions
SUBB A, Rx
A = A Rx 1
SUBB A, @ Ri
A = A Ri 1
SUBB A, # X
A = A Byte 1
Arithmetic Instructions
INC A
A=A+1
INC Rn
Rn = Rn + 1
INC Rx
Rx = Rx + 1
PUNJAB EDUSAT SOCIETY
Arithmetic Instructions
INC @ Ri
Ri = Ri + 1
DEC A
A=A1
DEC Rn
Rn = Rn 1
PUNJAB EDUSAT SOCIETY
Arithmetic Instructions
DEC Rx
Rx = Rx 1
DEC @ Ri
Ri = Ri 1
INC DPTR
DPTR = DPTR + 1
PUNJAB EDUSAT SOCIETY
Arithmetic Instructions
MUL AB
B:A = A * B
DIV AB
A = [A/B]
DA A
Decimal adjustment of
accumulator according to BCD
code
PUNJAB EDUSAT SOCIETY
Logical Instructions
Logical Instructions
MNEMONIC
BYTE
ANL A, Rn
(A)
(A) ^ (Rn)
ANL A, Rx
(A)
(A) ^ (Rx)
ANL A,@ Ri
(A)
(A) ^ (Ri)
DESCRIPTION
Logical Instructions
ANL A, # X
ANL Rx, A
(Rx)
ANL Rx,# X
(Rx)
(A) ^ (Rx)
Logical Instructions
ORL A, Rn
(A)
(A) + (Rn)
ORL A, Rx
(A)
(A) + (Rx)
ORL A, @ Ri
(A)
(A) + (Ri)
Logical Instructions
ORL Rx, A
ORL Rx,# X
(Rx)
XORL A, Rn
Logical exclusive
OR operation between the contents
of accumulator and R register.
PUNJAB EDUSAT SOCIETY
Logical Instructions
XORL A, Rx
Logical exclusive OR
operation between the contents of the
accumulator and directly addressed
register Rx.
XORL A,@ Ri
Logical exclusive OR
operation between
the contents of the accumulator and
directly addressed register.
Logical Instructions
XORL A, # X
Logical exclusive OR
operation between the
contents of accumulator and the given
8 bit data.
XORL Rx, A
Logical exclusive OR
operation between the
contents of the accumulator and
directly addressed register Rx.
PUNJAB EDUSAT SOCIETY
Logical Instructions
XORL Rx, # X
Logical exclusive OR
operation between the contents of the
directly addressed register Rx and the
given 8 bit data.
CLR A
(A)
0
CPL A
(A)
(/A)
Logical Instructions
SWAP A
RL A
RLC
(A3-0)
(A7-4)
(An + 1)
(A0)
(An + 1)
(A0)
(C)
(An)
(A7)
(An)
(C)
(A7)
Logical Instructions
RR A
(An)
(An + 1)
(A7)
RRC A
(An)
(A0)
(An + 1)
(A7)
(C)
PUNJAB EDUSAT SOCIETY
(C)
(A0)
Logical Instructions On
Bits
Logical Instructions On
Bits
MNEMONIC
BYTE
CLR C
CLR bit
bit
SETB C
DESCRIPTION
(C=0)
clear directly addressed
(C=1)
Logical Instructions On
Bits
SETB bit
Set directly
addressed bit
CPL C
(1 = 0, 0 = 1)
CPL bit
directly
Complement
addressed bit
Logical Instructions On
Bits
ANL C, bit
Logical AND
operation
between Carry bit
and directly addressed bit.
ANL C,/bit
Logical AND
operation
between Carry bit
and inverted directly addressed bit.
PUNJAB EDUSAT SOCIETY
Logical Instructions On
Bits
ORL C, bit
Logical OR
operation
2 between Carry bit
and directly addressed
bit.
ORL C,/bit
Logical OR
operation
2 between Carry bit
and inverted directly addressed bit.
PUNJAB EDUSAT SOCIETY
Logical Instructions On
Bits
MOV C, bit
addressed 2
Move directly
bit to carry bit.
MOV bit, C
Move Carry bit to
directly 2 addressed bit.
MNEMONIC
ACALL adr11
DESCRIPTION
(PC)
(PC) + 2
(SP)
(SP) + 1
((SP))
(PC7 0)
(SP)
(SP) + 1
((SP))
(PC15-8)
BYTE
2
RET
(PC15-8)
(SP)
(PC7-0)
(SP)
1
PUNJAB EDUSAT SOCIETY
((SP))
(SP) 1
((SP))
(SP) -
RET1
AJMP addr11
(PC15-8)
((SP))
(SP)
(SP) 1
(PC7-0)
((SP))
(SP)
(SP)
(PC)
(PC10-0)
(PC) + 2
page address
LJMP addr16
SJMP rel
(PC)
addr15-0
JC rel
(PC)
(PC) + 2
IF ( C ) = 1
THEN (PC)
(PC) + rel
JNC rel
(PC)
(PC) + 2
IF ( C) = 0
THEN (PC)
(PC) + rel
PUNJAB EDUSAT SOCIETY
JB bit, rel
Jump if addressed
bit is set. Short jump.
Jump if addressed
bit is set and clear it.
JZ rel
(PC)
(A) + (DPTR)
(PC) + 2
IF (A) = 0
THEN (PC) (PC) + rel
JNZ rel
(PC)
(PC) + 2
IF (A) = 0
THEN (PC)
(PC) + rel
62
B register
0F0H
PSW*
0D0H
SP
Stack pointer
81H
DOTR
DPL
Low byte
82H
DPH
High byte
83H
P0*
Port 0
80H
P1*
Port 1
90H
P2*
Port 2
0A0H
P3*
Port 3
0B0H
IP*
0B8H
IE*
0A8H
63
Timer/counter 2 control
0C8H
T2MOD
0C9H
TH0
8CH
TL0
8AH
TH1
8DH
TL1
8BH
TH2
0CDH
TL2
0CCH
RCAP2H
0CBH
RCAP2L
0CAH
SCON*
Serial control
98H
SBUF
99H
64
Example 5-1
Write code to send 55H to ports P1 and P2, using
(a) their names
(b) their addresses.
Solution:
(a) MOV A,#55H
;A=55H
MOV P1,A
;P1=55H
MOV P2,A
;P2=55H
(b)
65