MPMC Unit (4) - III ECE (R19)
MPMC Unit (4) - III ECE (R19)
MPMC Unit (4) - III ECE (R19)
UNIT-4
8051 MICROCONTROLLER
Page 1 of 22
III ECE - MPMC– UNIT (4)
Microprocessors Microcontrollers
Microprocessors are used for general purpose Microcontrollers are used for some specific
applications. control applications.
Microprocessor contains ALU, Registers and Microcontroller contains all the features of
Timing control units. Microprocessor and as well as internal RAM,
ROM, I/O ports, Serial port, Interrupt
control, Timers/Counters….etc.
Microprocessor will have one (or) two types of Microcontroller has many bit-handling-
bit-handling-instructions. instructions.
Page 2 of 22
III ECE - MPMC– UNIT (4)
The 8051 has Four 8-bit I/O ports used for sending and receiving data from external
devices. The alternate function of each port is given below:
PORT-1 : It acts as a 8-bit I/O port & this port has no alternate function
PORT-2 : ̅̅̅̅ = 1
It acts as a 8-bit I/O port when 𝐄𝐀
It acts as external Address bus (A8 – A15) when ̅̅̅̅
𝐄𝐀 = 0
Page 3 of 22
III ECE - MPMC– UNIT (4)
Page 4 of 22
III ECE - MPMC– UNIT (4)
7. Interrupt Control :
The 8051 has internal serial data port which uses SBUF register to hold the serial
data to be transmitted (or) received data.
SBUF is a full duplex serial data buffer register – Tx buffer & Rx buffer.
ALE (Address Latch Enable) : This signal is used to enable the address latches for
the de-multiplexing of Address/Data lines.
̅̅̅̅̅̅̅̅ (Program Strobe Enable) : It is used to read the code from external ROM
𝐏𝐒𝐄𝐍
RESET : This signal is used to reset the microcontroller . After Reset, PC is initialized
to ZERO and µc starts execution from location 0000H of internal ROM.
XTAL0 & XTAL1 : These two pins are provided for connecting the crystal oscillator
Page 5 of 22
III ECE - MPMC– UNIT (4)
General purpose registers are 8-bit registers used to hold the 8-bit data
DPTR (Data pointer) is a 16-bit register used to hold the address of external RAM
and ROM. It is divided into two 8-bit registers named as DPH and DPL
PC (Program Counter) is a 16-bit register used to hold the address of next instruction
to be fetched from ROM
SP (Stack Pointer) is used to hold the address of stack top.
PSW (Program Status Word) is a flag register which hold the status flags
The 8051 provides 128 bytes of memory for Special Function Registers (SFRs).
The SFRs are used to perform the specific functions and are used to control timers,
counters, serial I/O, port I/O, and peripherals
Page 6 of 22
III ECE - MPMC– UNIT (4)
The 8051 microcontroller has separate Data memory (RAM) & Program Memory (ROM)
The RAM is used to store temporary data and keeping intermediate results /variables.
The ROM is used to store the permanent program being executed.
Internal Memory:
(a) 128-bytes of RAM (Data memory) : 00 H to 7F H
(b) 128-bytes of SFR memory (Special Function Registers) : 80 H to FF H
(c) 4 K bytes of internal ROM (Program memory) : 0000 H to 0FFF H
External Memory:
If the memory built in the microcontroller is not sufficient, then it is possible to add
external memory with capacity of 64Kbytes.
In this case, PORT-0 & PORT-2 are used for their addressing and data transmission.
External memory is connected when ̅̅̅̅ 𝐄𝐀 = 0
̅̅̅̅
If 𝐄𝐀 = 0, PORT-0 emits AD0-AD7 and PORT-2 emits A8-A15
̅̅̅̅̅̅̅̅
𝐏𝐒𝐄𝐍 (Program Strobe Enable) is used to access the external ROM
𝐑𝐃̅̅̅̅ and 𝐖𝐑
̅̅̅̅̅ control signals are used to access the external RAM
Page 7 of 22
III ECE - MPMC– UNIT (4)
INTERNAL RAM
The 8051 has 128-bytes of internal RAM which is divided into 3-parts as shown in figure.
32- bytes : Working registers (00 H to 1F H)
16-bytes : Bit addressable area (20 H to 2F H)
80-bytes : General purpose area (30 H to 3F H)
The first 32-bytes of internal RAM can be used as 32- working registers.
This area is divided into 4 – register banks : BANK-0 , BANK-1, BANK-2 & BANK-3
Each bank consists of 8- registers : R0 , R1 , R2 , R3 , R4 , R5 , R6 , R7
The Register Banks are selected by the bits RS1 & RS0 of PSW
Page 8 of 22
III ECE - MPMC– UNIT (4)
The 8051 provides 128 bytes of memory for Special Function Registers (SFRs).
The SFRs are used to perform the specific functions and are used to control timers,
counters, serial I/O, port I/O, and peripherals.
Page 9 of 22
III ECE - MPMC– UNIT (4)
MOVC A, @DPTR : Move the code byte from external ROM location
pointed by DPTR to Accumulator.
MOVC A, @A+DPTR : Move the code byte from external ROM location
pointed by (A+DPTR) to Accumulator.
Page 10 of 22
III ECE - MPMC– UNIT (4)
MOVX A,@DPTR ; Move the data from external RAM location pointed by DPTR
to Accumulator
Page 11 of 22
III ECE - MPMC– UNIT (4)
2. Register addressing:
The data is available in any one of the general purpose registers.
Ex: MOV A, R0 ; The content of register R0 is copied to register A
ADD A, R0 ; The content of register R0 is added to register A
3. Direct addressing:
The address of the data is available in the instruction.
Ex: MOV A, 25H ; The content of internal RAM location 25 H is moved to A
ADD A, 36H ; The content of internal RAM location 36 H is added to A
4. Indirect addressing:
The address of the data is available in the register.
The symbol ‘@ ’ is used to indicated indirect addressing.
Ex: MOV A,@R0 ; The content of internal RAM location pointed by R0 is moved to A
MOVX A,@DPTR ; The content of external RAM pointed by DPTR is moved to A
5. Implicit addressing:
There are some instructions which operate on the content of Accumulator.
Such instructions do not require the address of operand.
This type of addressing is called as Implicit (or) Implied addressing.
Ex: DAA - Decimal Adjust Accumulator after addition
6. Indexed addressing:
The address of the operand is the sum of A & PC (or) sum of A & DPTR.
Ex: MOVC A, @A+PC
MOVC A, @A+DPTR ; Moves the code byte from external ROM location
pointed by (A+DPTR) to Accumulator.
Page 12 of 22
III ECE - MPMC– UNIT (4)
(ii) Exchange
This instruction swaps the content of A with specified operand
XCH A, R0 ; Exchange the contents of A with register R0
Page 13 of 22
III ECE - MPMC– UNIT (4)
Page 14 of 22
III ECE - MPMC– UNIT (4)
Rotate Instructions
Page 15 of 22
III ECE - MPMC– UNIT (4)
Conditional Execution
JC rel ; Jump if C =1
JNC rel ; Jump if C= 0
Page 16 of 22
III ECE - MPMC– UNIT (4)
M1 M0 Mode Register
0 0 Mode-0 13-bit
0 1 Mode-1 16-bit
1 0 Mode-2 8-bit→ Auto reload
1 1 Mode-3 8-bit
Page 17 of 22
III ECE - MPMC– UNIT (4)
The timers of 8051 can be operated in 4 Modes - Mode 0, Mode 1, Mode 2, mode 3.
Page 18 of 22
III ECE - MPMC– UNIT (4)
MODE-3 : In mode-3 operation TH0 and TL0 acts as TWO independent 8-bit timers.
The timer TL0 uses Timer0 control bits. The timer TH0 uses Timer1 control bits
Timer 1 TL1 : TH1 (13- bit) TL1 : TH1(16- bit) TL1 (8- bit)
Page 19 of 22
III ECE - MPMC– UNIT (4)
The Interrupt service routine (ISR) for each interrupt begins at fixed location in
internal ROM
Interrupt ROM location
External interrupt -0 0003 H
Timer-0 over flow flag 000B H
External interrupt -0 0013 H
Timer-0 over flow flag 001B H
Serial port interrupt (TI/RI) 0023 H
Page 20 of 22
III ECE - MPMC– UNIT (4)
If two interrupts with some priority occurs at same time, then they have the following
priorities.
Page 21 of 22
III ECE - MPMC– UNIT (4)
The 8051 has internal serial data port which uses SBUF register to hold the serial
data to be transmitted (or) received data.
SBUF is a full duplex serial data buffer register, consists of Tx buffer & Rx buffer.
The internal RAM address of SBUF is 99 H.
The Pins TxD & RxD are used to transmit/receive serial data
Serial data communication is controlled by TWO control registers
SCON : Serial port Control register controls the serial data
PCON : Power Control register control the data rates
Page 22 of 22