Professional Documents
Culture Documents
4K bytes ROM
128 bytes RAM
Four 8-bit I/O ports
Two 16-bit timers
Serial interface
64K external code memory space
64K external data memory space
Pin Layout
The 8051 is a 40 pin device, but
out of these 40 pins, 32 are used
for I/O.
24 of these are dual purpose, i.e.
they can operate as I/O or a control
line or as part of address or date
bus.
P1.0
P1.1
P1.2
P1.3
P1.4
P1.5
P1.6
P1.7
RST
(RXD)P3.0
(TXD)P3.1
(INT0)P3.2
(INT1)P3.3
(T0)P3.4
(T1)P3.5
(WR)P3.6
(RD)P3.7
XTAL2
XTAL1
GND
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
)P0.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
Reset Operation
Two circuits for system reset. (a) Manual reset (b) Power-on reset.
Register
PC
ACC
B
PSW
SP
DPTR
Reset Value
0000
0000
0000
0000
0007
0000
15
XTAL2
N
C
EXTERNAL
OSCILLATOR
SIGNAL
XTAL1
GND
16
Relationship between oscillator clock cycles, states, and the machine cycle
Example :
Find the machine cycle for
(a) XTAL = 11.0592 MHz
(b) XTAL = 16 MHz.
Solution:
(a) 11.0592 MHz / 12 = 921.6 kHz;
machine cycle = 1 / 921.6 kHz = 1.085 s
(b) 16 MHz / 12 = 1.333 MHz;
machine cycle = 1 / 1.333 MHz = 0.75 s
19
Alternate Pin-functions
A Pin of Port 0
Read latch
Internal
CPU bus
Write to
latch
TB2
P0.X
pin
D
QP1.X
M1
Clk
Q
TB1
Read pin
8051 IC
7/4/15
23
24
Tri-state Buffer
Output
Input
Tri-state control
(active high)
7/4/15
Low
Highimpedance
(open-circuit)
25
7/4/15
26
7/4/15
Port 0
P0.0
DS500 P0.1
P0.2
0
P0.3
8751 P0.4
P0.5
8951 P0.6
P0.7
10
K
27
7/4/15
28
74LS373
PSEN
ALE
P0.0
P0.7
G
D
74LS3
73
OE
O
C
A0
A7
D0
D7
EA
P2.0
P2.7
7/4/15
8051
A8
A15
ROM
29
2. 74373
latches the
address and
74LS3
send
to ROM
1. Send address
to ROM
G
D
73
OE
O
C
A0
A7
Address
D0
D7
EA
P2.0
P2.7
8051
7/4/15
A8
A12
ROM
30
2. 74373
latches the
address and
send to ROM
74LS3
73
D
Address
OE
O
C
A0
A7
D0
D7
EA
7/4/15
8051
A8
A12
ROM
31
ALE Pin
The ALE pin is used for de-multiplexing the
address and data by connecting to the G pin of
the 74LS373 latch.
When ALE=0, P0 provides data D0-D7.
When ALE=1, P0 provides address A0-A7.
The reason is to allow P0 to multiplex address and
data.
7/4/15
32
7/4/15
33
7/4/15
34
7/4/15
P3 Bit
Functio
n
Pin
P3.0
P3.1
P3.2
P3.3
P3.4
P3.5
P3.6
P3.7
RxD
TxD
INT0
INT1
T0
T1
WR
RD
10
11
12
13
14
15
16
17
35
A Pin of Port 1
Read latch
Internal
CPU bus
Write to
latch
TB2
Vcc
Load(L1
)
D
QP1.X
P1.X
pin
M1
Clk
Q
TB1
Read pin
8051 IC
7/4/15
36
Vcc
TB2
1. write a 1 to the
pin
Internal
CPU bus
Write to
latch
D
QP1.X
1
0
Load(L1
)
M1
2. output
pin is Vcc
P1.X
pin
output 1
Clk
Q
TB1
Read pin
8051 IC
7/4/15
37
Vcc
TB2
1. write a 0 to the
pin
Internal
CPU bus
Write to
latch
D
QP1.X
Load(L1
)
2. output
pin is
ground
P1.X
pin
M1
output 0
Clk
Q
TB1
Read pin
8051 IC
7/4/15
38
2. MOV A,P1
Vcc
Load(L1)
D
QP1.X
Write to latch
external
pin=High
P1.X pin
M1
Clk
Q
TB1
Read pin
3. Read pin=1 Read
latch=0 Write to
latch=1
7/4/15
8051 IC
39
Vcc
2. MOV A,P1
TB2
Load(L1)
external pin=Low
MOV P1,#0FFH
Internal CPU
bus
D
QP1.X
Write to latch
P1.X pin
M1
Clk
Q
TB1
Read pin
3. Read pin=1 Read
latch=0 Write to
latch=1
7/4/15
8051 IC
40
Memory Structure
While most microprocessors implement a
shared memory space for data and code
(programs), microcontrollers has limited
memory and the program is usually stored
in ROM.
In the 8051, both code and data may be
internal but they are stored in separate
memories, namely the internal ROM and
RAM. Expandable to a max of 64K using
external memory.
The next page shows the 8031 which has
no internal ROM.
Register Banks
4 Register Banks Bank0, Bank1,
Bank2 and Bank3
Each Bank consists of R0, R1,
R2, R3, R4, R5, R6, R7
Bank 0 is the default upon power
up of the microcontroller
Other banks can be selected by
programming PSW register.
Register Bank 3
Register Bank 2
Register Bank 1) Stack(
Register Bank 0
45
Bit-Addressable RAM
The 8051 contains 210 bitaddressable locations of which 128
are at byte address 20H through
2FH.
This is the powerful feature of
most
microcontroller
because
individual bits can be set, cleared,
ANDed, ORed etc. with a single
instruction instead of having to
AC
F0
RS1
RS0
OV
--
RS1 RS0
Register Bank
Address
00H-07H
08H-0FH
10H-17H
18H-1FH
1
1
0
1
48
7FH
Scratch pad RAM
30H
2FH
Bit-Addressable RAM
20H
1FH
18H
17H
10H
0FH
08H
07H
00H
Register Bank 3
Register Bank 2
Register Bank( Stack)
1
Register Bank 0
49
SFRs
SFR are usually addressed by name
Memory location 0F0H is given a name
called Register B, similarly 80H is called
P0.
Not all memory location has a name
memory location 35H has no name
Function
Internal RAM
address (hex)
PCON
Power control
87
PSW
SCON
98
SBUF
99
SP
Stack pointer
81
TMOD
timer./counter mode 89
TCON
Timer control
88
TL0
8A
TH0
8C
TL1
8B
TH1
8D
74LS373
PSEN
ALE
P0.0
P0.7
G
D
74LS3
73
OE
O
C
A0
A7
D0
D7
EA
P2.0
P2.7
7/4/15
8051
A8
A15
ROM
57
2. 74373
latches the
address and
74LS3
send
to ROM
1. Send address
to ROM
G
D
73
OE
O
C
A0
A7
Address
D0
D7
EA
P2.0
P2.7
8051
7/4/15
A8
A12
ROM
58
2. 74373
latches the
address and
send to ROM
74LS3
73
D
Address
OE
O
C
A0
A7
D0
D7
EA
7/4/15
8051
A8
A12
ROM
59
FIGURE 211
Internal Timers
Original 8051 has 2 timers
16 bits
16 bits
TH0 : TL0
TH1 : TL1
Timer 0
Timer 1
Timer/Counter Logic
7/4/15
64
7/4/15
65
Timer 1 registers
TL1 ( timer 1 low byte )
TH1 ( timer 1 high byte )
7/4/15
66
7/4/15
67
7/4/15
68
Operation of Timer on
Mode-0
7/4/15
69
Operation of Timer in
Mode 1
7/4/15
70
Operation of Timer in
Mode 2
7/4/15
71
Operation of Timer in
Mode 3
7/4/15
72