0% found this document useful (0 votes)
40 views

UNIT - 5 MP&I

The 8051 microcontroller, developed by Intel in the 1980s, is based on Harvard architecture and is primarily used in embedded systems. It features an 8-bit data bus, 16-bit address bus, and includes various internal components such as timers, interrupts, and registers. The architecture supports programming in embedded C and is characterized by its efficient design for controlling devices in compact systems.

Uploaded by

rahulcswe
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views

UNIT - 5 MP&I

The 8051 microcontroller, developed by Intel in the 1980s, is based on Harvard architecture and is primarily used in embedded systems. It features an 8-bit data bus, 16-bit address bus, and includes various internal components such as timers, interrupts, and registers. The architecture supports programming in embedded C and is characterized by its efficient design for controlling devices in compact systems.

Uploaded by

rahulcswe
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 23

UNIT – 5 : INTRODUCTION AND ARCHITECTURE OF 8051

MICROCONTROLLER

Introduction:
The 8051 microcontroller was invented in 1980's by Intel. Its foundation is based
on Harvard architecture and this microcontroller was developed principally for
bringing it to be used in Embedded Systems.
At first it was created by using NMOS technology but the use of NMOS
consumed more power to work therefore Intel re-launch the microcontroller 8051
using CMOS technology and new edition came up with edition of letter 'C' in the
title name, therefore the new modified version of microcontroller is called by
name 80C51.
The 8051 microcontroller programming is performed in embedded C
language using Keil software.

Features of 8051 Microcontroller:


The 8051 is an 8-bit microcontroller with 8-bit data bus and 16-bit address bus.
The 16-bit address bus can address a 64K (216) byte code memory space and a
separate 64K byte of data memory space.
The 8051 has 4K on-chip read only code memory and 128 bytes of internal
Random Access Memory (RAM)
Besides internal RAM, the 8051 has various Special Function Registers (SFR)
such as the Accumulator, the B register, and many other control registers.
34 8-bit general purpose registers in total.
The ALU performs one 8-bit operation at a time.
Two 16 bit /Counter timers
3 internal interrupts (one serial), 2 external interrupts.
Four 8-bit I/O ports
Some 8051 chips come with UART for serial communication and ADC for
analog to digital Conversion
Comparison of Microcontroller and Microprocessor:

Parameter Microprocessor Microcontroller

Microprocessors can be Microcontrollers can be


Definition understood as the heart of a understood as the heart of an
computer system. embedded system.

A microprocessor is a A microcontroller is a
processor where the memory controlling device wherein the
What is it?
and I/O component are memory and I/O output
connected externally. component are present internally.

The circuit is complex due to Microcontrollers are present on


Circuit
external connection. chip memory. The circuit is less
complexity
complex.

Memory and The memory and I/O The memory and I/O
I/O components are to be components are available.
components connected externally.

Compact Microprocessors can’t be Microcontrollers can be used


system used in compact system. with a compact system.
compatibility

Microprocessors are not Microcontrollers are efficient.


Efficiency
efficient.

Zero status Microprocessors have a zero Microcontroller doesn’t have a


flag status flag. zero status flag.

Number of Microprocessors have less Microcontrollers have more


registers number of registers. number of registers.

Microprocessors are generally Microcontrollers are generally


Applications used in personal computers. used in washing machines, and
air conditioners.
8051 Microcontroller Architecture:

The basic units present in the 8051 microcontroller architecture are:


CPU (Central Processing Unit): The CPU is the brain of any processing
machine. It is the part that is responsible for managing all the tasks of the
microcontroller. The CPU is an independent unit. Users can not interfere with the
CPU controlling how it should function. It identifies the tasks present in the ROM
and then processes them. In the 8051 microcontroller architecture, the CPU is
responsible for managing registers. Registers are a type of memory in a computer.
They can store and manipulate data.
Interrupts: In the 8051 microcontroller architecture, interrupts stop the
microcontroller’s current task. Interrupts are caused when some other program
has a higher priority request for execution. When an interrupt occurs, the ongoing
task stops, the sub-routine for the interrupt is executed, and then the previous job
resumes.
Types of interrupts in 8051 Microcontroller:
The following are the types of interrupts in the 8051 microcontroller architecture:
Memory: The next part of the 8051 microcontroller architecture is the memory.
For any data manipulation to occur, we require a set of instructions. These
programs need to be saved in memory. This memory where the program resides
in the controller's memory is called code memory or program memory. It acts
as ROM memory for the 8051 microcontroller architecture. In the 8051
microcontroller architecture, the microcontroller has 4KB ROM and 128 bytes of
RAM.

Bus: Fundamentally Bus is a group of wires which function as a communication


canal or means for the transfer of Data. These buses comprise 8, 16, or more
cables. As a result, a bus can bear 8 bits, 16 bits altogether. There are two types
of buses:
1. Address Bus: Microcontroller 8051 consists of a 16-bit address bus. It is
brought into play to address memory positions. It is also utilized to transmit
the address from the Central Processing Unit to Memory.
2. Data Bus: Microcontroller 8051 comprise of 8 bits data bus. It is employed
to cart data.

Oscillators: The microcontroller requires a clock to perform operations. In the


8051 microcontroller architecture, we have an oscillator that functions as a clock
for the CPU.

Input/Output Ports: A microcontroller controls small operations for a system.


It is embedded in the systems. We might sometimes need to connect the
microcontroller to other devices. In the 8051 microcontroller architecture, we
have 4 input/output ports. We connect other input/output peripherals using these
ports.
Timers/Counters: In the 8051 microcontroller architecture, we have two timers.
They are each 16 bits. We have the timers to generate gaps between two events.
The two timers generate two delays(gaps), and the suitable one is chosen.

Data Types: In 8051, there is only one data type of 8 bits, from the MSB (most
significant bit) D7 to the LSB (least significant bit) D0. With an 8-bit data type,
any data type larger than 8-bit must be broken into 8-bit chunks by the
programmer before it is processed.
Registers:
8051 microcontrollers mainly contain two types of registers:
1. General-purpose registers (Byte addressable registers)
2. Special function registers (Bit addressable registers)
8051 microcontrollers basically consist of 256 bytes of RAM (Random Access
Memory), which is divided into two parts, first part contain 128 bytes for general
purpose Register these are byte addressable registers and second part contain 128
bytes for special function registers (SFR) memory these are bit addressable
registers.
The part of memory which is used for general purpose is called as RAM, and the
memory used for Special Function Register (SFR) contains all the peripheral
related registers like Accumulator, ‘B’ register, Timers or Counters, and interrupt
related registers.
General Purpose Registers:
We know that a register is a storage element that can be store bits of information.
8051 microcontroller has 4 registers bank. These are B0, B1, B2, and B3 stand
for Bank0, Bank1, Bank2, Bank3 respectively and each bank contains eight
general purpose registers ranging from ‘R0’ to ‘R7’.
These are 32 general purpose registers address from 00h to 1Fh.
 The address range of Register Bank 0 (00 h to 07 h)
 The address range of Register Bank 1 (08 h to F h)
 The address range of Register Bank 2 (10 h to 17 h)
 The address range of Register Bank 3 (18 h to 1F h)
These Register Banks are selected with the help of PSW (Program Status Word)
Register bits i.e., RS0, RS1.

General Purpose Registers Banks and Registers


Special Function Registers (SFR’s):
In 8051 micro controller there are 21 Special function registers (SFR) and this
includes Register A, Register B, Processor Status Word (PSW), PCON etc. There
are 21 unique locations for these 21 special function registers and each of these
registers is of 1 byte size.
The 21 SFR of 8051 Microcontroller are categorized into seven groups these are:
 Math or CPU Registers: A and B Register
 Status Register: PSW (Program Status Word) Register
 Pointer Registers: DPTR (Data Pointer – DPL, DPH) and SP (Stack
Pointer) Registers
 I/O Port Latches: P0 (Port 0), P1 (Port 1), P2 (Port 2) and P3 (Port 3)
Registers
 Peripheral Control Registers: PCON, SCON, TCON, TMOD, IE and IP
Registers
 Peripheral Data Registers: TL0, TH0, TL1, TH1 and SBUF Registers

Accumulator (A register):
 It is an 8-bit register.
 It holds a data and receives the result of the arithmetic instructions.
 ACC is usually accessed by direct addressing and its physical address
is E0H. Accumulator is both byte and bit addressable. if you want to
access the second bit (i.e bit 1), you may use E1H and for third bit E2H
and so on.

B Register:
 It is 8-bit register.
 It is bit and byte-addressable register.
 You can access 1-bit or all 8-bits by a physical address F0h. Suppose to
access a bit 1, we have to use f1.
 The B register is only used for multiplication and division arithmetic
operations.

PSW (Program Status Word) Register:


The PSW (Program Status Word) Register is also called as Flag Register. It is one
of the important SFRs in 8051 microcontrollers. It is also an 8-bit register. It
consists of Flag Bits or status bits that reflect the current state of the CPU. This
will help the programmer in checking the condition of the result and also make
decisions.
PSW flag register is both bit and byte addressable. The physical address of PSW
starts from D0H. The individual bits are accessed by using bit address D1, D2 …
D7. The two unused bits are user-defined flags. Four of the flags are
called conditional flags, which means that they indicate a condition which results
after an instruction is executed. These four are CY (Carry), AC (auxiliary
carry), P (parity), and OV (overflow).

PSW Register
PSW Register Bits

Timer/Counter Registers:
 The 8051 has two 16-bit Programmable timers / counters (Timer 0 -Timer 1).
 Which can be used either as timer to generate a time delay or as counter to
count events happening outside the microcontroller.
 The Counters and Timers in 8051 microcontrollers contain two special
function registers: TMOD (Timer Mode Register) and TCON (Timer Control
Register).
TMODE Registers:
 TMODE register is an 8-bit register.

 Gate: when Gate control is set. Timer/counter is enable only while the
INTx pin is high and the TRx control pin is set. When it is cleared, the
timer is enabled whenever the TRx control bit is set.
 C/T: The Timer or counter selection. When cleared for timer operation
(input from internal system clock). Set for counter operation (input from
Tx input pin).
 Mode selects bits of TMODE register: The M1 and M0 are mode select
bits, which are used to select the timer operations. There are four modes to
operate the timers.

Mode Selection Bits Of TMODE Register


TCON Registers:
 It is Timer control Register.
 It is an 8-bit register.

SP (Stack Pointer):
 The stack is a portion of a RAM Used by the CPU to store data or memory
address on temporary basis.
 The stack pointer register is used to access the stack is known as SP register.
The stack pointer register is 8-bits wide. It can take a value of 00 to FFH.
The RAM memory location 08H is the first location used for the stack. When
the 8051 microcontroller is initialized, the SP register contains the value
07H.
 If we want to store CPU register data into the stack this is known as PUSH
operation and if we getting the data from stack back into a CPU register this
is known as a POP operation.

DP (Data pointer register):


 The data pointer is a 16-bit register used to hold the 16-bit address of data
memory. This can also be used as two 8-bit register namely DPH and
DPL. Data Pointer can be used as a single 16-bit register (as DPTR) or two
8-bit registers (as DPL and DPH).
 The 8-bit data pointers are used for accessing internal RAM and SFR. The
16-bit data pointer is used for accessing external data memory.
 The contents of data pointer are programmable using instructions. It is used
by the 8051 to access external memory using the address indicated by DPTR.
Port Registers: 8051 microcontrollers have 4 bidirectional I/O ports. Port 0, Port
1, Port 2 and Port 3 (P0, P1, P2 and P3). Which can be work as input or output
port. Each port having 8-bits. Hence, total 32 input/output pins allow the
microcontroller to communicate with outside world means this port allow to be
connected with the peripheral devices.

PC (program Counter): It is a 16-bit register. It is use to hold the address of the


memory location from where the next instruction to be fetched.
when the 8051 initializes PC starts at 0000h and it is automatically is incremented
every time after an instruction is executed. (So, in this way PC maintain the
sequence of program execution).
Due to this the width of the PC decides the max program length in bytes. Since
the PC is 16-bit width 8051 can access program addresses from 0000H to FFFFH,
a total of 6kB of code.
Addressing modes: Addressing modes in the 8051 microcontrollers are a way of
specifying the location of an operand in memory. The addressing mode affects
the number of bytes that the instruction takes up in the memory and the speed at
which it is executed. We choose different addressing modes according to specific
applications. There are six different types of Addressing Modes.
 Immediate Addressing Mode
 Register Addressing Mode
 Register Indirect Addressing Mode
 Implied Addressing Mode
 Direct Addressing Mode
 Indexed Addressing Mode

8051 Pin Description:

Description of the pins:


The 8051 microcontroller pin diagram is comprised of 40 pins, as may be seen above.
Four Ports named P0, P1, P2, and P3 are used to store a total of 32 pins. Where each
port has eight pins.
Pins 1 to 8 (P1.0-P1.7): It is also known as PORT 1. The 8-bit bidirectional input and
output ports with inbuilt pull-up resistors make up PORT 1 Pins. Older 8051
microcontrollers only have an 8-bit I/O port on port 1. This port doesn't serve any
additional purposes, unlike other ports.
Pin 9(RST): It is an active HIGH pin, meaning the microcontroller will be reset if
the RST Pin (Pin 9) is HIGH for at least two machine cycles. So it is the RESET pin
used to reset it to its default values when operating or at the beginning of an application.
Pins 10 to 17 (P3.0-P3.7): It is also known as PORT 3. Interrupts, timer input, control
signals, serial communication signals Receive Data (RXD) and Transmit
Data (TXD), and other operations are served by this port.
 Pin 3.0 (RXD) - This pin is known as the serial input pin and its function is to
receive data during serial communication.
 Pin 3.1 (TXD) - This pin is known as the serial output pin and its function is to
transmit data during serial communication.
 Pin 3.2 (INT0) - This pin is used as an external trigger for interrupt 0.
 Pin 3.3 (INT1) - This pin is used as an external trigger for interrupt 1.
 Pin 3.4 (T0) - This pin is for external input for Timer 0.
 Pin 3.5 (T1) - This pin is for external input for Timer 1.
 Pin 3.6 (WR) - This pin is used for writing data to the external memory.
 Pin 3.7 (RD) - This pin is used for reading data from the external memory.

Pins 18 and 19 (XTAL 2 and XTAL 1): The pins connecting an external oscillator are
18 and 19, or XTAL 2 and XTAL 1, respectively. A Quartz Crystal Oscillator is often
attached here.
Pin 20 (GND): The ground pin on an 8051 microcontroller is pin 20, or GND. It
connects to the power supply's negative terminal (0V), representing 0V.
Pins- 21-28 (P2.0-P2.7) (A8-A15): The PORT 2 Pins on the 8051 Microcontroller are
Pins 21 through 28. The PORT 2 pins function as either inputs or outputs because it is
a bidirectional port. Additionally, PORT 2 pins work as the higher-order address byte
when external memory is interfaced.
Pin 29 (PSEN): Program Store Enable, often known as PSEN, is used to interpret
signals from external program memory.
Pin 30 (ALE): It is also known as Address Latch Enable or ALE and is used to
demultiplex the port 0 address data indication (for external memory interfacing).
Pin 31 (EA): This is EA pin which stands for External Access input. It is used to
enable/disable the external memory interfacing.
Pins 32 to 39 (P0.7 - P0.0): Pins 32 to 39 are known as Port 0 (P0.7 - P0.0), and they
are multiplexed with low-order data/address bus signals (AD7-AD0) to act as
input/output ports (to provide the use of outer memory interfacing).
Pin 40 (VCC): The circuit receives power supply voltage, or +5 Volts, from this pin, V CC
(Voltage Common Collector).

Reset Circuit of 8051:


RESET is an active High input When RESET is set to High, 8051 goes back to the
power on state. The 8051 is reset by holding the RST high for at least two machine
cycles and then returning it low.
There are two methods of reset circuit:
1.Power on Reset.
 Initially charging of capacitor makes RST High
 When capacitor charges fully it blocks DC.
2.Manual Reset
 closing the switch momentarily will make RST High.

After a reset, the program counter is loaded with 0000H but the content of on-chip
RAM is not affected.
Clock Circuit of 8051:

An 8051 clock circuit is shown above. In general cases, a quartz crystal is used
to make the clock circuit. The connection is shown in figure (a) and note the
connections to XTAL 1 and XTAL 2. In some cases, external clock sources are
used and you can see the various connections above. Clock frequency limits
(maximum and minimum) may change from device to device. Standard practice
is to use 12MHz frequency. If serial communications are involved then its best to
use 11.0592 MHz frequency.

Okay, take a look at the above machine cycle waveform. One complete oscillation
of the clock source is called a pulse. Two pulses forms a state and six states forms
one machine cycle. Also note that, two pulses of ALE are available for 1 machine
cycle.
8051 Memory Organization:
The 8051 microcontroller's memory is divided into Program Memory and Data
Memory. Program Memory (ROM) is used for permanent saving program being
executed, while Data Memory (RAM) is used for temporarily storing and keeping
intermediate results and variables.
Program Memory (ROM):
Program Memory (ROM) is used for permanent saving program (CODE) being
executed. The memory is read only. Depending on the settings made in compiler,
program memory may also use to store a constant variable. The 8051 executes
programs stored in program memory only. code memory type specifier is used to
refer to program memory.
8051 memory organization allows external program memory to be added.
How does the microcontroller handle external memory depends on the pin EA
logical state.

Internal Data Memory:


Up to 256 bytes of internal data memory are available depending on the 8051
derivative. Locations available to the user occupy addressing space from 0 to 7Fh,
i.e., first 128 registers and this part of RAM is divided in several blocks. The first
128 bytes of internal data memory are both directly and indirectly addressable.
The upper 128 bytes of data memory (from 0x80 to 0xFF) can be addressed only
indirectly.
Since internal data memory is used for CALL stack also and there is only 256
bytes splited over few different memory areas fine utilizing of this memory is
crucial for fast and compact code. See types efficiency also.
Memory block in the range of 20h to 2Fh is bit-addressable, which means that
each bit being there has its own address from 0 to 7Fh. Since there are 16 such
registers, this block contains in total of 128 bits with separate addresses (Bit 0 of
byte 20h has the bit address 0, and bit 7 of byte 2Fh has the bit address 7Fh).
Three memory type specifiers can be used to refer to the internal data
memory: data, idata, and bdata.

External Data Memory:


Access to external memory is slower than access to internal data memory. There
may be up to 64K Bytes of external data memory. Several 8051 devices provide
on-chip XRAM space that is accessed with the same instructions as the traditional
external data space. This XRAM space is typically enabled via proper setting of
SFR register and overlaps the external memory space. Setting of that register must
be manually done in code, before any access to external memory or XRAM space
is made.
SFR Memory:
The 8051 provides 128 bytes of memory for Special Function Registers (SFRs).
SFRs are bit, byte, or word-sized registers that are used to control timers,
counters, serial I/O, port I/O, and peripherals.
Machine Cycles and Timing Diagram:
The external basic operations performed by a microcontroller are called machine
cycles. The executive of an instruction involves execution of one or more
machine cycles in a specified order. The 8051 microcontroller takes one to four
machine cycles to execute an instruction. The basic timing of the 8051 machine
cycle is shown in Fig. 5.1.

The entire timing of a machine cycle of 8031/8051 is divided into 6 states and
they are denoted as S1, S2, S3, S4, S5 and S6. The timing of each state is two
clock periods and they are denoted as P1 and P2.A state in a machine cycle is a
basic time interval for discrete operation of the microcontroller such as fetching
an opcode byte, decoding an opcode, executing an opcode, writing a data, etc.
The time taken to execute a machine cycle is 12 clock periods and so the time
taken to execute an instruction is obtained by multiplying the number of machine
cycles of that instruction by 12 clock periods.
Instruction execution time = C × 12 × T
= C × 12 × 1/f
where, C = Number of machine cycles of an instruction.
T = Time period of crystal frequency in seconds.
f = Crystal frequency in Hz
The 8051 microcontroller has four machine cycles. These are:
1. External program memory fetch cycle
2. External data memory read cycle
3. External data memory write cycle
4. Port operation cycle
The timing diagram provides information about the various conditions of the
signal while a machine cycle is executed. The following section describes the
timing diagram of the various machine cycles.
THE END

You might also like