Skip to main content
  1. Resources/
  2. Study Materials/
  3. Electronics & Communication Engineering/
  4. ECE Semester 4/
  5. Microprocessor & Microcontroller (4341101)/

Microprocessor and Microcontroller (1333202) - Winter 2023 Solution

41 mins· ·
Study-Material Solutions Microprocessor 1333202 2023 Winter
Milav Dabgar
Author
Milav Dabgar
Experienced lecturer in the electrical and electronic manufacturing industry. Skilled in Embedded Systems, Image Processing, Data Science, MATLAB, Python, STM32. Strong education professional with a Master’s degree in Communication Systems Engineering from L.D. College of Engineering - Ahmedabad.
Table of Contents

Q1a: Define Microprocessor.
#

Definition of a Microprocessor

A microprocessor is a single integrated circuit (IC) that incorporates the core functions of a computer’s central processing unit (CPU).

  • Key Points:

    • The “Brain” of a Computer: It executes instructions, performs calculations, and manages the flow of data within a computer system.
    • Small and Powerful: Microprocessors pack millions or even billions of transistors into a tiny chip, enabling complex processing in compact devices.
    • Essential for Modern Devices: They power a vast range of devices from smartphones and laptops to cars, appliances, and industrial equipment.
    • Components: Typical components of a microprocessor include:
      • Arithmetic Logic Unit (ALU) - Performs arithmetic and logical operations
      • Control Unit (CU) - Decodes instructions and coordinates the operations of other units
      • Registers - Small, high-speed memory locations for temporary data storage

Q1b: Explain Flag register of 8085 microprocessor.
#

The Flag Register

The Flag register in the 8085 is an 8-bit register, with only 5 bits actively used as flags. These flags act as individual flip-flops that are set (1) or reset (0) to reflect specific conditions arising from arithmetic, logical, and other operations performed by the ALU (Arithmetic and Logic Unit).

The 5 Flags:

  1. Sign Flag (S):

    • Set (1) if the result of an operation is negative (the Most Significant Bit, or MSB, of the result is 1).
    • Reset (0) if the result is positive.
  2. Zero Flag (Z):

    • Set (1) if the result of an operation is zero.
    • Reset (0) if the result is not zero.
  3. Auxiliary Carry Flag (AC):

    • Set (1) if there is a carry-out from the lower nibble (lower 4 bits) into the upper nibble (upper 4 bits) of a result.
    • Used primarily in instructions that perform decimal arithmetic.
  4. Parity Flag (P):

    • Set (1) if the result has even parity (contains an even number of 1s).
    • Reset (0) if the result has odd parity.
  5. Carry Flag (CY):

    • Set (1) if there is a carry-out from the most significant bit (MSB) of a result during addition, or a borrow during subtraction.
    • Reset (0) otherwise.

How the Flags are Used:

  • Conditional Jumps: Instructions like JZ (Jump if Zero), JNZ (Jump if Not Zero), JC (Jump if Carry), etc. use the status of these flags to determine whether to branch to different parts of the program.
  • Decision Making: The processor can examine flag states to modify calculations or behaviors based on previous operations.

Example:

; Assume the accumulator (A) holds the value 50
SUB B  ; Subtract the value in register B from the accumulator
JZ LABEL  ; If the result is zero, jump to the code section marked as LABEL

Q1c: Explain format of instruction of 8085 microprocessor with example.
#

8085 Instruction Formats

Instructions in the 8085 microprocessor can be 1, 2, or 3 bytes long. The structure varies depending on the specific instruction and the addressing modes used.

General Structure

  • Opcode (Operation Code): The first byte of an instruction. It specifies the operation to be performed (e.g., MOV, ADD, JMP).

  • Operands (Optional): The second and third bytes, if present, provide data or addresses required by the operation. Operands can be:

    • Registers: 8-bit registers within the 8085 (B, C, D, E, H, L, or the accumulator A).
    • Immediate Data: 8-bit or 16-bit data embedded directly into the instruction.
    • Memory Addresses: 16-bit addresses of memory locations.

8085 Instruction Examples

  1. Single-Byte Instruction (No Operands):

    • Instruction: NOP (No Operation)
    • Opcode: 00000000
    • Explanation: Does nothing - the processor simply moves to the next instruction.
  2. Two-Byte Instruction (Immediate Data):

    • Instruction: MVI A, 42H (Move Immediate to Accumulator)
    • Opcode: 00111110
    • Operand: 42H (Hexadecimal value to be loaded)
    • Explanation: Loads the value 42H into the accumulator.
  3. Three-Byte Instruction (16-bit Memory Address):

    • Instruction: LDA 2050H (Load Accumulator Direct)
    • Opcode: 00111010
    • Operand: 2050H (16-bit memory address)
    • Explanation: Loads the content of the memory location at address 2050H into the accumulator.

Addressing Modes

The way operands are specified determines the “addressing mode” of the instruction. The 8085 supports modes like:

  • Register addressing: The operand is a register.
  • Direct addressing: The operand is a 16-bit memory address.
  • Immediate addressing: The operand is data within the instruction.
  • Register indirect addressing: The operand’s address is held within a register pair.

Remember:

  • The specific format depends on the instruction and the addressing mode used.
  • Opcodes and addressing modes are how the 8085 interprets the bytes that make up an instruction.

Q1c: Explain function of ALU, Control Unit and CPU of 8085 microprocessor.
#

1. ALU (Arithmetic Logic Unit)

  • Heart of Calculations: The ALU performs the core arithmetic and logical operations within the microprocessor.
  • Operations:
    • Arithmetic: Addition, subtraction, increment, decrement, etc.
    • Logical: AND, OR, XOR, NOT, comparisons, etc.
  • Flags: Sets status flags (Carry, Zero, Sign, Parity) based on the results of its operations. These flags are used for conditional branching and decision-making by the processor.

2. Control Unit

  • The Orchestrator: Governs the overall operation of the microprocessor.
  • Key Functions:
    • Instruction Decoding: Interprets the opcode of the current instruction fetched from memory.
    • Control Signal Generation: Produces control signals that synchronize and manage the actions of all other units within the microprocessor (ALU, registers, memory interface, etc.).
    • Data Flow Management: Coordinates the movement of data between the ALU, registers, and memory/I/O devices.

3. CPU (Central Processing Unit)

  • The Brain of the System: The CPU is the combination of the ALU and the Control Unit.
  • Responsibilities:
    • Instruction Execution: Fetches instructions from memory, decodes them using the control unit, and executes them using the ALU and other components.
    • Program Control: Manages the flow of instructions within a program, including branching and jumps based on conditions.
    • System Management: Handles communication with external devices and responds to interrupts.

How They Work Together

  1. The Control Unit fetches an instruction from memory.
  2. The Control Unit decodes the instruction and generates the necessary control signals.
  3. The ALU, if needed, performs the required arithmetic or logical operation.
  4. Results may be stored in registers, written to memory, or sent to output devices.
  5. The Control Unit directs the processor to fetch the next instruction, continuing the cycle.

Q2a: Explain function of ALE signal with diagram.
#

What is the ALE Signal?

  • The ALE signal is a control signal generated by the 8085 microprocessor.
  • It is a positive-going pulse that occurs during the first clock cycle (T1 state) of each machine cycle.

Purpose of the ALE Signal

The primary function of the ALE signal is to demultiplex the lower-order address/data bus (AD0-AD7). This bus is shared (multiplexed) to carry both:

  1. Lower 8-bits of the Address (during T1 state): The 8085 needs to send out the 16-bit address of a memory location or I/O port. The lower 8 bits of the address are carried on lines AD0-AD7.
  2. Data (during subsequent states): The same lines are used to transmit or receive actual data to/from the memory or I/O device.

How ALE Demultiplexes the Bus

  1. T1 State:

    • The ALE signal goes high.
    • The 8085 places the lower 8 bits of the address on lines AD0-AD7.
    • An external latch (usually an 8282 or 8283 octal latch) connected to these lines “latches” or captures this address information.
  2. Subsequent States (T2, T3, …):

    • ALE goes low.
    • The lower-order address lines (AD0-AD7) are now free to be used as a data bus for transferring data.

Diagram

A simple timing diagram can help visualize this:

          ______         ______
ALE      |      |_______|      |______
          _____           _____
AD0-AD7  |Addr |_______| Data |________
         (T1)      (T2, T3, ...)

Key Points:

  • The ALE signal is crucial for the 8085 to correctly interface with memory and I/O devices.
  • The external latch holds the lower order address bits, freeing the 8085 to continue its fetch or write operation.

Q2b: Compare microprocessor and microcontroller
#

FeatureMicroprocessorMicrocontroller
ComplexityLess complexMore complex
Instruction SetLarger and more versatileSmaller and more application-specific
MemoryRequires external memory (RAM, ROM)Has built-in memory (RAM, ROM, Flash)
PeripheralsRequires external peripherals (e.g., display, I/O)Has built-in peripherals (e.g., timers, ADCs, DACs)
CostGenerally lower costGenerally higher cost
ApplicationsGeneral-purpose computingEmbedded systems, specific tasks
ExamplesIntel 8085, Intel x86Atmel AVR, PIC, ARM Cortex-M

Q2c: Draw & explain block diagram of 8085 microprocessor.
#

Block Diagram

Block Diagram of 8085

Key Components and their Functions

  1. Accumulator: An 8-bit register that’s central to arithmetic and logical operations performed by the ALU.

  2. Arithmetic and Logic Unit (ALU): Performs arithmetic operations (addition, subtraction, etc.) and logical operations (AND, OR, NOT, etc.). It sets flags (Carry, Zero, Sign, etc.) based on the results.

  3. Temporary Register: A temporary holding location for data used during instruction execution.

  4. Instruction Register: Holds the currently fetched instruction.

  5. Instruction Decoder and Machine Cycle Encoder: Decodes the instruction in the instruction register and generates control signals to coordinate the microprocessor’s actions during a machine cycle.

  6. Register Array: Contains six general purpose 8-bit registers (B, C, D, E, H, and L), which can be used individually or in pairs (BC, DE, HL) for 16-bit operations.

  7. Program Counter (PC): A 16-bit register that holds the memory address of the next instruction to be fetched.

  8. Stack Pointer (SP): A 16-bit register pointing to the top of the stack in memory. The stack is used for storing return addresses of subroutines and temporarily storing data.

  9. Timing and Control Unit: Generates timing and control signals for all operations within the microprocessor and synchronizes with external devices.

  10. Interrupt Control: Handles incoming interrupt requests (if any), acknowledging them and allowing them to temporarily disrupt the current program execution.

  11. Serial I/O Control: Facilitates serial input and output, useful for slower communication with certain types of peripherals.

  12. Address Bus (A8 - A15): The upper 8-bits of the 16-bit address bus, used to send the most significant portion of an address.

  13. Address/Data Bus (AD0 - AD7): A multiplexed bus. It carries the lower 8 bits of an address during the beginning of a machine cycle and data during data transfer operations.

How it Works (Simplified)

  1. Fetch: The PC provides an address; the instruction is fetched from memory and placed into the Instruction Register.
  2. Decode: The Instruction Decoder decodes the instruction to understand what needs to be done.
  3. Execute: The Control Unit generates signals to coordinate the ALU, registers, and other components as they perform the necessary operations.
  4. Repeat: The process continues, fetching and executing instructions sequentially.

Q2a: Explain 16 bits registers of 8085 microprocessor.
#

16-Bit Registers in the 8085

The 8085 microprocessor, while primarily an 8-bit processor, features several 16-bit registers that are crucial for memory addressing and specific operations:

  • Program Counter (PC):

    • Holds the 16-bit memory address of the next instruction to be fetched and executed by the processor.
    • Essential for maintaining the correct sequence of program execution.
  • Stack Pointer (SP):

    • Points to the current top of the stack in memory.
    • The stack is a Last-In, First-Out (LIFO) data structure used for storing return addresses during subroutine calls, temporary data, and interrupt handling.
  • Register Pairs (BC, DE, HL):

    • While B, C, D, E, H, and L are individual 8-bit registers, they can be paired together to form 16-bit registers:
      • BC
      • DE
      • HL
    • These register pairs allow for operations on 16-bit data and for holding 16-bit memory addresses.

Key Functions of 16-bit Registers

  1. Memory Addressing: The 8085 has a 16-bit address bus, meaning it can address up to 64KB of memory. The 16-bit registers are used to store and manipulate memory addresses for data storage and retrieval.

  2. Subroutine Calls and Returns: When a subroutine is called (using instructions like CALL), the processor needs to store the address where it should return to after the subroutine is finished. The Program Counter is pushed onto the stack for safekeeping.

  3. Data Manipulation: Some instructions treat these register pairs as a single unit for performing 16-bit operations (e.g., addition, loading immediate 16-bit values).

Q2b: Explain de-multiplexing lower order address and data lines with diagram of 8085 microprocessor.
#

Why Demultiplexing is Needed

The Intel 8085 utilizes a multiplexed address/data bus to reduce the number of pins required. The lower 8 lines (AD0-AD7) carry two types of information:

  1. Address (during T1 state): During the first clock cycle of a machine cycle, these lines hold the lower 8 bits of a 16-bit memory or I/O address.

  2. Data (during subsequent states): In the remaining clock cycles, those same lines transmit or receive the actual data being sent to or from a memory location or I/O device.

Demultiplexing Process

Demultiplexing is the process of separating the address and data information so the 8085 and external devices can operate correctly. Here’s how it’s achieved:

  1. The ALE Signal: During the first clock cycle (T1), the 8085 asserts the ALE (Address Latch Enable) control signal. This signal goes high.

  2. External Latch: An external latch circuit (e.g., 8282 or 74LS373 octal latch) is connected to the AD0-AD7 lines. When the ALE signal goes high, this latch captures and holds the lower 8 bits of the address.

  3. Address Decoded: The latched lower-order address bits, along with the higher-order address bits (A8-A15), provide the complete 16-bit address for memory or I/O devices.

  4. Data Bus Freed: After the T1 state, the ALE signal goes low. The AD0-AD7 lines are now free to be used as a data bus for the remainder of the machine cycle.

Diagram

Demultiplexing of Lower Order Address Bus & Data Bus

Key Points

  • Demultiplexing enables the 8085 to interface with memory and I/O devices correctly by separating the address and data functions of the same physical bus lines.
  • The ALE signal plays a crucial role in timing the latching of address information.

Q2c: Draw and explain pin diagram of 8085.
#

Pin Diagram

8085 microprocessor pin diagram

Explanation of Pin Groups

  1. Address Bus (A8-A15): The upper 8-bits of the 16-bit address bus used for addressing memory and I/O devices.

  2. Multiplexed Address/Data Bus (AD0-AD7): These pins serve two functions:

    • During the first clock state (T1), they carry the lower 8-bits of the address.
    • During subsequent clock states, they serve as the data bus for data transfer.
  3. Control and Status Signals

    • ALE (Address Latch Enable): Indicates that the AD0-AD7 lines contain a valid address.
    • RD (Read): Indicates a read operation from memory or I/O.
    • WR (Write): Indicates a write operation to memory or I/O.
    • IO/M (IO/Memory Select): Distinguishes between memory (IO/M = 0) and I/O (IO/M = 1) operations.
    • S0, S1 (Status signals): These, along with IO/M, indicate the type of machine cycle (opcode fetch, memory read, I/O write, etc.).
  4. Power Supply and Clock

    • VCC: +5V power supply.
    • VSS: Ground (0V).
    • X1, X2: Connections for a crystal or external clock source to drive the internal clock generator.
    • CLK (OUT): Clock output signal for synchronizing external devices.
  5. Interrupts

    • TRAP: Highest priority non-maskable interrupt.
    • RST 7.5, RST 6.5, RST 5.5: Maskable interrupts with decreasing priority.
    • INTR: General maskable interrupt.
    • INTA: Interrupt acknowledge signal sent by the 8085.
  6. Serial I/O

    • SID (Serial Input Data): Input line for serial data.
    • SOD (Serial Output Data): Output line for serial data.
  7. Reset

    • RESET IN: When low, resets the microprocessor, clearing the program counter and registers.
    • RESET OUT: Indicates that the microprocessor is being reset.
  8. DMA (Direct Memory Access)

    • HOLD: Input from a DMA device to request control of buses.
    • HLDA: Acknowledge signal, indicating the 8085 has relinquished control of buses.

Q3a: Draw clock and reset circuit of 8051 microcontroller.
#

Absolutely! Let’s break down the clock and reset circuit of a typical 8051 microcontroller.

Clock Circuit

  • Crystal Oscillator: The foundation of the timing for the 8051 is a crystal oscillator connected to the XTAL1 and XTAL2 pins of the microcontroller.

    • The crystal, along with small capacitors (usually in the 20-30pF range), provides a stable and precise clock frequency.
    • Common crystal frequencies for 8051 systems are 11.0592 MHz or 12 MHz.
  • Internal Clock Generation: The 8051 has an internal clock generator that takes the external crystal oscillator’s signal and divides it down. This ensures that the microcontroller and its various components operate at the correct internal clock speed.

Diagram

clock-circuit

Reset Circuit

  • RC Network: A simple resistor-capacitor (RC) network is often used for the reset circuit.

    • When power is first applied, the capacitor begins to charge. This holds the RESET pin low for a short period, guaranteeing the 8051 starts in a known state.
    • Once the capacitor voltage reaches a threshold, the RESET pin goes high, allowing the microcontroller to begin executing code.
  • Supervisory Circuit (Optional): For more robust reset control, a dedicated supervisory circuit/IC provides more precise monitoring of the power supply voltage. This ensures reliable resets if the power supply fluctuates or becomes unstable.

Diagram

reset-circuit

Explanation

  1. Power On: When the system powers on, the capacitor of the reset circuit is initially discharged, holding the RESET pin low.
  2. Reset: This low level on the RESET pin forces the 8051 microcontroller into a reset state. Internal registers are cleared, and the Program Counter begins at address 0000H.
  3. Capacitor Charging: The capacitor in the reset circuit starts charging through the resistor.
  4. Reset Released: Once the capacitor charges beyond the RESET pin’s threshold voltage, the pin goes high. The 8051 starts executing code from the beginning of its program memory.
  5. Clock Stabilization: While the reset circuit is active, the crystal oscillator begins to oscillate and the clock stabilizes. The 8051’s internal clock generator uses this signal to provide the necessary timing for the microcontroller’s operation.

Key Points

  • The clock and reset circuits are essential for the correct initialization and operation of an 8051 microcontroller system.
  • Simple and inexpensive reset circuits can be designed using just a capacitor and resistor.
  • Supervisory circuits offer improved power monitoring and enhanced reset reliability.

Q3b: Explain internal RAM of 8051.
#

Internal RAM Organization

The 8051 family of microcontrollers typically includes 128 bytes of internal RAM, although some derivatives like the 8052 offer an extended 256 bytes. This internal RAM is organized into several distinct sections:

  1. Register Banks (00H - 1FH):

    • Four banks of eight general-purpose registers (R0-R7).
    • Each bank can be selected using two bits in the Program Status Word (PSW) register.
    • Used for storing temporary data and intermediate results during calculations.
  2. Bit-Addressable Area (20H to 2FH):

    • 16 bytes of RAM where each bit can be individually addressed (128 individual bits in total).
    • Useful for storing single-bit variables (like flags or control signals).
  3. General Purpose RAM (30H - 7FH):

    • The remaining 80 bytes of general-purpose RAM.
    • Used for variable storage, temporary data, and even as a small stack if needed.

Key Points

  • Speed: Internal RAM is extremely fast to access compared to external RAM, as it’s located directly on the microcontroller chip.
  • Limited Size: The internal RAM in 8051 is limited. Programs with larger data requirements often need external RAM.
  • Flexibility: The bit-addressable area provides fine-grained control over individual bits, ideal for control and status flags.

How Internal RAM Is Used

  • Arithmetic and Logical Operations: The register banks are heavily used by the ALU for arithmetic and logical operations.
  • Temporary Storage: All sections of the internal RAM can be used for temporarily storing data during calculation or program execution.
  • Stack: Although the 8051 has a dedicated hardware stack, the general-purpose RAM can also be used as a stack area in constrained situations.
  • Flags and Control: The bit-addressable area often houses individual control flags and status bits for the 8051 or its peripherals.

Example

MOV R1, #50H  ; Move the value 50H into register R1
ADD A, R1     ; Add the value in R1 to the accumulator
MOV 35H, A    ; Store the result in general-purpose RAM location 35H
SETB PSW.2    ; Set bit 2 (Carry flag) in the Program Status Word

Q3c: Explain block diagram of 8051.
#

Detailed Block Diagram Breakdown

Simplified 8051 Block Diagram

Central Processing Unit (CPU)

  • Accumulator: A core 8-bit register involved in most arithmetic and logical operations with the ALU.
  • B Register: A temporary register that can be used for multiplication, division, or as extra data storage.
  • Program Status Word (PSW): Holds important status flags like Carry, Overflow, Parity, and register bank selection bits.
  • Stack Pointer (SP): An 8-bit register pointing to the current top of the stack in RAM.
  • Program Counter (PC): 16-bit register keeping track of the memory address of the next instruction to be fetched.
  • Instruction Register: Holds the currently fetched instruction.
  • Instruction Decoder: Decodes the instruction in the instruction register, generating control signals that orchestrate what happens within the other blocks.
  • Timing and Control: Governs the fetch-decode-execute cycle of the CPU, synchronizes actions, and interfaces with external signals.

Memory

  • Internal RAM (128 bytes):
    • Register Banks 0-3: Four sets of eight 8-bit general-purpose registers (R0-R7).
    • Bit-addressable area (20h-2Fh): 16 bytes with individually addressable bits.
    • General-purpose area (30h-7Fh): Remaining 80 bytes of RAM for data and variables.
  • Internal ROM (typically 4KB): Non-volatile memory for storing the 8051’s program code.

Input/Output (I/O)

  • Ports 0 through 3 (P0 - P3): Four bi-directional 8-bit I/O ports that can be individually configured as input or output.

Timers/Counters

  • Timer/Counter 0 and 1 (T0, T1): 16-bit timers/counters with various modes of operation (counting external events, generating time intervals, etc.).

Serial Port (UART)

  • TXD: Transmit Data: The line used for sending serial data out from the 8051.
  • RXD: Receive Data: The line used for receiving serial data into the 8051.
  • SBUF: Serial Data Buffer: A temporary register for holding data during serial transmission or reception.

Interrupts

  • External Interrupts (INT0, INT1): Triggered by signals on external pins.
  • Timer Interrupts (TF0, TF1): Triggered when the timers/counters overflow or reach a specific value.
  • Serial Interrupt (RI, TI): Triggered by events related to UART transmission/reception.
  • Interrupt Control Logic: Handles enabling/disabling, prioritizing, and managing these interrupts.

Additional Notes

  • Bus Structure: Notice the internal data bus that connects the CPU, memory, and I/O blocks. Instructions and data flow along this bus under the control of the CPU.
  • Reset: The RESET input initializes the 8051, setting registers and the Program Counter to their starting states.
  • Oscillator: The XTAL1 and XTAL2 inputs are for connecting the crystal and other components that form the clock circuit for the microcontroller.

Q3a: Explain different timer modes of 8051 microcontroller.
#

Mode 0: 13-Bit Timer

  • Configuration: The timer register is split into two parts:
    • Five high-order bits (THx)
    • Eight low-order bits (TLx), with the top 3 bits of TLx written as zeroes.
  • Operation: The 5 bits of TLx are automatically incremented. When TLx overflows, it increments THx. This forms a 13-bit timer.
  • Use Cases: Often used for event counting or generating baud rates in serial communication, particularly when interfacing with legacy systems.

Mode 1: 16-Bit Timer

  • Configuration: The full 16-bits of the Timer register (THx and TLx) function as a single timer unit.
  • Operation: Each clock pulse increments the entire register.
  • Use Cases General-purpose time delays, long interval measurements, anything requiring 16-bit precision timing.

Mode 2: 8-Bit Auto-Reload Timer

  • Configuration:
    • THx holds a fixed reload value.
    • TLx operates as the 8-bit timer.
  • Operation:
    • TLx counts up. When it overflows, it’s automatically reloaded with the value stored in THx.
    • This creates a recurring time interval.
  • Use Cases: Generating fixed, predictable time delays or timing periodic events.

Mode 3: Split 8-bit Timers

  • Configuration:
    • Timer 0 is split into two independent 8-bit timers/counters: TL0 and TH0.
    • Timer 1 remains as a 16-bit timer if needed.
  • Operation:
    • TL0 and TH0 function as two separate timers, often with TL0 used as a timer and TH0 used as a counter.
  • Use Cases:
    • Situations requiring two independent timers
    • Generating baud rates (TL0) while counting external events (TH0)

Key Control Registers

  • TMOD (Timer Mode): This register selects the operating mode for Timer 0 and Timer 1.
  • TCON (Timer Control): Contains flags and start/stop control bits for the timers.

How to Select a Mode

Mode selection depends on:

  • Timing Precision: 16-bit vs. 8-bit
  • Recurring Intervals: Auto-reload mode vs. manual restart.
  • Number of Timers Needed: Split timer mode provides two independent 8-bit timers if needed within Timer 0.

Q3b: Explain function of DPTR and PC.
#

DPTR (Data Pointer)

  • Type: 16-bit register, often visualized as two conjoined 8-bit registers DPH (Higher Byte) and DPL (Lower Byte).
  • Primary Function: Pointing to memory locations within the 8051’s data memory space. This includes both the internal and external RAM.

Key Uses of DPTR

  1. Accessing External Memory: The 8051 can access up to 64KB of external data memory. The DPTR holds the address when instructions like these are used:

    • MOVX A,@DPTR (Read a byte from external RAM pointed to by DPTR)
    • MOVX @DPTR,A (Write a byte to external RAM pointed to by DPTR)
  2. Lookup Tables and Buffers: DPTR can be used to conveniently access data stored within tables or buffers located in memory. You can change the value in DPTR to point to different areas of these data structures.

  3. Passing Parameters: If a function or subroutine requires data stored in memory, the memory address can be passed using the DPTR register.

PC (Program Counter)

  • Type: 16-bit Register
  • Primary Function: Keeping track of the memory address of the next instruction to be executed by the 8051’s CPU.

How PC Works

  1. Fetch: The PC provides the address from which the next instruction is fetched from program memory (ROM).

  2. Increment: After the instruction is fetched, the PC is automatically incremented to point to the next sequential instruction, ensuring instructions are normally executed in order.

  3. Modifiying Program Flow: Instructions like jumps, calls, and returns alter the value in the PC, changing the execution flow of the program.

Key Points

  • DPTR is primarily for data; PC is for code: DPTR is designed for accessing data in memory, while PC is for tracking instructions in the program memory.
  • PC mostly automatic; DPTR is programmer-controlled: The PC increments automatically with regular program execution, while the programmer generally controls and sets the value in DPTR.

Q3c: Explain interrupts of 8051 microcontroller.
#

What is an Interrupt?

  • An interrupt is an event that temporarily suspends the normal execution of a program and forces the 8051 to execute a special routine called an Interrupt Service Routine (ISR).
  • Interrupts allow the microcontroller to respond quickly to important events (e.g., button presses, timer overflow, data received) without needing to constantly poll for them in the main code.

Types of Interrupts in the 8051

  1. External Interrupts:

    • INT0 (Pin P3.2): Triggered by a low-to-high transition on the INT0 pin.
    • INT1 (Pin P3.3): Triggered by a low-to-high transition on the INT1 pin.
  2. Timer Interrupts:

    • TF0 (Timer 0 Overflow): Triggered when Timer 0 overflows.
    • TF1 (Timer 1 Overflow): Triggered when Timer 1 overflows.
  3. Serial Interrupt:

    • RI/TI (Receive Interrupt/Transmit Interrupt): Triggered when the serial port finishes receiving a byte (RI) or transmitting a byte (TI).

Interrupt Process

  1. Trigger: An interrupt source (external pin, timer overflow, etc.) is triggered.
  2. Completion of Current Instruction: The 8051 completes executing its current instruction.
  3. Saving State: The microcontroller automatically pushes the current Program Counter (PC) onto the stack.
  4. Jump to ISR: The 8051 jumps to the pre-determined memory address of the corresponding Interrupt Service Routine (ISR).
  5. ISR Execution: The ISR code executes, handling the event that triggered the interrupt.
  6. Returning: After the ISR completes, a ‘RETI’ instruction pops the PC value from the stack, resuming the original program flow.

Interrupt Control Registers

  • IE (Interrupt Enable): Enables or disables specific interrupts globally and individually within the system.
  • IP (Interrupt Priority): Assigns priority levels to each interrupt source. If multiple interrupts occur simultaneously, the one with higher priority is serviced first.

Key Points

  • Priority: The 8051 has a fixed interrupt priority structure (e.g., INT0 has the highest priority).
  • Masking: Interrupts can be turned on or off selectively using the IE register.
  • Nesting: Interrupts can potentially interrupt other interrupts, depending on their priority.

Example

Imagine an 8051 system monitoring a sensor. A timer interrupt might trigger periodically to read the sensor value, while an external interrupt could signal a critical threshold being exceeded, requiring immediate action.

Q4a: Explain data transfer instruction with example for 8051.
#

Data Transfer Instructions in the 8051

These instructions move data between various registers, internal RAM, external RAM, and I/O ports of the 8051. Here’s a breakdown of the key types:

1. Register-to-Register Transfers

  • MOV instruction: The most versatile data transfer instruction.
  • Examples:
    • MOV A, R5 - Copies the contents of register R5 into the accumulator.
    • MOV R2, #45H - Loads the immediate value 45H into register R2.
    • MOV P1, A - Copies the accumulator’s contents to port P1 (output).

2. Direct Addressing

  • MOV instruction with ‘direct’ addressing mode: Accesses internal RAM or Special Function Registers (SFRs).
  • Examples:
    • MOV 50H, A - Stores the value in the accumulator to internal RAM location 50H.
    • MOV ACC, 55H - Loads the byte from internal RAM location 55H into the accumulator.
    • MOV TMOD, #01H - Sets Timer 0 into mode 1.

3. Indirect Addressing

  • MOV instruction using registers as pointers: The register holds the address of the data.
  • Examples:
    • MOV A, @R0 - Copies the byte pointed to by register R0 into the accumulator.
    • MOV @R1, 33H - Stores the value 33H at the address pointed to by R1.

4. External Memory Transfers

  • MOVX instruction: Used to access external RAM.
  • Examples:
    • MOVX A, @DPTR – Copies a byte from external RAM (address in DPTR) into the accumulator.
    • MOVX @DPTR, A – Copies the contents of the accumulator into external RAM (address in DPTR).

5. Special Data Transfers

  • PUSH instruction: Pushes data onto the stack (internal RAM).
  • POP instruction: Pops data off the stack.

Example: Data Sorting Routine

Consider a simple routine to sort three numbers stored at internal RAM locations 40H, 41H, and 42H:

COMPARE: MOV A, 40H    ; Load the first number
         MOVC A, @A+DPTR ; Load the second number (assuming DPTR points to RAM)
         JC  SWAP        ; Jump to SWAP if the first is greater than the second

         MOV A, 41H     ; Load the second number
         MOVC A, @A+DPTR ; Load the third number
         JC  SWAP        ; Jump to SWAP if the second is greater than the third
         ; ... (rest of your code)

SWAP:    ; ... (Code to swap values)

Q4b: List and explain different addressing modes of 8051 microcontroller.
#

Key Addressing Modes in the 8051

  1. Register Addressing

    • How it Works: The operand of the instruction directly specifies one of the 8051’s registers (A, B, R0-R7).
    • Example: MOV A, R2 (Copy the contents of R2 into the accumulator)
    • Fast and Efficient: No additional memory accesses are needed.
  2. Direct Addressing

    • How it Works: The instruction contains an 8-bit address that directly points to a location in the internal RAM or Special Function Registers (SFRs).
    • Example: MOV 45H, A (Store the value in the accumulator into internal RAM location 45H)
    • Accesses only first 256 bytes: Limited to accessing the lower portion of internal RAM and SFRs.
  3. Indirect Addressing

    • How it Works: The instruction specifies a register (R0 or R1) that holds the memory address of where the data actually resides.
    • Example: MOV A, @R0 (Copy the byte pointed to by the address in R0 into the accumulator).
    • Flexibility: Allows dynamic calculation of data locations.
  4. Immediate Addressing

    • How it Works: The data to be used is embedded directly within the instruction itself. Preceded by the ‘#’ symbol.
    • Example: MOV A, #60H (Load the value 60H into the accumulator).
    • Convenient for constants: Useful for loading fixed values.
  5. Base Relative Addressing (with DPTR)

    • How it Works: Used for accessing external RAM. The Data Pointer (DPTR) provides a 16-bit base address, and an 8-bit offset within the instruction specifies a location relative to that base.
    • Example: MOVX A, @DPTR (Copy byte from external RAM pointed to by DPTR into the accumulator)
    • Expanded Memory: Access up to 64KB of external memory

Important Notes

  • Different instructions support different combinations of addressing modes.
  • The chosen addressing mode affects the instruction’s length and execution time.
  • Choosing the right addressing mode is a balance between flexibility and efficiency.

Q4c: Write a program to copy block of 8 data starting from location 100h to 200h.
#

Here’s an assembly program for the 8051 microcontroller to copy a block of 8 bytes of data from starting location 100H to destination location 200H:

ORG 0000H  ; Program starts at memory location 0000H

; Initialization
MOV DPTR, #100H   ; Set DPTR to point to the source block (100H)
MOV R0, #200H     ; Set R0 to point to the destination block (200H)
MOV R1, #08H      ; Set R1 as the loop counter (8 bytes to copy)

COPY_LOOP:
MOVX A, @DPTR   ; Read a byte from the source using DPTR
MOVX @R0, A     ; Write the byte to the destination using R0
INC DPTR        ; Increment DPTR to point to the next source byte
INC R0          ; Increment R0 to point to the next destination byte
DJNZ R1, COPY_LOOP ; Decrement R1 and jump if not zero

; End of Program (You can add more code here or an infinite loop)
END

Explanation

  1. ORG 0000H: This directive tells the assembler to place the code starting from memory location 0000H.

  2. Initialization:

    • We load the Data Pointer (DPTR) with the starting address of the source block (100H).
    • Register R0 is loaded with the starting address of the destination block (200H).
    • Register R1 is initialized to 8, which is the number of bytes we want to copy.
  3. COPY_LOOP:

    • MOVX A, @DPTR: Reads a byte from external RAM pointed to by DPTR and stores it in the accumulator.
    • MOVX @R0, A: Writes the byte from the accumulator to external RAM pointed to by R0.
    • INC DPTR, INC R0: Increment both DPTR and R0 to move to the next memory locations.
    • DJNZ R1, COPY_LOOP: Decrement R1 and jump back to the ‘COPY_LOOP’ label if R1 is not zero (meaning we haven’t copied all 8 bytes yet).
  4. END: Signifies the end of the assembly program.

Key Points

  • This assumes you have external RAM where you are storing the data.
  • You may need to adapt the addresses (100H and 200H) if your data is stored elsewhere.

Q4a: Write a program to add two bytes of data and store result in R0 register.
#

Here’s the 8051 assembly code to add two bytes of data and store the result in register R0:

; Data initialization - you might load these from memory in a real program
MOV A, #56H   ; Load the first byte of data into the accumulator
MOV B, #23H   ; Load the second byte of data into register B

; Addition
ADD A, B       ; Add the value in register B to the accumulator
MOV R0, A     ; Store the result (which is now in the accumulator) into R0

; End of program (you might do something with the result or add an infinite loop here)
END

Explanation

  1. Data Initialization:

    • MOV A, #56H: Loads the immediate value 56H (hexadecimal) into the accumulator (A register).
    • MOV B, #23H: Loads the immediate value 23H into register B.
  2. Addition:

    • ADD A, B: Adds the value in register B to the value in the accumulator. The result remains in the accumulator.
  3. Storing the Result:

    • MOV R0, A: Moves the value from the accumulator (which holds the sum) into register R0.

Important Points

  • You can replace the MOV instructions with ways to get data from other sources (memory, user input, etc.).
  • Make sure that the sum of your two data bytes can fit into 8 bits to avoid overflow.

Q4b: Explain indexed addressing mode with example.
#

What is Indexed Addressing Mode?

  • Combination: Indexed addressing mode combines the use of a base register and an offset to calculate the effective address of data.
    • Base Register: Can be either the Data Pointer (DPTR) or the Program Counter (PC).
    • Offset: The accumulator (A) holds the offset value.
  • Purpose: Primarily used to access elements within data structures like arrays or lookup tables located in program memory (ROM).

How Indexed Addressing Works

  1. The base register (DPTR or PC) is loaded with the starting address of the data structure (e.g., the array).
  2. The accumulator (A) is loaded with an offset indicating the position of a specific element relative to the base address.
  3. The effective address is calculated by adding the contents of the base register and the accumulator.
  4. The instruction accesses the data at this calculated effective address.

Example: Accessing an Array Element

Suppose you have an array of bytes stored in program memory starting at address 2000H. Here’s how to access the 5th element using indexed addressing:

MOV DPTR, #2000H  ; Load DPTR with the base address of the array
MOV A, #04H       ; Load offset (index 4, since arrays are zero-based)

; Accessing the 5th element (assuming you want to load it into the accumulator)
MOVC A, @A+DPTR   ; Calculate effective address and fetch the data

Explanation of the Example

  • MOV DPTR, #2000H: Sets the DPTR as the base register pointing to the beginning of the array.
  • MOV A, #04H: Loads accumulator with offset 4, indicating we want the 5th element (remember: zero-based indexing).
  • MOVC A, @A+DPTR:
    • The 8051 adds the offset in A (4) to the base address in DPTR (2000H), resulting in the effective address 2004H.
    • The ‘MOVC’ instruction fetches the byte from program memory location 2004H and loads it into the accumulator.

Key Points

  • Indexed addressing requires ROM access, so the source operand can only be program memory.
  • It makes sequentially accessing elements within arrays or tables convenient.

Q4c: Explain stack operation of 8051 microcontroller, PUSH and POP instruction.
#

The Stack in the 8051

  • Purpose: A Last-In, First-Out (LIFO) data structure residing in the internal RAM.
  • Stack Pointer (SP): A dedicated 8-bit register that always points to the current top of the stack.
  • Growth: The 8051 stack grows downward in memory. The SP is decremented when data is pushed, and incremented when data is popped.

PUSH Instruction

  1. Decrement Stack Pointer: The SP is decremented by one.
  2. Write Data: The byte to be pushed is written to the internal RAM location now pointed to by the SP.

Example:

MOV R5, #37H  ; Load the value 37H into register R5
PUSH R5       ; Push the contents of R5 onto the stack

POP Instruction

  1. Read Data: The byte pointed to by the SP is read from internal RAM.
  2. Increment Stack Pointer: The SP is incremented by one.

Example:

POP R6    ; Pop the top value from the stack into register R6

Common Uses of the Stack

  • Temporary Storage: Storing the contents of registers during calculations when there aren’t enough registers available.

  • Subroutine Calls: When a subroutine (function) is called using the ‘CALL’ instruction, the return address (next instruction after the call) is automatically pushed onto the stack. The ‘RET’ instruction pops this return address, so execution continues correctly.

  • Interrupt Handling: When an interrupt occurs, the 8051 automatically pushes the Program Counter (PC) onto the stack, allowing seamless return to the interrupted code after the interrupt service routine.

Important Points

  • Stack Size: The 8051’s internal RAM for the stack is limited; it’s crucial to prevent stack overflow.
  • Initialization: The SP is initialized to 07H when the 8051 resets; your code often needs to set it to a custom location.

Example: Swapping Two Numbers

MOV SP, #70H   ; Initialize Stack Pointer (assuming safe RAM space)

MOV A, #25H    ; Load the first number into the accumulator
PUSH A         ; Push the first number onto the stack

MOV A, #30H    ; Load the second number into the accumulator
PUSH A         ; Push the second number onto the stack

POP B         ; Pop the top (second) number into register B
POP A          ; Pop the original (first) number into the accumulator

Q5a: Explain branching instruction with example.
#

What are Branching Instructions?

Branching instructions, often also called jump instructions, allow you to alter the normal sequential flow of program execution. They cause the Program Counter (PC) to jump to a different memory location, breaking the usual ’execute the next instruction’ pattern.

Types of Branching Instructions

  1. Unconditional Branching

    • LJMP (Long Jump): Jumps to the specified 16-bit address.
      • Example: LJMP 2050H (jumps to memory location 2050H)
  2. Conditional Branching

    • These depend on the status of flags (Carry, Parity, Overflow, etc.) set by previous operations
    • Examples:
      • JC LABEL (Jump if Carry flag is set)
      • JNC LABEL (Jump if Carry flag is not set)
      • JZ LABEL (Jump if Zero flag is set)
      • JNZ LABEL (Jump if Zero flag is not set)
  3. Short Jump (Relative Jump)

    • SJMP: Jumps to an address within a limited range relative (+127 or -128 bytes) to the current instruction.
    • Example: SJMP LOOP_START (jumps to a label relatively nearby)

Example: Conditional Loop

MOV R0, #10    ; Initialize a counter
LOOP:
   ; ... some code here ...
   DJNZ R0, LOOP  ; Decrement and jump if not zero

Explanation

  1. The counter register R0 is loaded with 10.
  2. The code in the LOOP section executes.
  3. DJNZ R0, LOOP
    • Decrements R0 by one.
    • If the Zero flag is NOT set (R0 is not zero), jumps back to the LOOP label.

Key Points

  • Branching instructions are core to creating loops, decision structures (if-else), and subroutines within programs.
  • The destination of a jump can be an explicit address (e.g., LJMP 2050H) or often a label that the assembler translates to the correct address.

Q5b: Interface 8 leds with 8051 microcontroller and write a program to turn on and off.
#

Hardware Setup

  1. 8 LEDs: Choose standard LEDs considering the current requirements of the 8051’s I/O ports.
  2. Current-Limiting Resistors: Calculate the appropriate resistor values for your specific LEDs to prevent damage (search for an online “LED resistor calculator” if needed).
  3. 8051 Microcontroller: We’ll assume you have an 8051 development board with an I/O port (e.g., Port 1).
  4. Connections:
    • Connect one leg of each LED to a separate pin on Port 1 of the 8051 (P1.0 to P1.7).
    • Connect the other leg of each LED through a current-limiting resistor to ground.

Programming (Assembly)

Here’s a simple 8051 assembly program to repeatedly turn the LEDs on and then off with a delay:

ORG 0000H  ; Program starts at address 0000H

MAIN_LOOP:
    MOV A, #FFH   ; Set all port pins high (LEDs on)
    MOV P1, A     ; Send data to Port 1
    CALL DELAY    ; Call a delay subroutine

    MOV A, #00H   ; Set all port pins low (LEDs off)
    MOV P1, A
    CALL DELAY

    SJMP MAIN_LOOP  ; Jump back to the beginning

DELAY:  ; Simple delay subroutine - adjust for desired time
    MOV R0, #200   ; Adjust these values for timing
    MOV R1, #150
DLY_LOOP: DJNZ R1, DLY_LOOP
          DJNZ R0, DLY_LOOP
          RET  ; Return from subroutine

END

Explanation

  1. MAIN_LOOP:

    • MOV A, #FFH: Loads the accumulator with FFH (all bits 1), which will turn all LEDs on.
    • MOV P1, A: Sends this value to Port 1.
    • CALL DELAY: Calls a subroutine to create a delay.
    • MOV A, #00H: Loads the accumulator with 00H (all bits 0), which will turn all LEDs off.
    • SJMP MAIN_LOOP: Creates an infinite loop.
  2. DELAY Subroutine:

    • Provides a simple software delay using nested loops. You might want a more precise timer-based delay in a real application.

Key Points:

  • Port Choice: I used Port 1(P1); adapt the code if you connect the LEDs to a different port.
  • LED Polarity: If your LEDs light up in the opposite manner, reverse the logic (use 00H to turn them on and FFH to turn them off)
  • Delay Adjustment: Modify the values in the DELAY subroutine to change the on and off duration.

Q5c: Interface LCD with 8051 microcontroller and write a program to display “welcome”.
#

Hardware Setup

  • LCD: We’ll assume a standard 16x2 character LCD module with a common HD44780 compatible controller.
  • Connections:
    • Data Pins (D0-D7): Connect to an 8051 I/O Port (e.g., Port 2)
    • Control Pins:
      • RS (Register Select): Connect to an 8051 pin (e.g., P1.0)
      • RW (Read/Write): Connect to an 8051 pin (e.g., P1.1)
      • E (Enable): Connect to an 8051 pin (e.g., P1.2)
    • Contrast Adjustment (Vo): Connect to a potentiometer for controlling display contrast.
    • Backlight (if present): Power according to its requirements.

Assembly Programming

Here’s an 8051 assembly program to initialize the LCD and display “Welcome”:

ORG 0000H

; Constants
LCD_PORT EQU P2
RS_PIN   EQU P1.0
RW_PIN   EQU P1.1
E_PIN    EQU P1.2

; --- LCD Initialization ---
LCD_INIT:
    MOV A, #38H  ; Function set: 8-bit, 2 lines, 5x7 font
    CALL LCD_CMD
    MOV A, #0CH  ; Display on, cursor off, no blinking
    CALL LCD_CMD
    MOV A, #01H  ; Clear display
    CALL LCD_CMD
    MOV A, #06H  ; Entry mode: Increment cursor
    CALL LCD_CMD
    RET

; --- Send Command to LCD  ---
LCD_CMD:
    CLR RS_PIN
    CLR RW_PIN
    MOV LCD_PORT, A
    SETB E_PIN     ; Pulse Enable
    CLR E_PIN
    CALL DELAY     ; Small delay (important for LCD)
    RET

; --- Send Data (Character) to LCD ---
LCD_DATA:
    SETB RS_PIN
    CLR RW_PIN
    MOV LCD_PORT, A
    SETB E_PIN      ; Pulse Enable
    CLR E_PIN
    CALL DELAY      ; Small delay
    RET

; --- Simple Delay Subroutine ---
DELAY:
    MOV R5, #50    ; Adjust these for approximate delay
    DLOOP: MOV R6, #200
           DJNZ R6, DLOOP
           DJNZ R5, DLOOP
           RET

; -- Main Program --
MAIN:
    CALL LCD_INIT

    MOV A, #80H     ; Set cursor to first line, first position
    CALL LCD_CMD

    MOV A, #'W'    ; Load characters to send
    CALL LCD_DATA
    MOV A, #'e'
    CALL LCD_DATA
    MOV A, #'l'
    CALL LCD_DATA
    ; ... (Send rest of "come")

END ; Add an infinite loop if needed for display to stay

Explanation

  • Constants: LCD_PORT is defined to make the code adaptable if your connections change.
  • Subroutines: These encapsulate the interaction details with the LCD (sending commands, sending data), making the main program cleaner. You’ll need to fill in the details of these subroutines according to your LCD’s datasheet.
  • Main Program:
    • Calls LCD_INIT to configure the LCD.
    • Sends commands to select the desired display mode (2 lines, 5x7 font) and clear the display.
    • Sends each character of the message “Welcome” to the LCD using LCD_DATA.

Key Points

  • LCD Datasheet: You MUST adapt the initialization and command sequences based on your specific LCD module.
  • 8051 Timing: You might need short delays within the subroutines to ensure the LCD processes commands correctly.
  • Subroutine Implementation: The core logic of sending commands/data to the LCD involves setting the RS/RW lines, placing data on the data port, and pulsing the Enable pin.

Q5a: Explain logical instruction with example.
#

What are Logical Instructions?

Logical instructions perform bitwise operations on individual bits within registers or between a register and an immediate value. These include:

  • AND: Bitwise logical AND operation.
  • OR: Bitwise logical OR operation.
  • XOR: Bitwise logical XOR (Exclusive OR) operation.
  • NOT: Bitwise inversion (Complement)
  • Rotate/Shift: Move bits within a register or memory location

How they work

Each bit of the first operand is compared to the corresponding bit of the second operand according to the following truth tables:

Input AInput BANDORXOR
00000
01011
10011
11110

Key Takeaways:

  • AND: Outputs 1 only when both inputs are 1.
  • OR: Outputs 1 when at least one input is 1.
  • XOR: Outputs 1 when the inputs are different.

Examples

  1. Masking Bits (AND)

    MOV A, #53H  ; A = 0101 0011
    ANL A, #0FH  ; AND with 0000 1111 (mask to keep only the lower 4 bits)
    ; A now holds 0000 0011
    
  2. Setting Bits (OR)

    MOV A, #7BH  ; A = 0111 1011
    ORL A, #80H  ; OR with 1000 0000 (set the most significant bit)
    ; A now holds 1111 1011
    
  3. Toggling Bits (XOR)

    MOV A, #96H  ; A = 1001 0110
    XOR A, #05H  ; XOR with 0000 0101 (toggle specific bits)
    ; A now holds 1001 0011
    
  4. Rotating Bits

    MOV A, #0AH  ; A = 0000 1010
    RL A         ; Rotate left through carry (assume Carry flag is 0)
    ; A now holds 0001 0100
    

Common Uses

  • Testing if specific bits are set or clear.
  • Manipulating flags (e.g., setting the Carry flag).
  • Isolating sections of data within a byte.
  • Implementing simple cryptographic functions.

Q5b: Interface 7 segment with 8051 microcontroller.
#

Assumptions

  • Common Anode Display: The segments have a common positive connection. We’ll control them by sinking current (connecting to ground) through the 8051’s pins.
    • Adapt the segment patterns if you have a Common Cathode display.
  • Single Digit: We’ll interface a single digit display. This can be extended for multiple digits using multiplexing techniques.
  • Connections: We’ll assume you’ll connect the 7-segment pins (a through g) to a port of the 8051 (e.g., Port 1).

Hardware Setup

  1. 7-Segment Display: Choose a common anode 7-segment LED display.
  2. Current-Limiting Resistors: Calculate and use resistors in series with each segment LED to prevent damage. Search for a “LED resistor calculator” to find the right values.
  3. Connections:
    • Connect the anodes of all segments (a through g) to the corresponding pins of Port 1 (P1.0 through P1.6) of the 8051.
    • Connect the common anode pin to the power supply (+5V).
    • Connect each segment’s cathode through the resistor to ground.

Lookup Table

Create a lookup table in your program memory that maps the digit you want to display (0-9) to the corresponding segment patterns:

SEGMENT_PATTERNS:
    DB 0C0H ; Pattern for 0 (abcdefg)
    DB 0F9H ; Pattern for 1
    DB 0A4H ; Pattern for 2
     ; ... Add patterns for 3-9

Note: For a common anode display, ‘1’ means the segment should be ON, so it’s connected to ground.

Assembly Code Example

ORG 0000H

; Assume display is connected to Port 1
DISPLAY_PORT EQU P1

; ... (Segment patterns lookup table from above)

MAIN_LOOP:
    MOV R0, #2   ; Example: Load the digit 2 to display
    MOV A, @R0   ; Point to the segment pattern in the table
    ADD A, SEGMENT_PATTERNS  ; Calculate the address
    MOVC A, @A+DPTR          ; Fetch the segment pattern
    MOV DISPLAY_PORT, A      ;  Send the pattern to the display port

    ; ... (Add display refreshing if you want to multiplex multiple digits)
END

Explanation

  • Table Usage: The code loads the digit to be displayed into R0, uses indirect addressing to get the corresponding pattern from the lookup table, and sends it to the display port.
  • Multiplexing: If you have multiple 7-segment displays, you need to switch between them rapidly and update the display port accordingly to create the illusion they are all on simultaneously.

Important:

  • Port Output: Ensure the port you use is configured as output.
  • Resistors: Don’t forget the current-limiting resistors!

Q5c: Interface LM 35 with 8051 microcontroller and explain block diagram of temperature controller.
#

Interfacing LM35 with 8051

  1. Connections:

    • Connect the Vout pin of the LM35 to one of the 8051’s analog input channels (ADC).
    • Connect the VSS pin of the LM35 to ground.
    • Connect the VS pin of the LM35 to the power supply (+5V).
  2. ADC Configuration:

    • Select the ADC channel connected to the LM35.
    • Set the ADC’s resolution (e.g., 10-bit).
    • In your program, initiate the ADC conversion process.
  3. Reading and Conversion:

    • After the conversion completes, read the digital value from the ADC data register.
    • The LM35 outputs 10mV per degree Celsius. To convert the digital ADC reading to temperature:
      • Scale the ADC value based on its resolution and reference voltage.
      • Divide by 10 to get the temperature in Celsius.

Code Snippet (Illustrative)

; ... (ADC Initialization)
START_CONVERSION:
    SETB ADC_START_BIT  ; Trigger ADC conversion
    JBC ADC_BUSY_BIT, START_CONVERSION ; Wait for conversion to complete

    MOV A, ADC_DATA_REG   ; Read ADC result
    ; ... (Calculate temperature from ADC value)

Block Diagram: Temperature Controller

Block Diagram of 8051 based Temperature Control

  • Temperature Sensor (LM35): Measures the ambient temperature and generates an analog voltage proportional to the temperature.
  • ADC (Analog-to-Digital Converter): Part of the 8051 microcontroller, it converts the analog voltage from the LM35 into a digital value.
  • 8051 Microcontroller:
    • Reads the temperature from the ADC.
    • Compares the measured temperature with a desired setpoint.
    • Generates control signals based on the comparison.
  • Control Output (Relay, etc.): Controls a device (e.g., heater, fan) to regulate the temperature. Could be a simple on/off relay or more complex control like PWM.
  • Display (Optional): A display (LCD, 7-segment) to show the current temperature or setpoint.

How it Works

  1. The LM35 senses temperature and sends the analog signal to the ADC.
  2. The ADC converts the analog signal to a digital value.
  3. The 8051 microcontroller reads this value, calculates the temperature, and compares it to the desired setpoint.
  4. If the temperature deviates from the setpoint, the 8051 sends control signals to turn a heater or cooler on or off, aiming to bring the temperature back to the setpoint.

Related

Microprocessor and Microcontroller (4341101) - Winter 2023 Solution
19 mins
Study-Material Solutions Microprocessor 4341101 2023 Winter
Microprocessor and Microcontroller (4341101) - Summer 2023 Solution
23 mins
Study-Material Solutions Microprocessor 4341101 2023 Summer
Fundamentals of Electronics (4311102) - Winter 2023 Solution
19 mins
Study-Material Solutions Electronics 4311102 2023 Winter
Electronic Circuits & Applications (4321103) - Winter 2023 Solution
16 mins
Study-Material Solutions Electronics 4321103 2023 Winter
Principles of Electronic Communication (4331104) - Winter 2023 Solution
20 mins
Study-Material Solutions Electronic-Communication 4331104 2023 Winter
Fundamentals of Electrical Engineering (4311101) - Winter 2023 Solution
12 mins
Study-Material Solutions Electrical-Engineering 4311101 2023 Winter