Nothing Special   »   [go: up one dir, main page]

Unit-4 MMC 8051

Download as pdf or txt
Download as pdf or txt
You are on page 1of 10

UNIT-4

ARCHITECTURE OF 8051
The Intel MCS-51 (commonly referred to as 8051) is a Harvard architecture, single chip microcontroller (μC)
series which was developed by Intel in 1980 for use in embedded systems. The 8051 architecture provides many
functions (CPU, RAM, ROM, I/O, interrupt logic, timer,etc.) in a single package
Features of 8051:
8-bit ALU, Accumulator, 8-bit Registers and 8-bit data bus; hence it is an 8-bit microcontroller
16-bit program counter
8-bit Processor Status Word(PSW)
8-bit Stack Pointer
Internal RAM of128bytes
On chip ROM is4KB
Special Function Registers (SFRs) of 128bytes
32 I/O pins arranged as four 8-bit ports (P0 -P3)
Two 16-bit timer/counters : T0 andT1
Two external and three internal vectored interrupts
Full duplex UART (serialport)

Types of Registers in 8051 Microcontroller

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

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.

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 etc. There are 21 unique locations for these 21 special function
registers and each of these register 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.
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 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).
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.
TCON Registers:

 It is Timer control Register.


 It is an 8-bit register.

PCON (Power Control)


The PCON or Power Control register, as the name suggests is used to control the 8051 Microcontroller’s Power
Modes and is located at 87H of the SFR Memory Space. Using two bits in the PCON Register, the
microcontroller can be set to Idle Mode or Power down Mode.

SCON (Serial Control)


The Serial Control or SCON SFR is used to control the 8051 Microcontroller’s Serial Port. It is located as an
address of 98H. Using SCON, we can control the Operation Modes of the Serial Port, Baud Rate of the Serial
Port and Send or Receive Data using Serial Port.
IE (Interrupt Enable)
The IE or Interrupt Enable Register is used to enable or disable individual interrupts. If a bit is SET, the
corresponding interrupt is enabled and if the bit is cleared, the interrupt is disabled. The Bit7 of the IE register
i.e. EA bit is used to enable or disable all the interrupts.

Symbol Description Additional Info

EA Global Interrupt Enable If set to 1, individual interrupts can be enabled. If


Bit. set to 0, all interrupts are disabled.

— —

ET2 Reserved

ES Serial Port Interrupt If set to 1, Serial Port interrupt is enabled.


Enable Bit If set to 0, Serial Port interrupt is disabled.

ET1 Timer 1 Overflow If set to 1, Timer 1 Overflow interrupt is enabled. If


Interrupt Enable Bit set to 0, Timer 1 Overflow interrupt is disabled.

EX1 Ext. Interrupt 1 Enable If set to 1, Ext. Interrupt 1 is enabled. If


Bit set to 0, Ext. Interrupt 1 is disabled.

ET0 Timer 0 If set to 1, Timer 0 Overflow interrupt is enabled. If


Overflow set to 0, Timer 0 Overflow interrupt is disabled.
Interrupt Enable
Bit

EX0 Ext. Interrupt 0 Enable If set to 1, Ext. Interrupt 0 is enabled. If set


Bit to 0, Ext. Interrupt 0 is disabled.

IP (Interrupt Priority)
The IP or Interrupt Priority Register is used to set the priority of the interrupt as High or Low. If a bit is
CLEARED, the corresponding interrupt is assigned low priority and if the bit is SET, the interrupt is assigned
high priority.
PT2 - Reserved, PS- Priority of Serial Port Interrupt, PT1- Priority of Timer 1 Overflow Interrupt,
PX1- Priority of Ext. Interrupt 1, PT0- Priority of Timer 0 Overflow Interrupt
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.
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.
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.

8051 MICROCONTROLLER INTERRUPTS


8051 Microcontroller suffers five different types of interrupts that hampers the main program execution. These
five types of interrupts are:
 Timer 0 overflow interrupt- TF0
 Timer 1 overflow interrupt-TF1
 External hardware interrupt- INT0
 External hardware interrupt- INT1
 Serial communication interrupt- RI/TI
External Interrupt 0 (INT0)
 It is connected to the 8051’s pin PORT3.2.
 An interrupt request is issued when this pin transitions from low to high in response to an external
signal.
 It is possible to program the microcontroller to carry out a particular Interrupt Service Routine (ISR) in
response to this interrupt.

External Interrupt 1 (INT1)

 It is connected to the 8051’s pin PORT3.3


 When that particular pin encounters a low-to-high transitions, INT1, like INT0, creates an interrupt
request.
 A specific ISR can be executed by the microcontroller in response to INT1.
Timer Interrupts (Timer0 and Timer1)
Timer 0 and Timer 1 are hardware timers with internal timer interrupts featured in the 8051 microcontrollers. In
microcontroller applications, these timers are used to measure time intervals and generate precise delays. The
interrupt system of the microcontroller enables it to react quickly to outside events. Interrupts for Timer 0 and
Timer 1 are produced when their respective timers exceed their limit. The microcontroller will run the interrupt
service routine (ISR) for that timer if the related interrupt is enabled, and the associated interrupt flag is set upon
overflow.
Timer0 Interrupt
 Since Timer 0 is an 8-bit timer, its count range is 0 to 255.
 There are two modes of operation for it, 13-bit and 16-bit. It employs the TH0 (Timer 0 High) and TL0
(Timer 0 Low) registers in 13-bit mode and only the TH0 register in 16-bit mode.
 The microcontroller can perform a particular interrupt service routine (ISR) in response to the interrupt
request that this overflow generates.
Timer1 Interrupt
 Timer 1 is a 16-bit timer with a counting range of 0 to 65,535.
 It can operate in 16- or 8-bit mode. It employs the TL1 (Timer 1 Low) and TH1 (Timer 1 High) registers
in 8-bit mode and only the TH1 register in 16-bit mode.
 Timer 1 can be set up to produce an interrupt when it overflows, just like Timer 0. This interruption may
cause a certain ISR to be executed.
Serial Communication Interrupts (UART)
UART (Universal Asynchronous Receiver/Transmitter) is a serial communication protocol used with 8051
microcontrollers. Data is sent over a single cable, bit by bit, in serial transmission. In this sense, “interrupts”
refers to the processes that enable the microcontroller to react quickly to external events. Depending on the
operation you wish to interrupt for, enable the UART’s transmit interrupt (TI) or receive interrupt (RI).

PIN DIAGRAM OF 8051


The pin diagram of 8051 microcontroller looks as follows −
 Pins 1 to 8 − These pins are known as Port 1. This port doesn’t serve any other functions. It is internally
pulled up, bi-directional I/O port.
 Pin 9 − It is a RESET pin, which is used to reset the microcontroller to its initial values.
 Pins 10 to 17 − These pins are known as Port 3. This port serves some functions like interrupts, timer
input, control signals, serial communication signals RxD and TxD, etc.
 Pins 18 & 19 − These pins are used for interfacing an external crystal to get the system clock.
 Pin 20 − This pin provides the power supply to the circuit.
 Pins 21 to 28 − These pins are known as Port 2. It serves as I/O port. Higher order address bus signals
are also multiplexed using this port.
 Pin 29 − This is PSEN pin which stands for Program Store Enable. It is used to read a signal from the
external program memory.
 Pin 30 − This is EA pin which stands for External Access input. It is used to enable/disable the external
memory interfacing.
 Pin 31 − This is ALE pin which stands for Address Latch Enable. It is used to demultiplex the address-
data signal of port.
 Pins 32 to 39 − These pins are known as Port 0. It serves as I/O port. Lower order address and data bus
signals are multiplexed using this port.
 Pin 40 − This pin is used to provide power supply to the circuit.
Addressing Modes of 8051
The various techniques to specify the operands, is known as addressing modes. In 8051
there are four types of addressing modes.
 Immediate AddressingMode
 Register AddressingMode
 Direct AddressingMode
 Register IndirectAddressing Mode
Immediate addressing mode
In this Immediate Addressing Mode, the data is provided in the instruction itself. The data is
provided immediately after the opcode. These are some examples of Immediate Addressing
Mode.
MOVA, #0AFH;
MOVR3, #45H;
MOVDPTR, #FE00H;
In these instructions, the # symbol is used for immediate data.
Register addressing mode
In the register addressing mode the source or destination data should be present in a
register (R0 to R7). These are some examples of RegisterAddressing Mode.
MOV A, R5;
MOV R0, A;
Direct Addressing Mode
In the Direct Addressing Mode, the source or destination address is specified by using 8-bit
data in the instruction. Only the internal data memory can be used in this mode. Here some
of the examples of direct Addressing Mode.
MOV 80H, R6;
MOV R2, 45H;
MOV R0, 05H;
Register indirect addressing Mode
In this mode, the source or destination address is given in the register. By using register
indirect addressing mode, the internal or external addresses can be accessed. The R0 and
R1 are used for 8-bit addresses, and DPTR is used for 16-bit addresses, no other registers
can be used for addressing purposes. Let us see some examples of this mode.
MOV 0E5H, @R0;
MOV @R1, 80H
In the instructions, the @ symbol is used for register indirect addressing.

You might also like