Microcontrollers Notes
Microcontrollers Notes
(E) Interrupts
Interrupts allow the 8051 to pause execution of the main program and execute a separate
function when an event occurs.
There are five interrupts in the 8051:
1. External Interrupt 0 (INT0)
2. External Interrupt 1 (INT1)
Data Transfer Instructions Move data between registers, memory, or I/O ports.
Logical Instructions Perform bitwise AND, OR, XOR, and rotate operations.
MOV Rn, #data Load immediate data into Rn MOV R3, #25H
MOV DPTR, #data16 Load immediate 16-bit data into DPTR MOV DPTR, #1234H
3. Arithmetic Instructions
These instructions perform addition, subtraction, multiplication, and division.
MUL AB Multiply A and B, store result in A (low byte) and B (high MUL AB
byte)
Examples:
MOV A, #10H ; Load 10H into accumulator
MOV R1, #05H ; Load 05H into R1
ADD A, R1 ; A = A + R1 (10H + 05H = 15H)
MUL AB ; Multiply A and B
DIV AB ; Divide A by B
RL A Rotate A left RL A
RR A Rotate A right RR A
Examples:
MOV A, #55H ; Load 55H into accumulator
ANL A, #0FH ; AND operation with 0FH
ORL A, #F0H ; OR operation with F0H
XRL A, #AAH ; XOR operation with AAH
5. Branching Instructions
These instructions control program flow using jumps and calls.
CJNE A, #data, label Compare A and jump if not equal CJNE A, #10H, SKIP
DJNZ Rn, label Decrement Rn and jump if not zero DJNZ R3, LOOP
Examples:
MOV A, #00H
JZ END ; Jump to END if A is 0
MOV R1, #10H
DJNZ R1, LOOP ; Decrement R1 and jump to LOOP if not zero
JBC bit, label Jump if bit is 1 and clear it JBC P1.1, LOOP
10 | P a g e BSDVP ACADEMY
BSDVP ACADEMY
(B) Using LCALL
ORG 0000H
MOV P2, #0AAH ; Send 0AAH to Port 2
LCALL TOGGLE ; Call TOGGLE subroutine
SJMP $ ; Infinite loop
TOGGLE:
CPL P2 ; Complement (toggle) Port 2
RET ; Return to main program
END
Explanation:
• MOV P2, #0AAH loads Port 2.
• LCALL TOGGLE calls the TOGGLE subroutine.
• CPL P2 toggles all bits of Port 2.
• RET returns execution to the main program.
11 | P a g e BSDVP ACADEMY
BSDVP ACADEMY
SUB2:
RET ; Return to SUB1
END
Stack Operations:
1. LCALL SUB1 → Pushes return address onto the stack.
2. LCALL SUB2 → Pushes another return address onto the stack.
3. RET in SUB2 → Pops stack to return to SUB1.
4. RET in SUB1 → Pops stack to return to the main program.
8. Nested Subroutines
A nested subroutine is when a subroutine calls another subroutine before returning.
Example of Nested Subroutines
ORG 0000H
LCALL FUNCTION1 ; Call FUNCTION1
SJMP $ ; Infinite loop
FUNCTION1:
LCALL FUNCTION2 ; Call FUNCTION2 from FUNCTION1
RET ; Return to main program
FUNCTION2:
NOP ; Do nothing
RET ; Return to FUNCTION1
END
12 | P a g e BSDVP ACADEMY
BSDVP ACADEMY
Execution Flow:
1. LCALL FUNCTION1 → Goes to FUNCTION1.
2. LCALL FUNCTION2 → Goes to FUNCTION2.
3. RET in FUNCTION2 → Returns to FUNCTION1.
4. RET in FUNCTION1 → Returns to the main program.
13 | P a g e BSDVP ACADEMY
BSDVP ACADEMY
2. 8051 I/O Port Architecture
14 | P a g e BSDVP ACADEMY
BSDVP ACADEMY
(C) Bit-Level I/O Instructions
8051 allows bit manipulation, useful for controlling individual port pins.
15 | P a g e BSDVP ACADEMY
BSDVP ACADEMY
(C) Sending Data to an External Device
Send 0x55 to Port 0
MOV P0, #55H ; Send 55H to Port 0
5. Summary
MOV Pn, #data → Write to a port
MOV A, Pn → Read from a port
SETB / CLR / CPL → Control individual bits
JB / JNB → Conditional jumps based on input
16 | P a g e BSDVP ACADEMY
BSDVP ACADEMY
5. Time Delay Program in 8051 Microcontroller
1. Introduction to Time Delay in 8051
A time delay is a pause in program execution for a specific duration, commonly used for LED
blinking, motor control, and serial communication timing. The 8051 microcontroller
generates delays using loops and timers.
17 | P a g e BSDVP ACADEMY
BSDVP ACADEMY
LOOP2:
DJNZ R6, LOOP2 ; Decrement R6 until 0
DJNZ R7, LOOP1 ; Decrement R7 until 0
RET ; Return to main program
END
Explanation:
1. SETB P1.0 turns ON the LED.
2. ACALL DELAY calls a delay function.
3. CLR P1.0 turns OFF the LED.
4. ACALL DELAY adds another delay.
5. Nested loops count down to create a delay.
Bit Function
18 | P a g e BSDVP ACADEMY
BSDVP ACADEMY
Example: Delay Using Timer 0 (16-bit Mode)
ORG 0000H
MOV TMOD, #01H ; Set Timer 0 to 16-bit mode
AGAIN:
SETB P1.0 ; Turn ON LED
ACALL DELAY ; Call Timer-based delay
CLR P1.0 ; Turn OFF LED
ACALL DELAY ; Call Timer-based delay
SJMP AGAIN ; Repeat forever
DELAY:
MOV TH0, #0FDH ; Load high byte
MOV TL0, #0A0H ; Load low byte (50ms delay)
SETB TR0 ; Start Timer 0
WAIT:
JNB TF0, WAIT ; Wait until overflow
CLR TR0 ; Stop Timer
CLR TF0 ; Reset Timer Flag
RET ; Return to main program
END
Explanation:
1. MOV TMOD, #01H → Configures Timer 0 as a 16-bit timer.
2. MOV TH0, #0FDH and MOV TL0, #0A0H → Load timer registers.
3. SETB TR0 → Starts the timer.
4. JNB TF0, WAIT → Waits until the timer overflows.
5. CLR TR0 & CLR TF0 → Stops and resets the timer.
6. RET → Returns to the main program.
19 | P a g e BSDVP ACADEMY
BSDVP ACADEMY
5. Timer Calculation for Delay
The delay time depends on:
• Crystal frequency (11.0592 MHz)
• Timer mode (16-bit/8-bit)
• Timer register values (THx, TLx)
Formula to Calculate Delay
6. Comparison of Methods
20 | P a g e BSDVP ACADEMY
BSDVP ACADEMY
2. Assembler Directives in 8051
Assembler directives are categorized based on their function:
(A) Data Definition Directives
21 | P a g e BSDVP ACADEMY
BSDVP ACADEMY
VAR2 DS 2 ; Reserve 2 bytes
IC Function
22 | P a g e BSDVP ACADEMY
BSDVP ACADEMY
4. Interfacing Peripheral ICs with 8051
(A) Interfacing 8255 (Programmable Peripheral Interface)
• Expands I/O ports using three 8-bit ports (Port A, B, C).
• Controlled using the Control Register.
Example: Writing Data to 8255 Port A
MOV DPTR, #6000H ; Load address of 8255
MOV A, #80H ; Set Port A as output
MOVX @DPTR, A ; Write to Control Register
MOV A, #0FFH ; Data to be sent
MOVX @DPTR, A ; Send data to Port A
23 | P a g e BSDVP ACADEMY
BSDVP ACADEMY
7. 8086 Microprocessor Architecture
1. Introduction
The Intel 8086 is a 16-bit microprocessor introduced in 1978. It is widely known for its role
in the development of x86 architecture. The 8086 is a 16-bit processor, meaning it can
handle data 16 bits wide and processes 16 bits at a time. It was designed for high-
performance computing tasks and had significant influence on modern microprocessor
architecture.
24 | P a g e BSDVP ACADEMY
BSDVP ACADEMY
• AX (Accumulator Register): Often used in arithmetic and I/O operations.
• BX (Base Register): Used for addressing in data segment operations.
• CX (Count Register): Used in loop control, string operations.
• DX (Data Register): Used for I/O operations and as a secondary accumulator.
2. Segment Registers (16 bits each)
Used to hold the segment base addresses for accessing memory in the segmented memory
model.
• CS (Code Segment): Points to the code segment, where the program code is stored.
• DS (Data Segment): Points to the data segment, where variables and arrays are
stored.
• SS (Stack Segment): Points to the stack segment, used for storing temporary data
and function calls.
• ES (Extra Segment): Typically used for extra data storage during string operations.
3. Pointer and Index Registers (16 bits each)
These registers hold addresses of data in memory.
• SP (Stack Pointer): Points to the top of the stack.
• BP (Base Pointer): Used to access data on the stack.
• SI (Source Index): Used in string operations as the source address.
• DI (Destination Index): Used in string operations as the destination address.
4. Flag Register (16 bits)
The Flag Register contains status flags that are updated after every ALU operation. It
includes the following bits:
• Sign Flag (SF): Set if the result of the operation is negative.
• Zero Flag (ZF): Set if the result of the operation is zero.
• Auxiliary Carry Flag (AF): Set if there was a carry from bit 3 in a binary addition.
• Carry Flag (CF): Set if there was a carry in an arithmetic operation.
• Parity Flag (PF): Set if the result has an even number of 1's.
• Overflow Flag (OF): Set if there was a signed overflow during an operation.
25 | P a g e BSDVP ACADEMY
BSDVP ACADEMY
4. 8086 Architecture Blocks
(A) Bus Interface Unit (BIU)
The BIU handles all data transfers to and from memory. It interfaces with the system's
external components and memory by providing the address bus, data bus, and control
signals.
• Instruction Fetch: Fetches the instructions from memory.
• Address Generation: Uses segment registers and offsets to generate physical
addresses.
• Memory Read/Write: Controls memory operations by sending read or write signals.
Components of the BIU:
• Instruction Queue: The 8086 has a 6-byte instruction queue that fetches instructions
in advance to allow pipelining and faster processing. This helps in prefetching
instructions while others are being executed.
• Segment Registers: Contains CS, DS, SS, and ES.
• Physical Address Calculation: Combines segment address and offset address to
generate a 20-bit physical address.
(B) Execution Unit (EU)
The Execution Unit executes the instructions provided by the BIU. It contains the ALU and
the registers used for processing. It is responsible for processing data, controlling flags, and
performing operations.
Components of the EU:
• ALU: Performs arithmetic and logical operations.
• Registers: Holds data and performs calculations.
• Control Unit: Decodes and executes instructions.
26 | P a g e BSDVP ACADEMY
BSDVP ACADEMY
• Indirect Addressing: The operand is at an address stored in a register (e.g., MOV AX,
[BX]).
• Indexed Addressing: Combines a base register (like BX) and an index register (like SI)
to form an address (e.g., MOV AX, [BX + SI]).
• Relative Addressing: Used in branch instructions, the address is determined relative
to the current instruction pointer.
27 | P a g e BSDVP ACADEMY
BSDVP ACADEMY
8. 8086 Instruction Set
The 8086 microprocessor has a comprehensive instruction set that can be categorized
based on their functionality. These instructions help the microprocessor to perform a wide
range of operations such as data transfer, arithmetic and logical operations, branching,
string manipulation, and control. The instructions in the 8086 can operate on 16-bit
registers, memory, and input/output ports.
1. Instruction Categories
The 8086 instruction set is divided into several key categories based on their operations:
1. Data Transfer Instructions
These instructions are used to transfer data between registers, memory, and I/O ports.
MOV Move data from source to MOV AX, 50H (Move the value 50H into AX)
destination
PUSH Push data onto the stack PUSH AX (Push the value in AX to the stack)
POP Pop data from the stack POP AX (Pop the top value from the stack
into AX)
XCHG Exchange values between XCHG AX, BX (Exchange the values in AX and
two operands BX)
IN Input data from an I/O port IN AL, 60H (Read data from port 60H into AL)
OUT Output data to an I/O port OUT 60H, AL (Send the value in AL to port
60H)
2. Arithmetic Instructions
These instructions perform arithmetic operations such as addition, subtraction,
multiplication, and division.
ADD Add two operands and store the ADD AX, BX (AX = AX + BX)
result
28 | P a g e BSDVP ACADEMY
BSDVP ACADEMY
DEC Decrement an operand by 1 DEC BX (BX = BX - 1)
3. Logical Instructions
These instructions perform logical operations like AND, OR, XOR, etc.
AND Perform bitwise AND between two AND AX, BX (AX = AX AND BX)
operands
XOR Perform bitwise XOR between two XOR AX, BX (AX = AX XOR BX)
operands
NOT Perform bitwise NOT (invert bits) NOT AX (AX = NOT AX)
TEST Perform bitwise AND and set flags based TEST AX, BX (Sets flags based on
on the result AX AND BX)
4. Comparison Instructions
Comparison instructions compare two operands by subtracting them, and set the flags
accordingly.
29 | P a g e BSDVP ACADEMY
BSDVP ACADEMY
5. Control Transfer Instructions
These instructions alter the flow of program execution.
RET Return from a procedure or RET (Return from the current subroutine)
subroutine
JZ Jump if zero flag is set (if result JZ 2000H (Jump to 2000H if the zero flag is
of previous operation was zero) set)
JNZ Jump if zero flag is not set JNZ 2000H (Jump to 2000H if the zero flag
is not set)
JNC Jump if carry flag is not set JNC 3000H (Jump to 3000H if carry flag is
not set)
JNO Jump if overflow flag is not set JNO 4000H (Jump to 4000H if overflow
flag is not set)
6. String Instructions
These instructions are used for string manipulation (e.g., moving, comparing, and scanning
data in memory).
MOVS Move data from source string to MOVS (Moves data from DS:SI to
destination string ES:DI)
SCAS Scan a string for a particular byte or SCAS (Compares AL with the byte
word at ES:DI)
30 | P a g e BSDVP ACADEMY
BSDVP ACADEMY
LODS Load data from the source string to the LODS (Loads data from DS:SI to AL
accumulator or AX)
STOS Store data from the accumulator into STOS (Stores data from AL or AX to
the destination string ES:DI)
SHL (SAL) Shift left (arithmetic left) SHL AX, 1 (Shift AX left by 1 bit)
SHR Shift right (logical right) SHR AX, 1 (Shift AX right by 1 bit)
SAL Shift left (arithmetic shift left, same SAL AX, 1 (Shift AX left by 1 bit)
as SHL)
SAR Shift right (arithmetic shift right) SAR AX, 1 (Shift AX right by 1 bit,
preserve sign)
8. Interrupt Instructions
These instructions handle interrupts for hardware and software events.
IRET Return from interrupt IRET (Return from interrupt service routine)
31 | P a g e BSDVP ACADEMY
BSDVP ACADEMY
1. Pentium (Original) Features
The original Pentium processor, introduced in 1993, was the first to feature dual pipelines, a
key innovation that allowed it to execute two instructions per clock cycle. Here are some key
features:
Key Features of the Pentium Processor:
1. Dual-Pipelined Architecture:
o The original Pentium introduced superscalar architecture, allowing the
processor to execute two instructions simultaneously in parallel, effectively
increasing throughput.
o It had two execution units: one for integer operations and another for
floating-point operations.
2. Clock Speed:
o Initially available in clock speeds of 60 MHz, 66 MHz, and later higher speeds
(up to 200 MHz in some early models).
3. 32-bit Data Bus:
o The Pentium had a 32-bit data bus, meaning it could handle 32 bits of data at
a time, making it significantly faster than its predecessors (the 486 with a 32-
bit internal architecture but a 16-bit data bus).
4. 32-bit and 64-bit Support:
o The Pentium was designed to support 32-bit processing (addressing and
instructions). It could address up to 4 GB of memory, but the processor could
also handle some 64-bit operations for certain tasks, such as floating-point
calculations.
5. Floating-Point Unit (FPU):
o A dedicated FPU was included, which allowed for better performance in
handling complex mathematical computations (important for scientific,
engineering, and graphics applications).
6. MMX Technology:
o Some Pentium processors included MMX (Multimedia Extensions), a set of
instructions that enhanced performance for multimedia applications (audio,
video, and graphics). This allowed for more efficient multimedia data
processing.
32 | P a g e BSDVP ACADEMY
BSDVP ACADEMY
7. Cache Memory:
o The original Pentium supported 8 KB L1 cache to speed up access to
frequently used data, reducing the time it took to fetch information from the
main memory.
8. Pipeline Depth:
o The original Pentium processor had a 5-stage pipeline to break down the
execution of instructions into smaller stages, improving the throughput and
reducing delays between executing instructions.
2. Pentium MMX
Released in 1996, the Pentium MMX was an enhancement of the original Pentium,
specifically designed to improve performance in multimedia applications. MMX instructions
provided a significant boost for multimedia workloads.
Key Features of Pentium MMX:
1. MMX Technology:
o The MMX (Multimedia Extensions) instructions allowed the processor to
handle SIMD (Single Instruction, Multiple Data) operations, enabling faster
processing of multimedia data.
o This technology provided hardware acceleration for tasks such as image
processing, audio decoding, and 3D graphics rendering.
2. Improved Performance:
o Enhanced integer processing for multimedia tasks.
o Up to 32 MMX instructions were added to the Pentium, including operations
for video compression, audio manipulation, and graphic rendering.
3. Increased Clock Speeds:
o The Pentium MMX was available in higher clock speeds (up to 233 MHz),
offering a performance boost for certain types of applications.
3. Pentium Pro
Introduced in 1995, the Pentium Pro was aimed at the high-performance workstation and
server markets. It featured an advanced superscalar architecture and out-of-order
execution, which set it apart from the original Pentium.
33 | P a g e BSDVP ACADEMY
BSDVP ACADEMY
Key Features of Pentium Pro:
1. Advanced Superscalar Architecture:
o The Pentium Pro was designed to execute multiple instructions per clock
cycle. It had dual pipelines and could execute instructions in out-of-order
execution to optimize performance.
2. Out-of-Order Execution:
o The Pentium Pro could execute instructions out of order based on the
availability of resources, which helped improve performance by filling idle
execution units.
3. Enhanced L2 Cache:
o The Pentium Pro supported an external L2 cache (256 KB to 1 MB), which
greatly improved performance in tasks that required frequent access to
memory.
4. 64-bit Addressing:
o Although it was marketed as a 32-bit processor, the Pentium Pro had 64-bit
internal registers, allowing it to process 64-bit data internally, making it more
powerful for certain scientific and engineering applications.
4. Pentium II
The Pentium II, launched in 1997, was a significant advancement, especially in terms of
multimedia performance, and it was based on the Pentium Pro core with improvements to
meet the needs of the consumer market.
Key Features of Pentium II:
1. Slot 1 Design:
o Unlike its predecessors, the Pentium II used the Slot 1 interface, which
allowed for easy installation on motherboards, with a separate slot for the
processor and cache.
2. MMX Technology:
o Included MMX technology for multimedia performance, improving tasks like
video encoding and decoding.
3. Multimedia Instructions:
o Introduced SIMD instructions for better graphics, 3D rendering, and
multimedia applications.
34 | P a g e BSDVP ACADEMY
BSDVP ACADEMY
4. L2 Cache:
o Integrated 512 KB to 1 MB of L2 cache on the processor, providing faster
access to data for applications.
5. Higher Clock Speeds:
o The Pentium II reached up to 450 MHz in later stages, offering better overall
performance compared to its predecessors.
5. Pentium III
The Pentium III processor, released in 1999, brought further improvements in performance,
especially in terms of speed, multimedia capabilities, and the use of advanced technologies.
Key Features of Pentium III:
1. SSE (Streaming SIMD Extensions):
o Introduced the SSE instruction set, which provided hardware acceleration for
multimedia and 3D graphics.
o SSE was a key improvement over MMX, offering improved floating-point
performance for multimedia applications.
2. Clock Speeds:
o The Pentium III was available in speeds ranging from 450 MHz to 1.4 GHz,
making it one of the faster processors of its time.
3. Improved Cache:
o The Pentium III included an integrated L2 cache of up to 512 KB for better
performance.
4. Internet Streaming and Multimedia:
o The Pentium III was optimized for streaming media, making it ideal for
internet applications and rich multimedia content.
6. Pentium 4
The Pentium 4, released in 2000, was designed with higher clock speeds and larger caches,
making it suitable for performance-intensive tasks.
35 | P a g e BSDVP ACADEMY
BSDVP ACADEMY
Key Features of Pentium 4:
1. NetBurst Microarchitecture:
o The Pentium 4 was based on the NetBurst microarchitecture, which was
designed to achieve high clock speeds (up to 3.8 GHz and beyond) for better
performance.
2. Hyper-Threading Technology:
o Introduced Hyper-Threading (HT), which allowed each core to execute two
threads simultaneously, improving the processor's efficiency in multitasking
environments.
3. L2 Cache:
o The Pentium 4 featured 256 KB to 1 MB of L2 cache for faster access to
frequently used data.
4. Enhanced Multimedia Performance:
o The Pentium 4 also included SSE2 instructions for better performance in
multimedia, floating-point operations, and 3D rendering.
7. Pentium D
The Pentium D series, launched in 2005, marked the introduction of dual-core processors to
the Pentium line, providing substantial improvements in multitasking and parallel
processing.
Key Features of Pentium D:
1. Dual-Core Architecture:
o The Pentium D featured two cores on a single chip, each capable of executing
instructions independently, significantly improving multitasking performance.
2. Enhanced Performance:
o The dual-core architecture, along with Hyper-Threading, allowed for better
performance in parallel processing tasks and multitasking.
3. L2 Cache:
o The Pentium D processors included up to 2 MB L2 cache per core for faster
data access.
36 | P a g e BSDVP ACADEMY
BSDVP ACADEMY
ONE APP TO LEARN EVERYTHING!
Looking for the ultimate learning companion? Look no further! BSDVP Academy is your go-to
app for all your educational needs!
Download BSDVP Academy NOW from the Google Play Store and unlock a world of
knowledge at your fingertips!
Key Features:
Download now and take the first step towards a smarter future!
BSDVP Academy
Android App– [Link]
Apple Iphone App- [Link]
37 | P a g e BSDVP ACADEMY