The document discusses the architecture of the 8051 microcontroller. It describes the 8051's central processing unit, memory organization, input/output ports, timers/counters, serial port, and interrupts. The 8051 has a CPU, RAM, ROM, and I/O ports integrated into a single chip. It can be programmed to perform control and sensing tasks in embedded systems.
An overview of microcontrollers, specifically the 8051 architecture, including special function registers, I/O pins, and instruction set.
Microcontrollers are single-chip computers integrating CPU, memory, and I/O for specific tasks, distinguished from microprocessors. Discusses advantages and features of microcontrollers.
Focus on the 8051 microcontroller features, including memory specs, ports, and its comparison with the 8031.Details on 8051 architecture, including CPU components like registers and memory addressing capabilities.
Overview of CPU functions, key registers (Accumulator, B Register, Stack Pointer, etc.) and how they operate within the microcontroller.
Details about 8051's I/O ports, timers/counters, and the serial port functionalities, including intended uses.
Explanation of the oscillator function and memory organization in 8051, highlighting various memory types.
Introduction to Special Function Registers (SFRs) and their importance in 8051 architecture.
Detailed explanation of the pin configuration for the 8051 microcontroller, including their respective functionalities.
Functionality and operational use of the various I/O ports (P0, P1, P2, P3) in the 8051 microcontroller.
Discussion of different addressing modes (Immediate, Register, Direct, etc.) and their significance in microcontroller programming.
An overview of the instruction set categories in 8051, including data transfer, arithmetic, and logical instructions.
Details on Boolean variable manipulation instructions and programming examples for subtraction, multiplication, and division.
UNIT IV MICROCONTROLLER
•Architecture of 8051 – Special Function
Registers(SFRs) - I/O Pins Ports and Circuits -
Instruction set - Addressing modes - Assembly
language programming.
5/25/2021
Kongunadu College of Engineering and
Technology(Autonomous)
1
• Microcontrollers asthe name suggests, are small
controllers. They are like single chip computers
that often embedded into other systems to
function as processing / controlling unit.
• Microcontrollers are single - chip
Microcomputers.
• A microcontroller has a CPU (a microprocessor) in
addition to a fixed amount of RAM, ROM and I/O
parts and a timer on a single chip.
• The fixed amount of on - chip RAM, ROM, timer
and I/O parts in microcontrollers makes them
ideal for many applications in which cost and
space are less.
5/25/2021
Kongunadu College of Engineering and
Technology(Autonomous)
3
4.
• The wordmicroprocessor means a CPU only.
• The functional blocks like memory and other
peripherals are to be connected externally to
a microprocessor chip to make a complete
microcomputer.
• But the microcontrollers are having all these
facilities in a single chip.
• The examples for microcontrollers are Intel
MCS - 51 (8051), Atmel 89 C XX, Motorola
68HC X 11XX, PIC family by microchip (PIC
16C64X).
5/25/2021
Kongunadu College of Engineering and
Technology(Autonomous)
4
5.
Differences between microprocessors
andmicrocontrollers
• Microprocessors are intended to be general -
purpose digital computers whereas
microcontrollers are intended to be special -
purpose digital controllers.
• Microprocessors contain a CPU, memory
addressing circuits and interrupt handling
circuits. Microcontrollers have these features
as well as timers, parallel and serial I/O and
internal RAM and ROM.
5/25/2021
Kongunadu College of Engineering and
Technology(Autonomous)
5
6.
Features of microcontrollers
•High integration of functionality : Microcontrollers are
called as single chip computers because they have on -
chip memory and I/O circuitry and other circuitries that
enable them to function as small stand - alone
computers without other supporting circuitry.
• Field programmability, flexibility : Microcontrollers
often use EPROM or E2PROM as their storage device to
allow field programmability so they are flexible to use.
Once the program is tested to be correct then large
quantities of microcontrollers can be programmed to
be used in embedded systems.
• Easy to use.
5/25/2021
Kongunadu College of Engineering and
Technology(Autonomous)
6
7.
Advantages of microcontrollers
•The overall system cost is low, as the peripherals
are integrated in a single chip.
• The product is of small size as compared to the
microprocessor based system and is very handy.
• The system is more reliable.
• The system is easy to troubleshoot and maintain.
• If required additional RAM, ROM and I/O ports
may be interfaced.
5/25/2021
Kongunadu College of Engineering and
Technology(Autonomous)
7
8.
Intel 8051 microcontroller
•The 8 bit microcontroller 8051 family has
numbers ranging from 8031 to 8751 and are
available in N-channel Metal Oxide
Semiconductor (NMOS) and Complementary
MOS [CMOS] construction in a variety of package
types.
• The intel corporation introduced an 8 bit
microcontroller 8051 in 1981.
• This microcontroller had 128 bytes of RAM, 4k
bytes of on - chip ROM, two timers, one serial
port and 4 eight bit ports all on a single chip.
5/25/2021
Kongunadu College of Engineering and
Technology(Autonomous)
8
9.
Comparison between 8051and 8031
5/25/2021
Kongunadu College of Engineering and
Technology(Autonomous)
9
10.
ARCHITECTURE OF 8051
Thefeatures of the 8051 are :
• 8 bit CPU with registers A (the accumulator) and B
• 16 bit Program Counter (PC) and Data Pointer (DPTR)
• 8 bit Program Status Word (PSW)
• 64K Program memory address space
• 64K Data memory address space
• 128 bytes of on chip data memory
• 32 I/O pins for four 8 bit ports : Port 0, Port 1, Port 2,
Port 3
• Two 16 bit timers / counters : T0 and T1
• Full duplex UART : SBUF
• Two external and three internal interrupt sources
• On chip clock oscillator.
5/25/2021
Kongunadu College of Engineering and
Technology(Autonomous)
10
• The intel8051 contains two separate buses for
both program and data. So, it has two distinctive
memory spaces of 64K x 8 size for both program
and data.
• It is based on an 8 bit central processing unit with
an 8 bit accumulator and another 8 bit B register
as main processing blocks.
• Other portions of the architecture include few 8
bit and 16 bit registers and 8 bit memory
locations.
• It has some amount of data RAM built in the
device for internal processing.
• 8051 is supported with on-chip peripheral
functions like I/O ports, Timers / Counters, serial
communication port.
5/25/2021
Kongunadu College of Engineering and
Technology(Autonomous)
12
13.
Central processing unit
•The CPU is the brain of the microcontrollers reading user’s
programs and executing the expected task as per
instructions stored there in.
• It’s primary elements are an Accumulator (ACC), B register
(B), Stack pointer (SP), Program counter (PC), Program
status word (PSW), Data pointer register (DPTR) and few
more 8 bit registers.
Accumulator
• The accumulator performs arithmetic and logic functions
on 8 bit input variables. Arithmetic operations include
basic addition, subtraction, multiplication and division.
Logical operations are AND, OR XOR as well as rotate,
clear, complement.
• accumulator is responsible for conditional branching
decisions and provides a temporary place in a data
transfer operations within the device.
5/25/2021
Kongunadu College of Engineering and
Technology(Autonomous)
13
14.
B Register
• Bregister is used in multiply and divide
operations. During execution B register either
keeps one of the two inputs and then retains a
portion of the result. For other instructions it is
used as general purpose register.
Stack Pointer
• Stack Pointer (SP) is an 8 bit register. This pointer
keeps track of memory space where the
important register information are stored when
the program flow gets into executing a
subroutine.
• The SP is automatically incremented or
decremented for all PUSH or POP instructions
and for all subroutine calls and returns.
5/25/2021
Kongunadu College of Engineering and
Technology(Autonomous)
14
15.
Program Counter
• TheProgram Counter (PC) is the 16 bit register
giving address of next instruction to be
executed during program execution and it
always points to the program memory space.
Data Pointer Register
• The Data Pointer Register (DPTR) is the 16 bit
addressing register that can be used to fetch
any 8 bit data from the data memory space.
When it is not being used for this purpose, it
can be used as two eight bit registers, DPH and
DPL.
5/25/2021
Kongunadu College of Engineering and
Technology(Autonomous)
15
16.
Program Status Word
•The Program Status Word (PSW) keeps the
current status of the arithmetic and logic
operations in different bits. The 8051 has four
math flags that respond automatically to the
outcomes of arithmetic and logic operations and
3 general purpose user flags that can be set 1 or
cleared to 0 by the programmer as desired.
5/25/2021
Kongunadu College of Engineering and
Technology(Autonomous)
16
Input / OutputPorts
• 8051 has 32 I/O pins configured as 4 eight bit parallel ports
(P0, P1, P2 and P3).
• Each pin can be used as an input or as an output under the
software control. These I/O pins can be accessed directly by
memory instructions during program execution to get
require flexibility.
• These port lines can be operated in different modes and all
the pins can be made to do many different tasks apart from
their regular I/O function executions.
• Any instruction that accesses external program memory
will output the higher order byte (A8 - A15) on Port 2
during read cycle.
• Port 1 and Port 3 are available for standard I/O functions.
• Port 3 pins has the additional functions : 2 external
interrupt lines, 2 counter inputs, 2 serial port data lines and
2 timing control storbe lines.
5/25/2021
Kongunadu College of Engineering and
Technology(Autonomous)
18
19.
Timers / Counters
•8051 has two 16 bit Timers / Counters, T0 and
T1 capable of working in different modes.
Each consists of a ‘HIGH’ byte and a ‘LOW’
byte which can be accessed under software.
• There is a mode control register (TMOD) and a
control register (TCON) to configure these
timers / counters in number of ways.
• These timers are used to measure time
intervals, determine pulse widths or initiate
events with one microsecond resolution upto
a maximum 65ms. Use software to get longer
delays.
5/25/2021
Kongunadu College of Engineering and
Technology(Autonomous)
19
20.
Serial Port
• The8051 has a high speed full duplex serial port which is
software configurable in 4 basic modes :
• Shift register mode
• Standard UART mode
• Multiprocessor mode
• 9 bit UART mode.
• Full duplex means the data can go both ways at the same time.
Interrupts
• The 8051 has five interrupt sources : One from the serial port
(RI / TI) when a transmission or reception operation is
executed.
• two from the timers (TF0, TF1) when overflow occurs and two
come from the two input pins INT0, INT1. Each interrupt may
be independently enabled or disabled to allow polling on same
sources and each may be classified as high or low priority.
• These operations are selected by Interrupt Enable (IE) and
Interrupt Priority (IP) registers.
5/25/2021
Kongunadu College of Engineering and
Technology(Autonomous)
20
21.
Oscillator and Clock
•The 8051 generates the clock pulses by which all
internal operations are synchronized.
• Pins XTAL 1 and XTAL 2 are provided for
connecting a resonant network to form an
oscillator. A quartz crystal is used for oscillator.
• The crystal frequency is the basic internal clock
frequency of the microcontroller
5/25/2021
Kongunadu College of Engineering and
Technology(Autonomous)
21
22.
MEMORY ORGANIZATION
• The8051 architecture provide both on chip
memory expansion capabilities. It supports
several distinctive ‘physical’ address spaces,
functionally separated at the hardware level by
different addressing mechanisms, read and write
controls signals or both :
• On chip Program Memory
• On chip Data Memory
• Off chip Program Memory
• Off chip Data Memory
• On chip Special Function Registers
5/25/2021
Kongunadu College of Engineering and
Technology(Autonomous)
22
23.
• The ProgramMemory area (EPROM incase of
external memory or Flash / EPROM incase of
internal one) is extremely large and never lose
information when the power is removed.
• On chip data memory is smaller and therefore
quicker than Program Memory and it goes into a
random state when power is removed. On chip
RAM is used for variables which are calculated
when the program is executed.
• Different addressing mechanisms are used to
access these different memory spaces and this
greatly contributes to microcomputer’s operating
efficiency.
5/25/2021
Kongunadu College of Engineering and
Technology(Autonomous)
23
24.
Total internal DataMemory is divided into three blocks :
Lower 128 bytes
Higher 128 bytes.
Special Function Register Space.
Higher 128 bytes are available only in 8032 / 8052 devices.
5/25/2021
Kongunadu College of Engineering and
Technology(Autonomous)
24
• The remaining8 pins are VCC, GND, XTAL1, XTAL2, RST,
EA , PSEN and ALE / PROG and ALE / . The functions
of these pins are described as follows :
1. Vcc
• Pin 40 of 8051 provides supply voltage to the chip
from the +5V voltage source.
2. GND
• Pin 20 is the ground for the chip,
3. RST
• Pin 9 is the RESET pin. This is referred as a power-on
reset. When activating (high pulse) this pin the
microcontroller will reset and all values in the
registers to be lost. Table 4.4 gives the reset values of
some registers.
5/25/2021
Kongunadu College of Engineering and
Technology(Autonomous)
30
31.
4.EA (External Access)
•This input pin is connected to either Vcc or GND. The 8051
family members has ON – CHIP ROM to store programs. EA
pin (31) is connected to Vcc in 8051 Here, EA pin is
connected to GND to indicate that the code is stored
externally.
5. PSEN (Program Store Enable)
• This is an output pin and pin number is 29. In an 8051 -
based system in which an external ROM holds the program
code, this pin is connected to the OE pin of the ROM.
6. ALE (Addres Latch Enable)
This is an output pin (30) and is active high. When
connecting an 8051 to external memory, port 0 provides
both address and data. In other words, 8051 multiplexes
address and data through port 0 to save pins. If ALE = 0,
port 0 provides data (D0 - D7). If ALE=1, it has address (A0-
A7).
5/25/2021
Kongunadu College of Engineering and
Technology(Autonomous)
31
32.
7. XTAL 1and XTAL 2
• The 8051 has an on - chip oscillator and it requires
an external clock to return it. The quartz crystal
oscillator (12 MHz / 20 MHz) is connected to XTAL 1
(pin 19) and XTAL 2 (pin 18) with two 30pF capacitors
as shown in Fig.
5/25/2021
Kongunadu College of Engineering and
Technology(Autonomous)
32
33.
I/O PORTS
Port 0(P0.0 - 0.7)
• Port 0 is used for both address and data bus (AD0 – AD7).
When the microcontroller chip is connected to an external
memory, Port 0 provides both address and data. ALE pin
indicates if Port 0 has address or data.
• When ALE = 0, Port 0 provides data (D0 – D7)
• = 1, Port 0 provides address (A0 – A7)
• ALE is used for demultiplexing address and data with the
help of a latch.
Port 1 (P1.0 - P1.7)
• Port 1 pins are used as input or output. To make port 1 as
an input port, write 1 to all its 8 bits. To make port 1 as
output port, write 0 to all its 8 bits. Thus port 1 pins have
no dual functions.
5/25/2021
Kongunadu College of Engineering and
Technology(Autonomous)
33
34.
Port 2 (P2.0- P2.7)
• Port 2 pins are used as input / output pins similar in operation to port 1.
The alternate use of port 2 is to supply a high order address byte (A8 –
A15) when the microcontroller is connected to external memory.
Port 3 (P3.0 - P3.7)
• Port 3 pins are used as input or output. Port 3 has the additional
functions
5/25/2021
Kongunadu College of Engineering and
Technology(Autonomous)
34
35.
ADDRESSING MODES
• Theaddressing modes are the ways of accessing data in
register or in memory or be provided as an immediate
value. The 8051 mnemonics are written with the
destination address named first, followed by the source
address.
The following addressing modes are used to access data :
• Immediate addressing mode
• Register addressing mode
• Direct addressing mode
• Register indirect addressing mode
• Indexed addressing mode.
5/25/2021
Kongunadu College of Engineering and
Technology(Autonomous)
35
36.
Immediate Addressing Mode
•When a source operand is a constant rather than a
variable, then the constant can be embedded into the
instruction itself.
• This kind of instructions take two bytes and first one
specifies the opcode and second byte gives the required
constant.
• The operand comes immediately after the opcode. The
mnemonic for immediate data is the pound sign (#).
• This addressing mode can be used to load information into
any of the registers including DPTR register.
5/25/2021
Kongunadu College of Engineering and
Technology(Autonomous)
36
37.
Register Addressing Mode
•Register addressing accesses the eight working
registers (R0 - R7) of the selected register bank. The
least significant three bits of the instruction opcode
indicate which register is to be used for the operation.
• One of the four banks of registers is to be predefined in
the PSW before using register addressing instruction.
ACC, B and DPTR can also be addressed in this mode.
5/25/2021
Kongunadu College of Engineering and
Technology(Autonomous)
37
38.
Direct Addressing Mode
•In the direct addressing mode, all 128 bytes of
internal RAM and the SFRs may be addressed directly
using the single - byte address assigned to each RAM
location and each SFR.
• Internal RAM uses address from 00H to 7FH to
address each byte. The SFR addresses exist from 80H
to FFH.
5/25/2021
Kongunadu College of Engineering and
Technology(Autonomous)
38
39.
• Register IndirectAddressing Mode
• In this mode a register is used as a pointer to the data. If
the data is inside the CPU, only registers R0 and R1 are used
for this purpose. When R0 and R1 hold the addresses of
RAM locations, they must be preceded by the “@” sign.
Indexed Addressing Mode
Only the program memory can be accessed by this mode. This mode is intended
for reading lookup tables in the program memory. A 16 bit base register (DPTR or
PC) points to the base of the lookup tables and accumulator carries the constant
indicating table entry number. The address of the exact location of the table is
formed by adding the accumulator data to the base pointer.
5/25/2021
Kongunadu College of Engineering and
Technology(Autonomous)
39
40.
INSTRUCTION SET
• Aninstruction is a command given to the computer to
perform a specified operation on given data. The
instruction set is the collection of instructions that the
microcontroller is designed to execute.
• These instructions have been classified into the following
groups.
Data transfer group
Arithmetic group
Logical group
Boolean variable manipulation
Program branching
5/25/2021
Kongunadu College of Engineering and
Technology(Autonomous)
40
Note :
• Rn= Any of the eight registers, R0 to R7, in the
selected bank.
• Ri = Either of the pointing registers R0 to R1 in the
selected bank.
• addr = Address of the internal RAM from 00H to
FFH.
• L = Least significant nibble.
• ^ = External memory location.
• ( ) = Contents of the location inside the
parentheses.
5/25/2021
Kongunadu College of Engineering and
Technology(Autonomous)
43