Unit-3 8051 Microcontroller Architecture - Technical
Unit-3 8051 Microcontroller Architecture - Technical
6 Architecture
Syllabus
Introduction to MCS-51 Family Micro-controllers, Architectural block
Pin functions, General purpose and diagram, Pindiagram and
special function registers,
circuit, 1/O port circuits, Memory organization, Internal
Oscillator and clock circuit, Reser
program and data memory.
Contents
6.1 Introduction to MCS-51 Family Microcontrollers
6.2 Architecture of 8051 Summer-12,16,17,18,19,
Winter-15,16,18,19, Marks 7
6.3 Pin Configuration of 8051. . .. Summer-15,18,19,
Winter-19, Marks 4
6.4 Oscillator Circuits
6.5 Reset Circuit Summer-15, Winter-16, Marks 3
6.6 O Port Circuits Winter-15, 16, Summer-16, 18,
Marks 7
6.7 Memory Organization Winter-15, 16, 17, 19,
Summer-16, 1 8 , . Marks7
(6-1)
6.1 Introduction to MCS-51 Family Microcontrollers
The 8051 is an 8-bit microcontroller designed by Intel. It was optimized for 8-bit
and single bit Boolean operations. Its family includes 8031, 8051, 8052 and math
microcontrollers. Let us see the features of 8051 microcontroller.
8751
The features of the 8051 family are as follows
1. 4096 bytes on - chip program memory.
Timers/Counters (16-bit) 2 2 3 2
I/O pins 32 32 32 32
Serial Port 1 1
Interrupt sources (Reset not included)) 5 5 5
nNdNAAMNOOAMIU DO000D0099
nOe0000d0+w 00520vv* 09 ***********************
w w w .w
e wwwwwwwwww.*
www*
Review Questions
Several functions
fun to the accumulator: Kotate, parity computation,
Several apply exclusively
testing for zero and so on.
e
L
* *** ***** *
*** ** ***
vowemWwwwwwwwewwwwwwwwwewwNwwwwwwwwww *
FO
Flg. 6.2.1 Block diagram of 8051
Reglster B 16-bit DPTR
The data pointer (DPTR) consists of a high byte (DPH) and a low byte (DPL). Its
two independent 8-bit registers. It serves as a base register in indirect jumps, lookup
table instructions and external data transfer. The DPTR does not have a single internal
address; DPH (83F1) and DPL (82H) have separate internal addresses.
Fig. 6.2.2
89 H 1000 1001
98 H 1001 1011
ABH 1010 1011
+75 H 0111 0101
Borrow DEH 1101 1110
Carry 110 H 10001 0000
ov-Over Flow Flag : This flag is set whenever the result of a signed num
operation is too large, causing the high-order bit to overflow into the sign bit
mber
P-Parity Flag: Parity is defined by the number of ones present in the accumulato
P 0 , if number of ones are even and P = 1, if number of ones are odd.
ator.
Example: The status of CY, AC and P flags after the addition of 9BH and 65H isa
as
follows
wwww *************" w*****************************;
1 1 1 1 1 11 Carry
*********wwwwoi*** ********ss**e****
9B H 1 0 0 1 1 0 1 1
**aa*ao*********DnA****************************
65H01i1o o110 1
1 0 00 0 0 0 0 o
wwwwwwww.wwwwwwww.wwwwwwwwwww***wwwwwwveewwwwww*********vw****
Accumulator
CY 1, AC =1 andP = 0
There are instructions in 8051, that tests the condition of
and make decision based on the status of
flags in the PSW register
flags. Thus, programmer use these flags to
perform somearithmetic operations which involves
carry or borrow,
program control (using conditional branching).
or to change the
As mention earlier,
programmer can select register bank by setting corresponding bits
in PSW
previous versions.
i6.2.3 shows special functiorn bit addresses.
Direct
Bit address Hardware
byte
register
address (MSB) (LSB) symbol
OFFH
OFOH
FFs F F F2FFB
OEOH
E7Es Es E4 E3 E2 E E ACC
88888 8888
ODOH D7 D6 D5 D4 D3 D2 D1 Do PSW
OB8H IP
OBOH B7 B6 B5 B4 B3 B2 B1 BO P3
OA8H AF-AC AB AA A9 IE
OAOH A7 A As A4 A A2 A1 AP2
SCON
98H 9F 9E 9D 9c 98 9A 99 98
P1
90H 97 96 95 94 93 92 91
90
89 88 TCON
8E 8D 8C 88
8A
88H BF
PO
80
87 86 85 84 83 82 81
8800908080
80H
address
Fig. 6.2.3 SFR bit
addresses and their value in binary
SFRs and their
Tab
e 6.2.1 contains a list of all the
at reset.
Symbol Name Address Value in binary
ACC Accumulator 0EOH O000 0000
Port 1 90H* * * * * * * * * * * * * * * * * * * * * * *
1 1 11 1111
is provided in MCS-51.,
separate sign-tlag
Review Questions
2. Quantify the nmumber of register banks in 8051 and say how the CPU knows which bankis
Currently in use.
subtraction?
11. Which flag of 8051 indicates the overflow of signed arithmetic addition /
GTU Winter-16, Marks 2
microcontroller.
12. Draw and explain the functional block diagram of 8051 GTU Summer-17, Marks 7
Port 3
P3.3 (INT1) 13 28 P2.7(As
P3.4 To 14 27 P26(A
P3.5 (T) 15 26 P2.5 (A
P3.6 (WR) 16 25 P24(A12 Port 2
P3.7 RD) 24 P2.3 (A
Oscillator XTAL 2 8 23 P2.2 1A4o)
signals XTAL 1 19 22 P21A
GND 20 21 P2.0(As
Fig. 6.3.1 Pin-out of 8051
The 8051 has 32 I/0 pins configured as four eight-bit parallel ports (PO, P1, P2
and P3). All four ports are bidirectional ie. each pin will be configured as input or
output (or both). All port-pins are multiplexed except the pins of port 1. Each p
consists of a latch, an output driver and an input buffer.
Port 0 (Pins 32 39): Port 0 pins can be used as 1/O pins. The output drives
of
input buffers port 0 are used to access external
memory. Port 0 outputs the low order
byte of the external memory address, time multiplexed with the data being writen of
read. Thus, port 0 can be used as a
multiplexed address/data
bus.
Port 1 (Pins 1 8) : Port 1 pins can be used only as I/O pins.
Port 2 (Pins 21 28): The
output drives of port 2 are used to access external ntemory
Port 2 outputs the high order
byte of the external memory address when the adau
16 bits wide. Otherwise,
port 2 is used as an I/O port.
Port 3 (Pins 10 17): All port pins of port 3 are multifunctional. Therefore The
pin
of port 3 be
can
programmed to use as I/O or as one of the alternate funct
special functions as shown
have
below including two external Symbol Position
Symbol1 Altermate use
interrupts, wo counter inputs, two RD P3.7 External memory read signal
data lines and two
special
timing WR P3.6
control strobes. ***
External memory write signal.
**************** ******** **
RXD
**wwwwwww
P3.0 Serial data input.
iievervrirrrvrvvrnivinnrvnirinrvniii obowbbovsvdiiiiiuier OOirivrrriiiiiP e00rrvot*****
0scillator Pins XTAL2 (Pin 18) and ******
Table 6.3.1
XTAL1 (Pin 19): For generating an
internal clock signal, the external oscillator is connected at these two pins.
ALE (Address Latch Enable, Pin 30): AD to AD lines are multiplexed. To To
demultiplex these lines and for obtaining lower half of an address, an external latch and
ALE signal of 8051 is used.
RST (Reset, Pin 9): This pin is used to reset 8051. For proper reset operation, reset
signal must be held high at least for two machine cycles, while oscillator is running
PSEN (Program Store Enable, Pin 29): It is the active low output control signal used
to activate the enable signal of the external ROM/EPROM. It is activated every six
oscillator periods while reading the external memory. Thus, this signal acts as the read
strobe to external program memory.
EA(External Access, Pin 31): When the EA pin is high (connected to Vcc), program
fetches to addresses 0000H through 0FFFH are directed to the internal ROM and
program fetches to addresses 1000H through FFFFH are directed to external
ROM/EPROM. When EA is low (grounded), all addresses (0000H to FFFFH) fetched by
program are directed to the external ROM/EPROM.
Review Questions
1. Draw the pin diagram of 8051 microcontroller and explain its port structure.
microcontroller.
GTU : Winter-19, Marks 3
Draw only pin diagram of 8051
mat for knqmdadaa
6.4 Oscillator Circuits
The 8051 microcontroller has an on-chip oscillator. However, it requires an exter
lock source as input to generate the clock. Fig. 6.4.1 (a) shows the crystal oscilla
circuit. A quartz crystal in connected to inputs XTAL1 and XTAL2. A pair of 2
lator
capacitor is connected to assure oscillator start-up at the correct frequency.
pF
30 pF
XTAL1 No XTAL1
Connection
External XTAL2
XTAL2 oscillator signal
30 pF Cystal
GND
8051
GND
8051
Review Question
Review Question
Port 0 (Pins 32 39): Port 0 pins can be used as I/O pins. The output drives and
input buffers of port 0 are used to access external memory. Port 0 outputs the low order
the
byte of extermal memory address, time multiplexed with the data being
read. Thus, port 0 can be used as a multiplexed address/data bus.
written or
Addr/data bus
Control
Vcc
Read latch
PO.X
Pin
Internal bus
0.X
Mux
Latch
Write to latch
Control logic
Read pin
page.)
2 used to access external memory.
28): The output drives of port
are
Port 2 (Pins 21
external memory address when the address is
Fort 2 outputs the high order byte of the
6.6.3 on next page.)
l6 bits wide. Otherwise, port 2 is used as an I/0 port. (See Fig.
VcC
Read latch
Internal
pull-up
Internalbus D P1.X
Pin
P1.X
Latch
Write to latch CL
Read pin
D tern.
pull-up
Internalbus
P2.X
Latch
Write to latch CL
MUX
)
Control logic
Read pin
Port 3 (Pins 10 17): All port pins of port 3 are multifunctional. Therefore, each put
of port 3 can be programmed to use as I/O or as one of the alternate function. They
have special functions as shown below including two external interrupts, wo counter
inputs, two special data lines and two timing control strobes. (See Fig. 66.4 on nex
page)
VcC
Alternate
output
Read latch function Dulna/
Internal
pull-up
P3.X
Pin
Internalbus D
P3.X
Latch
Write to latch-
CL
Read pin
Alternate
input
function
Fig. 6.6.4 Port 3 bit
Table 6.6.1
Review Questions
1. Draw and explain the port structure of 8051.
of all the ports
FFFFH
FFFFH
EA0
60 kbytes Access
External External
memory 64 Kbytes
OR External
1000H
OFFFH
4 kbytes EA-1
Internal Access
0000 Internal 0000
memory
Data memory
only addressing9
AND
80H
64kbytes
7FH external
memory
Accessible by
Lower direct & indirect
128
addressin9
0000H
Fig. 6.7.1
6.7.1 Internal RAM Organization
The 8051 has 128-byte internal RAM. It is accessed The
using RAM address register
Fig. 6.7.2 shows the organization of internal RAM. As shown in the Fig. 6.7.2 inte. tenal
Byte
address
Byte
1F address
7F
1E Re
1D 5
1C R
Bank 3
1B R3
1A R2
19 R
18 Ro
17 R7
16 Rg
15 R5
Bank 2
14 R
13 R3
12 R
11 R
10 Ro B7 B Bs B4 B B2 B Bo
OF R7 7F 7E 7C 7B7A 79 78 2
OE Re 77 76 75 74 73 72 71 70 2E
OD R5 6F 6E 6D 6C 6B 6A 69 68 2D
OC RAR4 67 66 65 64 63 62 6160
Bank 1 2C
OB Ro 5F 5E 5D 5C 58 5A 59 58 2B
OA R2 57 56 55 54 53 52 51 50 2A
09 R 4F 4E 4D 4C|4B 4A 49 48
08 Ro 47 46 45 44 4342 41 40 28
07 R 3 3E 3D 3C
3A 39 38 27 3B
06 R 37 36 35 34 33 32 31 30 26
05 Rs 2F 2E 20 20 28 2A 29 28
Bank 00
04 27 26 25 24 23 22 21 20 24
03 Ra 1F 1E 1D 1C 1B 1A 19 18 23
02 R2 17 16 15 14 13 12 11 10 22
ww
OF OE OD OC 0B OA 09 08 21
01
R
00 R 07 06 05 04 03 02 01 00 20
30
Bit addresses Byte General purpose
Register addresses
bank
Fig. 6.7.2 Organization of internal RAM of 8051
67.11 8051 Register Banks (Working Registers)
V. from address 00H to 1FH of internal RAM constitute 32 working
Thefirst 32-bytes
each. The four register
They are organized into four banks of eight registers
ers.
k S are numbered 0 to 3 and are consists of eight registers named Ro to R7.
RAM address.
Each register can be addressed by name or by its
at a time. Bits RS0 and RS1 in the PSw
W deh
determine
Only register bank is in use
one
Bank 0
Bank 1
************* ************************************ 00
Bank 2
Bank 3
wwwve wrwwww.iv wwwwwewwwww.wwwww
wwww.wwwww.e
The 8051 has 4 kbyte of internal ROM with address space from 0000H to OFFFH. It B
programmed by manufacturer when the chip is built. This part cannot be erased o
altered after fabrication. This is used to store final version of the program. It is acce sed
using program address register.
Review Questions
10 Explain register banks of 8051. How banks can be GTU: Summer-16, Marks 7
selected ?
11. Explain internal RAM structure of 8051 GTU: Winter-16, Marks 3
microcontroller in brief.
12. Discuss the RAM memory space allocation in 8051.
GTU: Winter-17, Marks 4
13 Draw and explain memory GTU Summer-18, Marks 4
organization of 8051 microcontroller.
GTU: Winter-19, Marks 4
6.8 Short Questions and Answers
Q.1 What is mean by microcontroller ?
Ans. A device which contains the
microprocessor with integrated peripherals like
memory, serial ports, parallel ports, timer/counter,
interfaces like ADC, DAC is called microcontroller. interrupt controller, data acquisition
Q.2 Name any four additional hardware
features available in
compared to microprocessors. microcontrollers when
Ans. The
microcontroller has built-in ROM, RAM,
timer/counters and a clock circuit. parallel I/0, serial I/O,
Q.3 Write the memory capacity of microcontroller
8051.
Ans. The memory capacity of
microcontroller 8051 is 64 kbytes.
Q4 What are the flags available in 8051 ?
Ans. The flags available in 8051 are: CY
(Carry flag), AC (Auxiliary carry flag8).
OV (over flow flag) and P (Parity flag).
Q.5 What is meant by SFR in 8051 ? Give an example.
Ans.: The
group of registers, implemented to perform special function and are located
mmediately above the 128 bytes of RAM are called special function registers for
|example, all port registers, TCOM, SCON, IE, IP, and so on.
Q.6 Give the memory size of 8051 microcontroller.
ns, The 8051 can access upto 64 kbyte program memory and 64 kbytes of data
memory.
What are the applicatlons of 8051 microcontroller ?7
Microcontrollers are more preferred in embedded products. Some applications of
microcontroller are:
Calculators Accounting systems
ure
Game machines Data acquisition systems
Complex industrial controllers
Mobile systems
Traffic light control systems Military applications
Communication systems
Explain the significance of SFRs In 8051 microcontroller.
Q.8
Ans.: The group of registers, implemented to perform special function and are locate
ated
immediately above the 128 bytes of RAM are called special function registers. They aro
are
responsible for operation of ALU, timer, serial port, parallel ports and interrupt control
Q.9 State the function of R$1 and RS0 blts in the flag register of Intel Ro
microcontroller ?
Ans.: RS1 and RS0 are bank selection bits. They are used to select working register
bank of 8051 as given below:
00 Bank 0 0 1 Bank 1
1 0 Bank 2 11 Bank 3
Q.10 Explain the function of the PSEN pin of 8051.
Ans.: PSEN: PSEN stands for program store enable. In 8051 based
extermal ROM holds the program code, this pin is connected to the O
system in which an
pin of the ROM
Q.11 Explain the function of the EA pin of 8051.
Ans.: EA It stands for external When the EA is connected to
access. pin Vcc, program
fetched addresses 0000H through 0FFFH are directed to the internal ROM and
to
Q.16 What is the maximum frequency of the clock signal that can be counted by
8051 counter?
Ans. : The maximum frequency of the lock signal that can be counted by 8051 counter
is 1/12 x rystal frequency.
Q.17 What are the features of ROM and RAM in 8051 microcontroller?
Ans. The 8051 has 128-byte internal RAM. It is accessed using RAM address register.
The internal RAM of 8051 is organized into three distinct areas:
Register Bank BitBit addressable General purpose.
The 8051 has 4 internal ROM with address space from 0000H to OFFFH. It
kbyte of
cannot be erased or
is programmed by manufacturer when the chip is built. This part
altered after fabrication. This is used to store final version of the program. It is
accessed using program address register.