Unit4 EE3404 MPMC-2
Unit4 EE3404 MPMC-2
[Regulation-2021]
Unit 4
Introduction to 8051
Microcontroller
MP&MC/EE3404 Lecture Notes
by
Dr.I.William Christopher
Professor/EEE Dept./LICET
3/30/2025 EE3404/MPMC/Unit-4 1
Course Objectives
▪ To study the addressing modes & instruction set of 8085
& 8051
3/30/2025 EE3404/MPMC/Unit-4 3
Units of Microprocessor & Microcontroller
The Course deals with the following Units:
Unit –I : Introduction to 8085 Architecture
3/30/2025 EE3404/MPMC/Unit-4 4
Text and Reference Books
Textbooks:
1) Ramesh S. Gaonkar, ‘Microprocessor Architecture Programming and
Application’, Pen ram International (P)ltd., Mumbai, 6th Education, 2013.
2) Muhammad Ali Mazidi & Janice Gilli Mazidi, ‘The 8051 Micro Controller
and Embedded Systems’, Pearson Education, Second Edition 2011.
3) Muhammad Ali Mazidi & Janice Gilli Mazidi, ‘The PIC Micro Controller
and Embedded Systems’, 2010
Reference Books:
1) Douglas V. Hall, “Micro-processors & Interfacing”, Tata McGraw Hill 3rd
Edition, 2017.
2) Krishna Kant, “Micro-processors & Micro-controllers”, Prentice Hall of
India, 2007.
3) Mike Predko, “8051 Micro-controllers”, McGraw Hill, 2009
4) Kenneth Ayala, ‘The 8051 Microcontroller’, Thomson, 3rd Edition 2004.
3/30/2025 EE3404/MPMC/Unit-4 5
Unit-I: Introduction to 8085 Architecture
Topics to be discussed:
▪ Functional Block Diagram
▪ Memory Interfacing
▪ Timing Diagram
▪ Interrupt Structure
3/30/2025 EE3404/MPMC/Unit-4 6
Unit-II: 8085 Instruction Set and Programming
Topics to be discussed:
▪ Instruction Format and Addressing Modes
▪ Assembly Language Format
▪ Data Transfer, Data Manipulation &
Control Instructions
▪ Programming:
✓Loop structure with Counting & Indexing
✓Look up table
✓Subroutine instructions
✓Stack
3/30/2025 EE3404/MPMC/Unit-4 7
Unit-III: Interfacing Basics and ICs
Topics to be discussed:
▪ Study of Architecture and programming of ICs:
✓ 8255 - PPI
✓ 8259 - PIC
✓ 8251 - USART
✓ 8279 - Keyboard display controller
✓ 8254 - Timer/Counter
▪ Interfacing with 8085
✓A/D and D/A converter interfacing
3/30/2025 EE3404/MPMC/Unit-4 8
Unit-IV: Introduction to 8051 Microcontroller
Topics to be discussed:
▪ Functional Block Diagram
▪ Instruction Format And Addressing Modes
▪ Interrupt Structure
▪ Timer
▪ I/O Ports
▪ Serial Communication
▪ Simple Programming
▪ Keyboard And Display Interface
▪ Temperature Control System
▪ Stepper Motor Control
▪ Usage of IDE for Assembly Language Programming
3/30/2025 EE3404/MPMC/Unit-4 9
Unit-V: Introduction to RISC Based Architecture
Topics to be discussed:
▪ PIC16 /18 Architecture
▪ Memory Organization
▪ Addressing Modes
▪ Instruction Set
▪ Programming Techniques
▪ Timers
▪ I/O Ports
▪ Interrupt Programming
3/30/2025 EE3404/MPMC/Unit-4 10
Introduction
➢ Microprocessor – silicon chip which includes ALU,
register circuits & control circuits.
3/30/2025 EE3404/MPMC/Unit-4 11
Introduction to Microcontrollers
• Microcontroller – silicon chip which includes microprocessor,
memory & I/O ports in a single package.
• A Microcontroller has a CPU (Microprocessor) in addition to a
fixed amount of RAM,ROM, I/O ports and a timer all on a
single chip.
• 8051/8031 is a 8- bit Microcontroller.
• It has,
✓ [CPU + I/O ports + Timer’s] + [+ ROM] [+ RAM]
✓ Low to moderate performance only
✓ Limited RAM space, ROM space, and I/O pins
✓ EPROM version available
✓ Low chip-count to implement a small system
✓ Low-cost at large quantities
✓ Development tools readily available at reasonable
3/30/2025 EE3404/MPMC/Unit-4 12
Features of 8051/8031 Microcontroller
• ROM – 4K bytes
• RAM – 128 bytes
• Timers – ‘2’ (Timer 0, Timer 1)
• I/O Pins – ‘32’ [4 ports: Port 0 (AD0-AD7); Port 1;
Port 2 (A8-A15); Port 3 (Important Alternate Functions);
Each Port has 8 I/O pins]
• Serial Port – ‘1’ (UART : TxD (Transmit Data);
RxD (Receive Data);)
• Interrupt Sources – ‘6’ ( IE0; IE1; TF0; TF1; RI+TI )
• 8031 is called “ROM-less 8051”
• 8052 has all features of 8051 in addition to an extra 128 bytes
of RAM, extra Timer and extra 2 Interrupt Sources.
3/30/2025 EE3404/MPMC/Unit-4 13
Pin out of 8051 Microcontroller
3/30/2025 EE3404/MPMC/Unit-4 14
Pin out of
8051
Microcontroller
3/30/2025 EE3404/MPMC/Unit-4 15
Pin Descriptions of 8051
3/30/2025 EE3404/MPMC/Unit-4 16
Alternate functions of Port pins of 8051
3/30/2025 EE3404/MPMC/Unit-4 17
Functional block diagram of 8051/8031
3/30/2025 EE3404/MPMC/Unit-4 18
Architecture of 8051 Micro controller
3/30/2025 EE3404/MPMC/Unit-4 19
8051 Registers
3/30/2025 EE3404/MPMC/Unit-4 20
Register Banks of 8051 Microcontroller
▪ Four banks of 8 byte-sized registers, Each Bank has 8
Registers R0 to R7
▪ Addresses are :
18H - 1FH for bank 3
10H – 17H for bank 2
08H - 0FH for bank 1
00H - 07H for bank 0 (default)
▪ Active bank selected by bits [ RS1, RS0 ] in PSW (Program
Status Word).
▪ Permits fast “context switching” in Interrupt Service Routines
(ISR).
3/30/2025 EE3404/MPMC/Unit-4 21
Program Status Word (PSW) of 8051
3/30/2025 EE3404/MPMC/Unit-4 22
Register Bank of 8051
3/30/2025 EE3404/MPMC/Unit-4 23
16-bit Registers of 8051
Stack Pointer (8-bit)
D7 D0
DPH DPL
D15 D8 D7 D0
3/30/2025 EE3404/MPMC/Unit-4 24
16-bit CPU Registers of 8051
Stack Pointer :
✓ It is 8 bit wide.
✓ It is incremented before data is stored during PUSH and CALL
instructions.
✓ The stack array can reside anywhere in on-chip RAM.
✓ The stack pointer is initialized to 07H after a reset.
✓ This causes the stack to begin at location 08H.
Data Pointer (DPTR) :
✓ It consists of a high byte (DPH) and a low byte (DPL).
✓ Its function is to hold a 16-bit address.
✓ It may be manipulated as a 16-bit data register or as two
independent 8-bit registers.
✓ It serves as a base register in indirect jumps, lookup table
instructions, and external data transfer.
3/30/2025 EE3404/MPMC/Unit-4 25
Von Neumann & Harvard Architectures
3/30/2025 EE3404/MPMC/Unit-4 26
Memory Organization of 8051 (1)
PolyU 11
3/30/2025 EE3404/MPMC/Unit-4 27
Memory Organization of 8051 (2)
On-chip and Off-chip Program Code Access
3/30/2025 EE3404/MPMC/Unit-4 28
Memory Organization of 8051 (3)
Program Memory (Read Only) Structure
3/30/2025 EE3404/MPMC/Unit-4 29
Memory Organization of 8051 (4)
Accessing External Program Memory
3/30/2025 EE3404/MPMC/Unit-4 30
Memory Organization of 8051 (5)
Data Memory (Read/Write) Structure
✓ The 8051 can address up to 64 Kbytes of external data
memory.
3/30/2025 EE3404/MPMC/Unit-4 32
Memory Organization of 8051 (7)
Accessing External Data Memory
3/30/2025 EE3404/MPMC/Unit-4 33
Memory Organization of 8051 (8)
Internal Data Memory
3/30/2025 EE3404/MPMC/Unit-4 34
Memory Organization of 8051 (9)
128 bytes of RAM Direct and Indirect Addressable
3/30/2025 EE3404/MPMC/Unit-4 35
Memory Organization of 8051 (10)
Four Banks of Registers R0 – R7
3/30/2025 EE3404/MPMC/Unit-4 36
Special Function Registers (SFRs)-1
✓ Unlike other microprocessors in the Intel family, 8051 uses
memory-mapped I/O through a set of special function
registers that are implemented in the address space
immediately above the 128 bytes of RAM.
3/30/2025 EE3404/MPMC/Unit-4 37
Special Function Registers (SFRs)-2
3/30/2025 EE3404/MPMC/Unit-4 38
Special Function Registers (SFRs)-3
3/30/2025 EE3404/MPMC/Unit-4 39
I/O Ports of 8051 (1)
✓ It has 4 bidirectional 8-bit I/O ports.
✓ Each port is connected to an 8-bit register in the SFR.
✓ P0 = 80H, P1 = 90H, P2 = A0H, P3 = B0H
✓ Each port is also connected to an output driver and an
input buffer.
✓ All ports are configured for output at reset.
✓ In addition to simple I/O, Ports P0 and P2 double as the
8051’s Address and Data busses.
✓ Port P3 doubles as the 8051’s external control lines for the
timers and counters.
3/30/2025 EE3404/MPMC/Unit-4 40
I/O Ports of 8051 (2)
Pull-up Resistor Pull-down Resistor
3/30/2025 EE3404/MPMC/Unit-4 41
I/O Ports of 8051 (3)
Port-0 (1)
✓ P0 can be used for input or output.
3/30/2025 EE3404/MPMC/Unit-4 42
I/O Ports of 8051 (4)
Port-0 (2)
3/30/2025 EE3404/MPMC/Unit-4 43
I/O Ports of 8051 (5)
Port-0 (3)
3/30/2025 EE3404/MPMC/Unit-4 44
I/O Ports of 8051 (6)
Port-1 (1)
✓ Port 1 occupies a total of 8 pins (pins 1 through 8).
3/30/2025 EE3404/MPMC/Unit-4 45
I/O Ports of 8051 (7)
Port-1 (2)
3/30/2025 EE3404/MPMC/Unit-4 46
I/O Ports of 8051 (8)
Port-2 (1)
✓ Port 2 occupies a total of 8 pins (pins 21- 28).
✓ It can be used as input or output.
✓ Just like P1, P2 does not need any pull-up resistors since it
already has pull-up resistors internally.
✓ Upon reset, Port 2 is configured as an output port.
✓ To make port 2 an input, it must programmed by writing 1
to all its bits.
✓ P0 provides the lower 8 bits via A0-A7, it is the job of P2 to
provide bits A8-A15 of the address (dual function)
3/30/2025 EE3404/MPMC/Unit-4 47
I/O Ports of 8051 (9)
Port-2 (2)
✓ Since an 8051 is capable of accessing 64K bytes of external
memory, it needs a path for the 16 bits of the address.
3/30/2025 EE3404/MPMC/Unit-4 48
I/O Ports of 8051 (10)
Port-3 (1)
✓ Port 3 occupies a total of 8 pins, pins 10 through 17.
3/30/2025 EE3404/MPMC/Unit-4 49
I/O Ports of 8051 (11)
Port-3 (2)
3/30/2025 EE3404/MPMC/Unit-4 50
I/O Ports of 8051 (12)
Port-3 Alternate Functions (3)
3/30/2025 EE3404/MPMC/Unit-4 51
I/O Ports of 8051 (13)
Instructions for reading the status of an input port
3/30/2025 EE3404/MPMC/Unit-4 52
I/O Ports of 8051 (14)
Instructions for Reading a Latch (Read–Modify–Write)
3/30/2025 EE3404/MPMC/Unit-4 53
Timers of 8051 (1)
✓ 8051 has two 16-bit programmable UP timers/counters.
✓ They can be configured to operate either as timers or as event
counters.
✓ The names of the two timers are T0 and T1 respectively.
✓ The timer content is available in four 8-bit special function
registers, viz, TL0,TH0,TL1 and TH1 respectively.
3/30/2025 EE3404/MPMC/Unit-4 54
Timers of 8051 (2)
Clock (1)
✓ Every Timer needs a clock to work, and 8051 provides it from
an external crystal which is the main clock source for Timer.
✓ The internal circuitry in the 8051 microcontrollers provides a
clock source to the timers which is 1/12th of the frequency of
crystal attached to the microcontroller, also called as
Machine cycle frequency.
3/30/2025 EE3404/MPMC/Unit-4 55
Timers of 8051 (3)
Clock (2)
3/30/2025 EE3404/MPMC/Unit-4 56
Timers of 8051 (4)
Timer/Counter-0
3/30/2025 EE3404/MPMC/Unit-4 57
Timers of 8051 (5)
Timer/Counter-1
3/30/2025 EE3404/MPMC/Unit-4 58
Timers of 8051 (6)
Timer/Counter-SFRs
✓ In the “Timer" function mode, the counter is incremented in
every machine cycle. Thus, one can think of it as counting
machine cycles. Hence the clock rate is 1/12 th of the oscillator
frequency.
✓ In the "Counter" function mode, the register is incremented in
response to a 1 to 0 transition at its corresponding external input
pin (T0 or T1).
✓ It requires 2 machine cycles to detect a high-to-low transition.
Hence maximum count rate is 1/24 th of the oscillator frequency.
✓ The operation of the timers/counters is controlled by two special
function registers (SFRs), TMOD and TCON respectively.
3/30/2025 EE3404/MPMC/Unit-4 59
TMOD (Timer Mode) Register of 8051 (1)
3/30/2025 EE3404/MPMC/Unit-4 60
TMOD (Timer Mode) Register of 8051 (2)
Bit 5:4 & 1:0 - M1:M0: Timer/Counter mode select bit
These are Timer/Counter mode select bit as per below table
M1 M0 Mode Operation
13-bit timer/counter,
0 0 Mode-0
8-bit of THx & 5-bit of TLx
16-bit timer/counter,
0 1 Mode-1
THx cascaded with TLx
8-bit timer/counter (auto reload mode),
1 0 Mode-2 TLx reload with value held by THx each time
TLx overflow
3/30/2025 EE3404/MPMC/Unit-4 62
TMOD (Timer Mode) Register of 8051 (4)
Mode-0 (13-bit timer mode)
3/30/2025 EE3404/MPMC/Unit-4 64
TMOD (Timer Mode) Register of 8051 (5)
Mode-1 (16-bit timer mode)
This mode is similar to mode-0 except for the fact that the Timer
operates in 16-bit mode.
3/30/2025 EE3404/MPMC/Unit-4 65
TMOD (Timer Mode) Register of 8051 (6)
Mode-2 (8-bit auto-reload timer mode)
✓ Mode 2 is 8-bit auto-reload timer mode.
✓ In this mode we have to load the THx-8 bit value only.
✓ when the Timer gets started, THx value gets automatically loaded
into the TLx and TLx start counting from that value.
✓ After the value of TLx overflows from the 0xFF to 0x0, the TFx flag
gets set and again value from the THx gets automatically loaded
into the TLx register. That’s why this is called as auto reload mode.
3/30/2025 EE3404/MPMC/Unit-4 66
TMOD (Timer Mode) Register of 8051 (7)
✓ In this mode when the timer overflows i.e. TLX becomes FFH, it is
fed with the value stored in THX.
✓ For example if we load THX with 50H then the timer in mode 2
will count from 50H to FFH. After that 50H is again reloaded. This
mode is useful in applications like fixed-time sampling.
3/30/2025 EE3404/MPMC/Unit-4 67
TMOD (Timer Mode) Register of 8051 (8)
Mode-3 (Split timer mode)
✓ Timer 1 in mode-3 simply holds its count.
✓ The effect is same as setting TR1=0. Timer0 in mode-3 establishes
TL0 and TH0 as two separate counters.
✓ Control bits TR1 and TF1 are used by Timer-0 (higher 8 bits) (TH0)
in Mode-3 while TR0 and TF0 are available to Timer-0 lower 8
bits(TL0).
3/30/2025 EE3404/MPMC/Unit-4 68
TCON (Timer Control) Register of 8051 (1)
It is 8-bit control register and contains timer and interrupt flags.
3/30/2025 EE3404/MPMC/Unit-4 72
Interrupts of 8051
✓ Interrupts are basically the events that temporarily
suspend the main program, pass the control to the
external sources and execute their task.
✓ It then passes the control to the main program where it
had left off.
✓ 8051 has five interrupts.
✓ All of the interrupts can be enabled or disabled by using
the IE (Interrupt Enable) register.
✓ The Interrupts priority level can be decided by using the
IP (Interrupt Priority) register
3/30/2025 EE3404/MPMC/Unit-4 73
Interrupts of 8051
✓ Interrupts and their vector addresses are given below
Interrupt Address
INT0 0003H
INT1 000BH
T0 0013H
T1 001BH
TI/RI 0023H
3/30/2025 EE3404/MPMC/Unit-4 74
Interrupt Structure of 8051
3/30/2025 EE3404/MPMC/Unit-4 75
Interrupt Structure of 8051
3/30/2025 EE3404/MPMC/Unit-4 76
IE (Interrupt Enable) Register
▪ This register can be used to enable or disable interrupts
programmatically.
▪ This register is an SFR and the address is A8H.
3/30/2025 EE3404/MPMC/Unit-4 77
IP (Interrupt Priority) Register
▪ This IP register can be used to store the priority levels for
each interrupt.
▪ This is also a bit addressable SFR. Its address is B8H.
3/30/2025 EE3404/MPMC/Unit-4 78
Serial vs Parallel Communication (1)
3/30/2025 EE3404/MPMC/Unit-4 79
Serial vs Parallel Communication (2)
3/30/2025 EE3404/MPMC/Unit-4 80
Basics of Serial Communication (1)
Various Modes
3/30/2025 EE3404/MPMC/Unit-4 81
Basics of Serial Communication (2)
Comparison b/w Asynchronous and Synchronous Communication
Asynchronous serial communication Synchronous serial communication
transmitter and receiver are not transmitter and receiver are
synchronized by clock. synchronized by clock.
Character may arrive at any rate at Character is received at constant
receiver rate.
Data transfer is character oriented Data transfer takes place in blocks.
Start and stop bits are not required
Start and stop bits are required to to establish communication of each
establish communication of each character, however ,synchronization
character. bits are required to transfer the data
block.
Used in low-speed transmissions Used in high-speed transmission
3/30/2025 EE3404/MPMC/Unit-4 82
Basics of Serial Communication (3)
Data Transfer Rate (1)
✓ The rate of data transfer in serial data communication is stated in
bps (bits per second).
✓ Another widely used terminology for bps is baud rate.
✓ However, the baud and bps rates are not necessarily equal.
✓ This is due to the fact that baud rate is the modem terminology
and is defined as the number of signal changes per second.
✓ In modems a single change of signal sometimes transfers several
bits of data.
✓ As far as the conductor wire is concerned, the baud rate and bps
are the same
3/30/2025 EE3404/MPMC/Unit-4 83
Basics of Serial Communication (4)
Data Transfer Rate (2)
✓ The data transfer rate of a given computer system depends on
communication ports incorporated into that system.
✓ For example, the early IBM PC/ XT could transfer data at the
rate of 100 to 9600 bps.
3/30/2025 EE3404/MPMC/Unit-4 84
RS 232 Standards (1)
✓ To allow compatibility among data communication equipment
made by various manufacturers, an interfacing standard called
RS232 was set by the Electronics Industries Association (EIA) in
1960.
3/30/2025 EE3404/MPMC/Unit-4 85
RS 232 Standards (2)
✓ However, since the standard was set long before the advent of
the TTL logic family, its input and output voltage levels are not
TTL-compatible.
3/30/2025 EE3404/MPMC/Unit-4 86
RS 232 Standards (3)
RS232 Pins
✓ The original RS232 cable, commonly referred to as the DB-25
connector (Serial I/O Standard)
✓ Since not all the pins are used in PC cables, IBM introduced
the DB-9 version of the serial I/O standard, which uses 9 pins
only
3/30/2025 EE3404/MPMC/Unit-4 87
RS 232 Standards (4)
RS232 Pins (DB-25)
3/30/2025 EE3404/MPMC/Unit-4 88
RS 232 Standards (5)
IBM PC DB-9 Signals
3/30/2025 EE3404/MPMC/Unit-4 89
RS 232 Standards (6)
Data Communication Classification (1)
✓ Current terminology classifies data communication equipment as
▪ DTE (Data Terminal Equipment)
▪ DCE (Data Communication Equipment)
✓ DTE refers to terminals and computers that send and receive
data,
3/30/2025 EE3404/MPMC/Unit-4 91
8051 Connection to RS232 (1)
✓ RS232 standard is not TTL-compatible; therefore, it requires a
line driver such as the MAX232 chip to convert RS232 voltage
levels to TTL levels, and vice versa.
✓ 8051 has two pins that are used specifically for transferring and
receiving data serially.
✓ These two pins are called TxD and RxD and are part of the port 3
group (P3.0 and P3.1). Pin 11 of the 8051 (P3.1) is assigned to
TxD and pin 10 (P3.0) is designated as RxD.
3/30/2025 EE3404/MPMC/Unit-4 92
8051 Connection to RS232 (2)
✓ These pins are TTL-compatible; Therefore, they require a line
driver to make them RS232 compatible.
✓ The MAX232 has two sets of line drivers for transferring and
receiving data.
✓ The line drivers used for TxD are called T1 and T2, while the line
drivers for RxD are designated as R1 and R2.
3/30/2025 EE3404/MPMC/Unit-4 93
8051 Connection to RS232 (3)
3/30/2025 EE3404/MPMC/Unit-4 94
8051 Connection to RS232 (4)
3/30/2025 EE3404/MPMC/Unit-4 95
Serial Communication in 8051 (1)
Baud Rate:- The rate at which the number of bits are
transmitted
3/30/2025 EE3404/MPMC/Unit-4 96
Serial Communication in 8051 (2)
3/31/2025 EE3404/MPMC/Unit-4 97
Serial Communication in 8051 (3)
3/31/2025 EE3404/MPMC/Unit-4 98
Serial Communication in 8051 (4)
3/31/2025 EE3404/MPMC/Unit-4 99
Serial Communication in 8051 (5)
▪ JMP @A+DPTR – Jump indirect relative to the data pointer; the address
of a jump instruction is calculated as the sum of the accumulator and the
data pointer.
▪ MOVC A,@A+DPTR - Move a byte of data from program memory, whose
address can be found by adding the accumulator and the data pointer, to
the accumulator.
✓ In this mode, the full 64K code space is available and the
instruction is long and position-dependent.
▪ The CPU accesses both rows and columns through ports; therefore,
with two 8-bit ports, an 8 x 8 matrix of keys can be connected to a
microprocessor.
Solution:
From the previous slide, the row and column can be used to
identify the key.
(a) The row belongs to D0 and the column belongs to D2; therefore,
key number 2 was pressed.
(b) The row belongs to D1 and the column belongs to D3; therefore,
key number 7 was pressed.
3/30/2025 EE3404/MPMC/Unit-4 180
Keyboard and Display
Interface (16)
Keyboard Interfacing
- Flowchart (1)
▪ LM336-2.5 zener diode to fix the voltage across the 10K pot at 2.5V
▪ LM336-2.5 should overcome any fluctuations in the power supply.
3/30/2025 EE3404/MPMC/Unit-4 193
Temperature Control System (9)
Assembly Language Program (1)
Note:
▪ Change the value of DELAY to set the speed of rotation
▪ Using single-bit instructions SETB and CLR instead of RR A to create the
sequences.
3/30/2025 EE3404/MPMC/Unit-4 208
8051 Connection to Stepper Motor (4)
Using Transistors as Drivers (1)
▪ Instead of the ULN2003, transistors are used as drivers