Microprocessor and Microcontroller (4341101) - Winter 2024 Solution

Solution guide for Microprocessor and Microcontroller (4341101) Winter 2024 exam

Question 1(a) [3 marks]

List Common features of Microcontrollers.

Answer:

FeaturePurpose
CPU CoreProcess instructions
Memory (RAM/ROM)Store program and data
I/O PortsInterface with external devices
Timers/CountersMeasure time intervals
InterruptsHandle asynchronous events
Serial CommunicationTransfer data with other devices

Mnemonic: "CRITICS: CPU ROM I/O Timers Interrupts Comm Serial"

Question 1(b) [4 marks]

Explain the functions of ALU.

Answer:

FunctionDescription
Arithmetic OperationsAddition, subtraction, increment, decrement
Logical OperationsAND, OR, XOR, NOT, comparison
Data MovementTransfer between registers and memory
Flag SettingUpdate status flags based on operation results

Diagram:

goat

Mnemonic: "ALFS: Arithmetic Logic Flags Status"

Question 1(c) [7 marks]

Define: Memory, Operand, Instruction Cycle, Opcode, CU, Machine Cycle, CISC

Answer:

TermDefinition
MemoryStorage unit that holds data and instructions
OperandData value or address used in an operation
Instruction CycleComplete process of fetching and executing an instruction
OpcodeOperation code that specifies the instruction type
CUControl Unit that coordinates processor operations
Machine CycleBasic operation cycle consisting of T-states
CISCComplex Instruction Set Computer with rich instruction set
  • Memory: Organized array of storage cells with unique addresses
  • Operand: Data elements that instructions operate upon
  • Instruction Cycle: Fetch-decode-execute sequence for each instruction
  • Opcode: Binary code that tells processor what operation to perform

Diagram:

goat

Mnemonic: "MO-ICO-MC: Memory-Operand-Instruction-Control-Operation-Machine-Complex"

Question 1(c OR) [7 marks]

i) Define: Microprocessor. ii) Compare Von-Neumann and Harvard architecture.

Answer:

i) Microprocessor Definition:

An integrated circuit containing the CPU functionality of a computer,
capable of fetching, decoding, and executing instructions with ALU and
control circuitry on a single chip.

ii) Von-Neumann vs Harvard Architecture:

FeatureVon-NeumannHarvard
MemorySingle shared memorySeparate program & data memory
BusSingle bus for data & instructionsSeparate buses
SpeedSlower (memory bottleneck)Faster (parallel access)
ComplexitySimpler designMore complex
ApplicationsGeneral computingReal-time systems

Diagram:

goat

Mnemonic: "Harvard Has Separate Spaces"

Question 2(a) [3 marks]

Explain various Registers of 8085 microprocessor.

Answer:

RegisterSizeFunction
Accumulator (A)8-bitMain register for arithmetic & logic
General Purpose (B,C,D,E,H,L)8-bitTemporary data storage
Program Counter (PC)16-bitAddress of next instruction
Stack Pointer (SP)16-bitPoints to top of stack
Flag Register8-bitStatus flags (Z,S,P,CY,AC)

Mnemonic: "AGSF: Accumulator-General-Stack-Flags"

Question 2(b) [4 marks]

Explain Fetching, Decoding and Execution of Instruction.

Answer:

PhaseActivityHardware Involved
FetchingGet instruction from memory address in PCPC, Address bus, Memory
DecodingIdentify operation type and operandsInstruction Register, Control Unit
ExecutionPerform specified operationALU, Registers, Data bus

Diagram:

goat
  • Fetching: PC sends address to memory, instruction loaded into IR
  • Decoding: Control unit interprets instruction opcode and addressing mode
  • Execution: ALU performs arithmetic/logic, data moves between registers/memory

Mnemonic: "FDE: First Get, Then Understand, Finally Do"

Question 2(c) [7 marks]

Describe block diagram of 8085 microprocessor with the help of neat diagram.

Answer:

BlockFunction
ALUArithmetic & logical operations
Register ArrayTemporary data storage
Instruction Register & DecoderHold & interpret instructions
Control & Timing UnitGenerate control signals
Address BufferInterface with address bus
Data BufferInterface with data bus
Serial I/OCommunication with SID/SOD
Interrupt ControlHandle interrupt requests

Diagram:

goat
  • Core Components: ALU and registers form processing core
  • Control Path: Instructions flow through register, decoder, control unit
  • Data Path: Data moves through buffers to/from external buses
  • Timing: Synchronizes all operations via internal clock

Mnemonic: "RAID: Registers-ALU-Instructions-Decoders"

Question 2(a OR) [3 marks]

Compare Microprocessor & Microcontroller.

Answer:

FeatureMicroprocessorMicrocontroller
DesignCPU onlyCPU + peripherals
MemoryExternalInternal (RAM/ROM)
I/O portsLimitedMany built-in
ApplicationsGeneral computingEmbedded systems
CostHigherLower
ExampleIntel 8085/8086Intel 8051

Mnemonic: "Micro-P Processes, Micro-C Controls"

Question 2(b OR) [4 marks]

Explain De-multiplexing of Address and Data buses for 8085 Microprocessor.

Answer:

StepAction
1ALE signal goes high
2Lower address (A0-A7) appears on AD0-AD7
3Latch captures address using ALE
4ALE goes low, AD0-AD7 now carries data

Diagram:

goat
  • Multiplexing: AD0-AD7 pins carry address and data at different times
  • ALE Signal: Address Latch Enable controls when address is captured
  • 8-bit Latch: Holds lower address bits during entire machine cycle
  • Timing: Address valid only during high state of ALE pulse

Mnemonic: "ALAD: ALE Latches Address before Data"

Question 2(c OR) [7 marks]

Describe Pin diagram of 8085 microprocessor with the help of neat diagram.

Answer:

Pin GroupFunction
Address/DataMultiplexed AD0-AD7, A8-A15
ControlRD, WR, IO/M, S0, S1, ALE, CLK
InterruptsINTR, RST 5.5-7.5, TRAP
DMAHOLD, HLDA
PowerVcc, Vss
Serial I/OSID, SOD
ResetRESET IN, RESET OUT

Diagram:

goat
  • Address Pins: A8-A15 (8) and multiplexed AD0-AD7 (8) for 16-bit addressing
  • Control Pins: Generate timing and control signals for peripheral devices
  • Interrupt Pins: Hardware interrupt handling with priority levels
  • Clock: X1, X2 for crystal connection, CLK for synchronization
  • Power: Vcc (+5V) and Vss (Ground) for power supply

Mnemonic: "ACID-PS: Address-Control-Interrupt-DMA-Power-Serial"

Question 3(a) [3 marks]

Explain interrupts of 8051 microcontroller.

Answer:

InterruptVectorPrioritySource
External 00003H1 (IP.0)Pin INT0 (P3.2)
Timer 0000BH2 (IP.1)Timer 0 overflow
External 10013H3 (IP.2)Pin INT1 (P3.3)
Timer 1001BH4 (IP.3)Timer 1 overflow
Serial0023H5 (IP.4)Serial port events

Diagram:

goat

Mnemonic: "ETTES: External-Timer-Timer-External-Serial"

Question 3(b) [4 marks]

Draw Pin diagram of 8051 microcontroller.

Answer:

goat
Pin GroupFunction
P0Port 0, multiplexed with address/data
P1Port 1, general purpose I/O
P2Port 2, upper address and I/O
P3Port 3, special functions and I/O
XTALCrystal oscillator connections
ControlRST, EA, ALE, PSEN

Mnemonic: "PORT 0123: Data-General-Address-Special"

Question 3(c) [7 marks]

Explain Internal RAM Organization of 8051 microcontroller.

Answer:

RAM AreaAddress RangeUsage
Register Banks00H-1FHR0-R7 (4 banks)
Bit-addressable20H-2FH128 bits (0-7FH)
Scratch Pad30H-7FHGeneral purpose
SFRs80H-FFHControl registers

Diagram:

goat
  • Register Banks: Four banks of 8 registers (R0-R7) selectable by PSW
  • Bit-addressable: 16 bytes (128 bits) individually addressable as bits
  • General Purpose: User variables and stack space
  • SFRs: Control and status registers at higher addresses

Mnemonic: "RBBS: Registers Bits Buffer Special"

Question 3(a OR) [3 marks]

List SFRs with their addresses.

Answer:

SFRAddressFunction
P080HPort 0
SP81HStack Pointer
DPL82HData Pointer Low
DPH83HData Pointer High
PCON87HPower Control
TCON88HTimer Control
TMOD89HTimer Mode
P190HPort 1
SCON98HSerial Control
P2A0HPort 2
IEA8HInterrupt Enable
P3B0HPort 3
IPB8HInterrupt Priority
PSWD0HProgram Status Word
ACCE0HAccumulator
BF0HB Register

Mnemonic: "PDPT-SP: Ports-Data-Program-Timers-Serial-Prioritized"

Question 3(b OR) [4 marks]

Explain Timers/Counters logic diagram of 8051 microcontroller.

Answer:

Timer/Counter Diagram:

goat
ComponentFunction
TLx, THxTimer low and high byte registers
C/TSelects Timer (0) or Counter (1) mode
GATEExternal enable control
TRxTimer run control bit
Mode ControlSelects one of four operation modes
  • Timer: Uses internal clock, counts machine cycles
  • Counter: Counts external events on T0/T1 pins
  • Control Bits: Set in TMOD and TCON registers
  • Modes: Different timer configurations (13/16/8-bit)

Mnemonic: "TCG: Timer-Counter-Gate"

Question 3(c OR) [7 marks]

Explain block diagram of 8051 microcontroller.

Answer:

ComponentFunction
CPU8-bit processor with ALU
Memory4K ROM, 128 bytes RAM
I/O PortsFour 8-bit ports (P0-P3)
TimersTwo 16-bit timers/counters
Serial PortFull-duplex UART
InterruptsFive interrupt sources
Special Function RegistersControl registers

Diagram:

goat
  • Harvard Architecture: Separate program and data memory
  • CISC Design: Rich instruction set (over 100 instructions)
  • In-built Peripherals: No need for external components
  • Single-chip Solution: Complete system on one chip

Mnemonic: "CAPITALS: CPU Architecture Ports I/O Timer ALU LS-Interface Serial"

Question 4(a) [3 marks]

Write an 8051 Assembly Language Program to add two bytes of data and store result in R4 register.

Answer:

Assembly

Key Steps:

  • Load first operand into Accumulator
  • Load second operand into register R3
  • Perform addition using ADD instruction
  • Store result from Accumulator to R4

Mnemonic: "LLAS: Load-Load-Add-Store"

Question 4(b) [4 marks]

Write an 8051 Assembly Language Program to OR the contents of Port-1 and Port-2 then put the result in external RAM location 0200H.

Answer:

Assembly

Key Steps:

  • Read Port-1 into Accumulator
  • Perform OR operation with Port-2
  • Set up Data Pointer (DPTR) for external RAM
  • Write result to external memory

Mnemonic: "PORT: Port-OR-Register-Transfer"

Question 4(c) [7 marks]

List Addressing Modes of 8051 Microcontroller and explain them with at least one example.

Answer:

Addressing ModeExampleDescription
ImmediateMOV A, #25HData is in instruction
RegisterMOV A, R0Data is in register
DirectMOV A, 30HData is at RAM address
IndirectMOV A, @R0R0/R1 contains address
IndexedMOVC A, @A+DPTRAccess program memory
BitSETB P1.3Access individual bits
RelativeSJMP LABELJumps with 8-bit offset

Examples:

  • Immediate: MOV A, #55H (Load A with 55H)
  • Register: ADD A, R3 (Add R3 to A)
  • Direct: MOV 40H, A (Store A at address 40H)
  • Indirect: MOV @R0, #5 (Store 5 at address in R0)
  • Indexed: MOVC A, @A+DPTR (Read code memory)
  • Bit: CLR C (Clear carry flag)
  • Relative: JZ LOOP (Jump if A is zero)

Mnemonic: "I'M DIRBI: Immediate Register Direct Bit Indexed"

Question 4(a OR) [3 marks]

Explain following instructions: (i) DJNZ (ii) POP (iii) CJNE.

Answer:

InstructionSyntaxOperation
DJNZDJNZ Rn, relDecrement register, Jump if Not Zero
POPPOP directPop data from stack to direct address
CJNECJNE A, #data, relCompare and Jump if Not Equal

Examples and Explanation:

  • DJNZ R7, LOOP: Decrements R7 and jumps to LOOP if R7≠0

    • Used for loop counters and delays
  • POP 30H: Copies data from stack to address 30H

    • Increments SP after data retrieval
  • CJNE A, #25H, NOTEQUAL: Compares A with 25H, jumps if not equal

    • Also sets Carry flag if A < data

Mnemonic: "DPC: Decrement-Pop-Compare"

Question 4(b OR) [4 marks]

For 8051 Microcontroller with a crystal frequency of 12 MHz, generate a delay of 4ms.

Answer:

Assembly

Calculation:

  • Each inner loop: 4 cycles × 250 iterations = 1000
  • Outer loop: 16 iterations × 1000 cycles = 16,000 cycles
  • At 12MHz, 1 machine cycle = 1μs
  • Total delay = 4ms (4000 cycles)

Mnemonic: "LNDD: Load-NOP-Decrement-Decrement"

Question 4(c OR) [7 marks]

Explain any seven Logical instructions with example for 8051 Microcontroller.

Answer:

InstructionExampleOperation
ANLANL A, #3FHLogical AND
ORLORL P1, #80HLogical OR
XRLXRL A, R0Logical XOR
CLRCLR AClear (set to 0)
CPLCPL P1.0Complement (invert)
RLRL ARotate left
RRRR ARotate right

Examples with Explanation:

  1. ANL A, #0FH: Masks high nibble (A = A AND 0FH)

    • Before: A = 95H, After: A = 05H
  2. ORL 20H, A: Sets bits in memory (20H = 20H OR A)

    • Before: 20H = 55H, A = 0AH, After: 20H = 5FH
  3. XRL A, #55H: Toggles specific bits (A = A XOR 55H)

    • Before: A = AAH, After: A = FFH
  4. CLR C: Clears carry flag (C = 0)

    • Used before subtraction operations
  5. CPL A: Inverts all bits (A = NOT A)

    • Before: A = 55H, After: A = AAH
  6. RL A: Rotates accumulator left one bit

    • Before: A = 85H (10000101), After: A = 0BH (00001011)
  7. RR A: Rotates accumulator right one bit

    • Before: A = 85H (10000101), After: A = C2H (11000010)

Mnemonic: "A-OX-CCR: AND OR XOR Clear Complement Rotate"

Question 5(a) [3 marks]

List Applications of microcontroller in various fields.

Answer:

FieldApplications
IndustrialMotor control, automation, PLCs
MedicalPatient monitoring, diagnostic equipment
ConsumerWashing machines, microwaves, toys
AutomotiveEngine control, ABS, airbag systems
CommunicationMobile phones, modems, routers
SecurityAccess control, alarm systems

Mnemonic: "I-MACS: Industrial-Medical-Automotive-Consumer-Security"

Question 5(b) [4 marks]

Interface Push button Switch and LED with 8051 microcontroller.

Answer:

Circuit Diagram:

goat

Program:

Assembly
ComponentConnectionPurpose
Push ButtonP1.0 (input)User input, active-low
Pull-up Resistor10K to VccPrevents floating input
LEDP1.7 (output)Visual indicator
Current-limiting Resistor330ΩProtects LED

Mnemonic: "PLIC: Push-LED-Input-Control"

Question 5(c) [7 marks]

Interface LCD with microcontroller and write a program to display "HELLO".

Answer:

Circuit Diagram:

goat

Program:

Assembly
ComponentConnectionPurpose
Data PinsP2.0-P2.7Transfer data/commands
RS (Register Select)P3.0Select command (0) or data (1)
R/W (Read/Write)P3.1Select write (0) or read (1)
E (Enable)P3.2Latch data on falling edge
  • Initialization: Configure LCD for 8-bit, 2 lines, cursor options
  • Data Transfer: Commands sent with RS=0, characters with RS=1
  • Characters: ASCII values sent one by one to display text
  • Timing: Delay routine ensures proper signal timing

Mnemonic: "DICE: Data-Instruction-Control-Enable"

Question 5(a OR) [3 marks]

Draw Interfacing of LM35 with 8051 microcontroller.

Answer:

Circuit Diagram:

goat
ComponentFunction
LM35Temperature sensor (10mV/°C)
ADC0804Analog-to-Digital Converter
8051Microcontroller to read temperature

Key Points:

  • LM35 produces analog voltage proportional to temperature
  • ADC0804 converts analog voltage to digital value
  • 8051 controls ADC and reads temperature data
  • Resolution: 10mV/°C → ~0.2°C resolution with 8-bit ADC

Mnemonic: "TAC: Temperature-Analog-Convert"

Question 5(b OR) [4 marks]

Interface Stepper motor with 8051 microcontroller.

Answer:

Circuit Diagram:

goat

Program:

Assembly
ComponentPurpose
ULN2003Driver IC with Darlington arrays
Port pinsP1.0-P1.3 for 4 motor phases
Power supplySeparate supply for motor

Key Points:

  • Stepper motor requires specific sequence of pulses for rotation
  • ULN2003 provides current amplification for motor coils
  • 8-step sequence provides smoother rotation
  • Delay between steps controls rotation speed

Mnemonic: "PDCS: Port-Driver-Current-Sequence"

Question 5(c OR) [7 marks]

Interface ADC0804 with 8051 microcontroller.

Answer:

Circuit Diagram:

goat

Program:

Assembly
Connection8051 PinADC0804 Pin
Data BusP0.0-P0.7D0-D7
CSP1.0CS
RDP1.1RD
WRP1.2WR
INTRP1.3INTR

ADC0804 Features:

  • 8-bit resolution (256 steps)
  • 0-5V input range
  • Single-channel operation
  • ~100μs conversion time
  • Interface protocol:
    1. Activate CS, pulse WR to start conversion
    2. Wait for INTR to go low (conversion complete)
    3. Activate RD to read data
    4. Deactivate CS when done

Mnemonic: "CRIW: Control-Read-Interrupt-Write"