Skip to main content
  1. Resources/
  2. Study Materials/
  3. Information & Communication Technology Engineering/
  4. ICT Semester 3/
  5. Microprocessor & Microcontroller Systems (1333202)/

Microprocessor & Microcontroller Systems (1333202) - Summer 2024 Solution

23 mins· ·
Study-Material Solutions Microprocessor Microcontroller 8085 8051 1333202 2024 Summer
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

Question 1(a) [3 marks]
#

List common features of 8051 microcontroller.

Answer:

Table: Common Features of 8051 Microcontroller

FeatureDescription
On-chip OscillatorBuilt-in clock generator circuit
Program Memory4KB internal ROM for code storage
Data Memory128 bytes internal RAM
I/O Ports4 bidirectional 8-bit ports (P0-P3)
Timers/CountersTwo 16-bit Timer/Counter units
Serial PortFull duplex UART communication
Interrupts5 interrupt sources with priority
SFRsSpecial Function Registers for control

Mnemonic: “On Program Data I/O Timers Serial Interrupts SFRs”

Question 1(b) [4 marks]
#

Define T-State, Machine Cycle, Instruction Cycle and Opcode.

Answer:

Table: Microprocessor Timing Definitions

TermDefinitionDuration
T-StateOne clock period of system clockBasic timing unit
Machine CycleTime to complete one memory operation3-6 T-states
Instruction CycleTime to fetch, decode and execute instruction1-4 Machine cycles
OpcodeOperation code specifying instruction type1-3 bytes
  • T-State: Smallest unit of time in microprocessor operation
  • Machine Cycle: Contains multiple T-states for memory access
  • Instruction Cycle: Complete instruction execution time
  • Opcode: Binary code identifying specific instruction

Mnemonic: “Time Machine Instruction Operation”

Question 1(c) [7 marks]
#

Compare Von-Neumann and Harvard Architecture.

Answer:

Table: Von-Neumann vs Harvard Architecture Comparison

ParameterVon-NeumannHarvard
Memory OrganizationSingle memory for code and dataSeparate memory for code and data
Bus StructureSingle bus systemDual bus system
SpeedSlower due to bus sharingFaster parallel access
CostLower cost implementationHigher cost due to dual memory
FlexibilityMore flexible memory usageLess flexible, fixed allocation
Examples8085, x86 processors8051, DSP processors
graph TB
    subgraph "Von-Neumann Architecture"
        CPU1[CPU] <--> MEM1[Single Memory<br/>Code + Data]
    end
    
    subgraph "Harvard Architecture"
        CPU2[CPU] <--> PMEM[Program Memory]
        CPU2 <--> DMEM[Data Memory]
    end

Key Differences:

  • Memory Access: Von-Neumann uses sequential access, Harvard allows simultaneous
  • Performance: Harvard is faster for embedded applications
  • Applications: Von-Neumann for general computing, Harvard for real-time systems

Mnemonic: “Von-Single Harvard-Dual”

Question 1(c) OR [7 marks]
#

Explain Microcomputer System with block diagram.

Answer:

Microcomputer System Components:

graph TB
    subgraph "Microcomputer System"
        CPU[Central Processing Unit<br/>- Control Unit<br/>- ALU<br/>- Registers] 
        MEM[Memory Unit<br/>- RAM<br/>- ROM]
        IO[Input/Output Unit<br/>- Keyboard<br/>- Display<br/>- Ports]
        SYS[System Bus<br/>- Address Bus<br/>- Data Bus<br/>- Control Bus]
        
        CPU <--> SYS
        MEM <--> SYS
        IO <--> SYS
    end

Table: Microcomputer System Components

ComponentFunctionExamples
CPUCentral processing and control8085, 8086
MemoryProgram and data storageRAM, ROM, EPROM
I/O UnitInterface with external worldKeyboard, Display
System BusData transfer pathwayAddress, Data, Control
  • CPU: Executes instructions and controls system operation
  • Memory: Stores programs and data for processing
  • I/O: Provides communication with external devices
  • Bus: Connects all components for data transfer

Mnemonic: “CPU Memory I/O Bus”

Question 2(a) [3 marks]
#

Draw Bus organization in 8085 Microprocessor.

Answer:

A1MSd6eydB-msrubotesirestyms8C0P8U5D8eDB-Iaub/itsiOcates

Table: 8085 Bus Organization

Bus TypeWidthFunction
Address Bus16-bitMemory addressing (64KB)
Data Bus8-bitData transfer
Control BusMultipleControl signals

Mnemonic: “Address Data Control”

Question 2(b) [4 marks]
#

List Flags used in 8085 and Explain working of each flags.

Answer:

Table: 8085 Flags Register

FlagNameBit PositionFunction
SSignD7Set if result is negative
ZZeroD6Set if result is zero
ACAuxiliary CarryD4Set if carry from bit 3 to 4
PParityD2Set if result has even parity
CYCarryD0Set if carry/borrow occurs
D7SD6ZD5D4ACD3D2PD1D0CY
  • Sign Flag: Indicates negative result (MSB = 1)
  • Zero Flag: Set when arithmetic result is zero
  • Auxiliary Carry: Used for BCD arithmetic operations
  • Parity Flag: Checks even number of 1’s in result
  • Carry Flag: Indicates overflow in arithmetic operations

Mnemonic: “Sign Zero Auxiliary Parity Carry”

Question 2(c) [7 marks]
#

Draw and Explain Block Diagram of 8085.

Answer:

graph TB
    subgraph "8085 Microprocessor"
        ALU[Arithmetic Logic Unit<br/>8-bit operations]
        ACC[Accumulator<br/>Register A]
        REG[General Purpose<br/>Registers B,C,D,E,H,L]
        PC[Program Counter<br/>16-bit]
        SP[Stack Pointer<br/>16-bit]
        FLAGS[Flag Register<br/>5 flags]
        CU[Control Unit<br/>Instruction decode]
        
        ALU <--> ACC
        REG <--> ALU
        PC --> CU
        CU --> ALU
        FLAGS <--> ALU
    end
    
    EXT["External Buses<br/>Address(16), Data(8), Control"]
    8085 <--> EXT

Table: 8085 Block Components

BlockFunctionSize
ALUArithmetic and logical operations8-bit
AccumulatorPrimary register for operations8-bit
RegistersData storage (B,C,D,E,H,L)8-bit each
Program CounterPoints to next instruction16-bit
Stack PointerPoints to stack top16-bit
Control UnitInstruction decode and control-
  • Data Flow: Instructions fetched via PC, decoded by CU, executed in ALU
  • Register Operations: Accumulator works with ALU, other registers store data
  • Address Generation: PC and SP provide 16-bit addresses
  • Control Signals: CU generates timing and control signals

Mnemonic: “ALU Accumulator Registers Program Stack Control”

Question 2(a) OR [3 marks]
#

Explain Instruction Fetching, Decoding and Execution Operation in microprocessor.

Answer:

sequenceDiagram
    participant PC as Program Counter
    participant MEM as Memory
    participant IR as Instruction Register
    participant CU as Control Unit
    participant ALU as ALU
    
    PC->>MEM: Send address
    MEM->>IR: Fetch instruction
    IR->>CU: Send opcode
    CU->>ALU: Generate control signals
    ALU->>ALU: Execute operation

Table: Instruction Cycle Phases

PhaseOperationDuration
FetchGet instruction from memory1 machine cycle
DecodeInterpret instruction opcodePart of execute
ExecutePerform required operation1-3 machine cycles

Mnemonic: “Fetch Decode Execute”

Question 2(b) OR [4 marks]
#

What is Demultiplexing of Lower order Address and Data lines in 8085? Explain using neat sketch.

Answer:

AA7d-dAArD70e87A4s0-LLs8AES5D307D37D-aDt0aMAALuddalddttrrcieehpsslssIe/CxDLeaadttachEnable

Demultiplexing Process:

  • ALE Signal: Controls separation of address and data
  • Latch IC: 74LS373 stores address when ALE is high
  • Timing: Address appears first, then data on same lines

Table: Demultiplexing Components

ComponentFunctionTiming
ALEAddress Latch Enable signalHigh during T1
74LS373Octal latch ICStores A7-A0
AD7-AD0Multiplexed linesAddress then Data

Mnemonic: “Address Latch Enable Demultiplexes Lines”

Question 2(c) OR [7 marks]
#

Draw and Explain Pin Diagram of 8085.

Answer:

XXRSSTRRRIIAAAAAAAAV12SOIRSSSNNDDDDDDDDSTDDATTTTT01234567SP765RA12345678911111111112012345678908085PINDIAGR43333333333222222222A09876543210987654321MVHHCRRISRWASAAAAAAAACOLLEEO1DRL011111198CLDKSA/E543210DAEDMTYIN

Table: 8085 Pin Functions

Pin GroupFunctionCount
Address BusA8-A15 (Higher order)8 pins
Address/DataAD0-AD7 (Multiplexed)8 pins
Control SignalsALE, RD, WR, IO/M4 pins
InterruptsTRAP, RST7.5, RST6.5, RST5.5, INTR5 pins
PowerVCC, VSS2 pins
ClockX1, X2, CLK3 pins
  • Address Lines: 16-bit addressing capability (64KB)
  • Data Lines: 8-bit data transfer
  • Control Lines: Memory and I/O operation control
  • Interrupt Lines: Hardware interrupt handling

Mnemonic: “Address Data Control Interrupt Power Clock”

Question 3(a) [3 marks]
#

Draw IP SFR of 8051 and Explain function of each bit.

Answer:

IMPSDB7RegDi6steDr5(IDnP4tTe2rDr3uPpStD2PPrTi1Do1riPtXDyL10)SB-PXA0ddressB8H

Table: IP Register Bit Functions

BitNameFunction
D4PT2Timer 2 interrupt priority
D3PSSerial port interrupt priority
D2PT1Timer 1 interrupt priority
D1PX1External interrupt 1 priority
D0PX0External interrupt 0 priority
  • Priority Levels: 1 = High priority, 0 = Low priority
  • Default: All interrupts have low priority (00H)
  • Usage: Set bit to 1 for high priority interrupt

Mnemonic: “Timer2 Serial Timer1 External1 External0”

Question 3(b) [4 marks]
#

Draw and explain Timer/Counter Logic diagram for 8051.

Answer:

graph TB
    subgraph "Timer/Counter Logic"
        OSC[System Clock<br/>÷12] --> MUX1{Timer/Counter<br/>Mode Select}
        T0PIN[T0 Pin<br/>External] --> MUX1
        MUX1 --> TH0[TH0 Register<br/>High Byte]
        TH0 --> TL0[TL0 Register<br/>Low Byte]
        TL0 --> OVF[Overflow<br/>Flag TF0]
        
        TMOD[TMOD Register<br/>Mode Control] --> MUX1
        TCON[TCON Register<br/>Control Bits] --> MUX1
    end

Table: Timer Components

ComponentFunctionSize
TH0/TL0Timer 0 high/low byte registers8-bit each
TMODTimer mode register8-bit
TCONTimer control register8-bit
TF0Timer 0 overflow flag1-bit
  • Clock Source: Internal (system clock/12) or External (T0 pin)
  • Operation: Counts up from loaded value to FFH
  • Overflow: Sets TF0 flag and generates interrupt
  • Modes: 4 different timer modes available

Mnemonic: “Timer High-Low Mode Control Flag”

Question 3(c) [7 marks]
#

Draw and Explain Block Diagram of 8051.

Answer:

graph TB
    subgraph "8051 Microcontroller"
        CPU[8-bit CPU<br/>ALU + Control]
        ROM[Program Memory<br/>4KB ROM]
        RAM[Data Memory<br/>128B RAM]
        
        T0[Timer 0<br/>16-bit]
        T1[Timer 1<br/>16-bit]
        UART[Serial Port<br/>Full Duplex]
        
        P0[Port 0<br/>8-bit I/O]
        P1[Port 1<br/>8-bit I/O]
        P2[Port 2<br/>8-bit I/O]
        P3[Port 3<br/>8-bit I/O]
        
        INT[Interrupt<br/>System]
        OSC[Oscillator<br/>Clock Gen]
        
        CPU <--> ROM
        CPU <--> RAM
        CPU <--> T0
        CPU <--> T1
        CPU <--> UART
        CPU <--> P0
        CPU <--> P1
        CPU <--> P2
        CPU <--> P3
        CPU <--> INT
        OSC --> CPU
    end

Table: 8051 Block Components

BlockFunctionSpecification
CPUCentral processing unit8-bit processor
Program MemoryCode storage4KB internal ROM
Data MemoryVariable storage128 bytes RAM
I/O PortsExternal interface4 ports (32 I/O lines)
TimersTiming operations2 × 16-bit timers
Serial PortCommunicationFull duplex UART
InterruptsEvent handling5 interrupt sources
  • Architecture: Harvard architecture with separate program/data memory
  • I/O Capability: 32 bidirectional I/O lines
  • On-chip Features: Timers, serial port, interrupt system
  • Memory: Von-Neumann for data, Harvard for program

Mnemonic: “CPU Program Data I/O Timer Serial Interrupt”

Question 3(a) OR [3 marks]
#

Draw PCON SFR of 8051 and Explain function of each bit.

Answer:

PMCSSDOBM7NODR|De6gisDt5erD(4Pow|DeG3rF1C|DoG2nFt0r|Do1lP)D|D-LI0SDABLd|dress87H

Table: PCON Register Bit Functions

BitNameFunction
D7SMODSerial port mode modifier
D3GF1General purpose flag bit 1
D2GF0General purpose flag bit 0
D1PDPower down mode control
D0IDLIdle mode control
  • SMOD: Doubles serial port baud rate when set
  • GF1, GF0: User-defined flag bits
  • PD: Activates power-down mode
  • IDL: Activates idle mode

Mnemonic: “Serial General Power Idle”

Question 3(b) OR [4 marks]
#

In 8051 Serial communication Mode 1, For XTAL=11.0592 MHz, find TH1 value needed to have for 9600 and 4800 baud rate.

Answer:

Formula for Mode 1 Baud Rate:

Baud Rate = (2^SMOD/32) × (Timer1 Overflow Rate)
Timer1 Overflow Rate = XTAL/(12 × (256 - TH1))

For 9600 Baud Rate:

9600 = (1/32) × (11059200/(12 × (256 - TH1)))
9600 = 28800/(256 - TH1)
256 - TH1 = 3
TH1 = 253 = FDH

For 4800 Baud Rate:

4800 = (1/32) × (11059200/(12 × (256 - TH1)))
4800 = 28800/(256 - TH1)
256 - TH1 = 6
TH1 = 250 = FAH

Table: TH1 Values for Baud Rates

Baud RateTH1 Value (Hex)TH1 Value (Decimal)
9600FDH253
4800FAH250

Mnemonic: “Higher Baud Higher TH1”

Question 4(a) [3 marks]
#

What are the differences in LCALL and LJMP instructions in 8051?

Answer:

Table: LCALL vs LJMP Comparison

ParameterLCALLLJMP
FunctionLong subroutine callLong jump
Stack UsagePushes return addressNo stack operation
ReturnRET instruction neededDirect jump only
Bytes3 bytes3 bytes
Address Range16-bit (64KB)16-bit (64KB)
PC ActionSaved then loadedDirectly loaded
  • LCALL: Calls subroutine, saves return address on stack
  • LJMP: Unconditional jump to specified address
  • Stack Impact: LCALL uses 2 stack bytes, LJMP uses none
  • Usage: LCALL for functions, LJMP for program flow control

Mnemonic: “Call Saves Jump Goes”

Question 4(b) [4 marks]
#

Write 8051 Assembly Language Program to generate square wave on port 1.0 using Timer0.

Answer:

ORG 0000H           ; Start address
LJMP MAIN           ; Jump to main program

ORG 0030H           ; Main program start
MAIN:
    MOV TMOD, #01H  ; Timer0 mode1 (16-bit)
    MOV TH0, #HIGH(-50000)  ; Load high byte
    MOV TL0, #LOW(-50000)   ; Load low byte
    SETB TR0        ; Start Timer0

LOOP:
    JNB TF0, LOOP   ; Wait for overflow
    CLR TF0         ; Clear overflow flag
    CPL P1.0        ; Toggle P1.0
    MOV TH0, #HIGH(-50000)  ; Reload timer
    MOV TL0, #LOW(-50000)   ; Reload timer
    SJMP LOOP       ; Repeat

END

Program Explanation:

  • Timer Setup: Mode 1 (16-bit timer)
  • Count Value: -50000 for specific delay
  • Square Wave: Toggle P1.0 on each overflow
  • Continuous: Loop maintains square wave

Mnemonic: “Mode Load Start Wait Toggle Reload”

Question 4(c) [7 marks]
#

Explain any three Logical and any four Data Transfer Instruction of 8051 with example.

Answer:

Table: Logical Instructions

InstructionFunctionExampleResult
ANLLogical ANDANL A, #0FHA = A AND 0FH
ORLLogical ORORL A, #F0HA = A OR F0H
XRLLogical XORXRL A, #FFHA = A XOR FFH

Table: Data Transfer Instructions

InstructionFunctionExampleOperation
MOVMove dataMOV A, #50HLoad 50H into A
MOVXMove externalMOVX A, @DPTRLoad from external memory
PUSHPush to stackPUSH ACCPush accumulator to stack
POPPop from stackPOP ACCPop from stack to accumulator

Detailed Examples:

; Logical Instructions
ANL A, #0FH     ; Mask upper nibble
ORL P1, #80H    ; Set bit 7 of Port1
XRL A, #FFH     ; Complement accumulator

; Data Transfer Instructions
MOV R0, #30H    ; Load immediate data
MOVX @DPTR, A   ; Store to external memory
PUSH B          ; Save B register
POP PSW         ; Restore status word

Mnemonic: “AND OR XOR Move External Push Pop”

Question 4(a) OR [3 marks]
#

Explain Instructions: (i) RRC A (ii) POP (iii) CLR PSW.7

Answer:

Table: Instruction Explanations

InstructionFunctionOperationExample
RRC ARotate right through carryA→C, C→A(MSB)A=85H,C=0 → A=42H,C=1
POPPop from stackSP→Register, SP-1POP ACC
CLR PSW.7Clear bit 7 of PSWPSW.7 = 0Clear CY flag
RBARefCftoeArre:O:peAAra==ti[[oDCn7:DD67DD56DD45DD34DD23DD12DD01]]CC==[[CD]0]
  • RRC A: Rotates accumulator right through carry flag
  • POP: Removes top stack element into specified register
  • CLR PSW.7: Clears carry flag (bit 7 of Program Status Word)

Mnemonic: “Rotate Pop Clear”

Question 4(b) OR [4 marks]
#

Write 8051 Assembly Language Program to Divide data stored in location 30H by data stored in location 31H and store remainder in 40h and quotient in 41h memory location.

Answer:

ORG 0000H           ; Program start
LJMP MAIN

ORG 0030H
MAIN:
    MOV A, 30H      ; Load dividend
    MOV B, 31H      ; Load divisor
    DIV AB          ; Divide A by B
    MOV 41H, A      ; Store quotient
    MOV 40H, B      ; Store remainder
    SJMP $          ; Stop here

END

Program Steps:

  1. Load Data: Move dividend and divisor to A and B
  2. Division: Use DIV AB instruction
  3. Store Results: Quotient in A, remainder in B
  4. Save: Store results in specified memory locations

Table: DIV AB Instruction

BeforeAfter
A = DividendA = Quotient
B = DivisorB = Remainder

Mnemonic: “Load Divide Store”

Question 4(c) OR [7 marks]
#

List Addressing Modes of 8051 Microcontroller and Explain each with Example.

Answer:

Table: 8051 Addressing Modes

ModeDescriptionExampleExplanation
ImmediateData in instructionMOV A, #50HLoad 50H into A
RegisterUse registerMOV A, R0Move R0 content to A
DirectMemory address specifiedMOV A, 30HLoad from address 30H
IndirectAddress in registerMOV A, @R0Load from address in R0
IndexedBase + offsetMOVC A, @A+DPTRA = content of (A+DPTR)
RelativePC + offsetSJMP HEREJump relative to PC
BitBit addressSETB P1.0Set bit 0 of Port 1

Detailed Examples:

; Immediate Addressing
MOV A, #25H         ; Load immediate value 25H

; Register Addressing  
MOV A, R7           ; Move register R7 to A

; Direct Addressing
MOV A, 40H          ; Load from memory location 40H

; Indirect Addressing
MOV R0, #50H        ; R0 points to address 50H
MOV A, @R0          ; Load from address pointed by R0

; Indexed Addressing
MOV DPTR, #TABLE    ; Point to lookup table
MOVC A, @A+DPTR     ; Load from table[A]

; Relative Addressing
SJMP NEXT           ; Jump to label NEXT

; Bit Addressing
SETB P2.5           ; Set bit 5 of Port 2

Mnemonic: “Immediate Register Direct Indirect Indexed Relative Bit”

Question 5(a) [3 marks]
#

Draw Interfacing of Relay with 8051 microcontroller.

Answer:

8R0e5lN12NRC+aO.PBeoVyP2NCliCoK5alCCr4yoNt7(nC1tP2aiCVcno)tRBTl1sLearl2ossaeVaiencdsstRtioeCosrlortanoynrection

Table: Interface Components

ComponentFunctionValue
TransistorCurrent amplifierBC547 NPN
ResistorBase current limiter2.2KΩ
RelayElectromagnetic switch12V DC
DiodeBack EMF protection1N4007
  • Operation: Port pin HIGH → Transistor ON → Relay energized
  • Protection: Diode prevents back EMF damage
  • Isolation: Relay provides electrical isolation

Mnemonic: “Transistor Resistor Relay Diode”

Question 5(b) [4 marks]
#

Interface 7 Segment display with 8051 microcontroller and write a program to print “1” on it.

Answer:

PPPPPPPP11111111........0123456787ffee0-agd5Sagd1eagd--------gagdP[[[[[[[[mbbcco33333333er33333333ndt00000000tpΩΩΩΩΩΩΩΩ1]]]]]]]]D--------i--------s--------p--------laabcdefgdyp

Program to Display “1”:

ORG 0000H
LJMP MAIN

ORG 0030H
MAIN:
    MOV P1, #06H    ; Display "1" (segments b,c ON)
    SJMP $          ; Stop here

; Pattern for "1": 00000110 = 06H
; Only segments b and c are ON

END

Table: 7-Segment Display Components

ComponentFunctionValue
Current Limiting ResistorProtect LED segments330Ω
Port ConnectionDigital output controlPort 1
Display PatternSegment controlBinary pattern

Mnemonic: “Current Limit Segment Pattern”

Question 5(c) [7 marks]
#

Interface DAC 0808 with 8051 microcontroller and write a program to generate Square wave.

Answer:

PPPPPPPPPo22222222r........t0123456780251DDDDDDDD01234567DAC08II0ORVVG8UECENTFCED--[[(11+-G0055NOKKVVDpΩΩ)))-O]]Au--mt--pp--uBtufferVout

Program to Generate Square Wave:

ORG 0000H
LJMP MAIN

ORG 0030H
MAIN:
    MOV A, #00H     ; Minimum value (0V)
    MOV P2, A       ; Output to DAC
    CALL DELAY      ; Wait period
    
    MOV A, #0FFH    ; Maximum value (approx 5V)
    MOV P2, A       ; Output to DAC
    CALL DELAY      ; Wait period
    
    SJMP MAIN       ; Repeat for square wave

DELAY:
    MOV R0, #200    ; Delay counter
LOOP1:
    MOV R1, #250    ; Inner loop counter
LOOP2:
    DJNZ R1, LOOP2  ; Inner delay loop
    DJNZ R0, LOOP1  ; Outer delay loop
    RET

END

Table: DAC Interface Specifications

ParameterValueFunction
Resolution8-bit256 output levels
Reference Voltage5VFull scale output
Output Range0-5VAnalog voltage range
Interface TypeParallel8-bit data bus

Square Wave Generation:

  • Low Level: 00H produces approximately 0V output
  • High Level: FFH produces approximately 5V output
  • Frequency: Determined by delay routine duration
  • Output: Clean analog square wave at DAC output

Mnemonic: “Digital Analog Convert Square”

Question 5(a) OR [3 marks]
#

Interface of Push button Switch with 8051 microcontroller.

Answer:

+1SG50WNVKDPPuulPsl1h-.u0Bpu(tR8te0os5ni1sStPwooirrttchPin)

Table: Push Button Interface Components

ComponentValueFunction
Pull-up Resistor10KΩEnsures logic HIGH when switch open
Push ButtonSPST MomentaryUser input device
Logic LevelsHIGH=1, LOW=0Switch open=1, pressed=0

Sample Program:

CHECK_SWITCH:
    JB P1.0, SW_RELEASED    ; Jump if switch not pressed
    ; Switch pressed code here
    CALL SWITCH_PRESSED
    SJMP CHECK_SWITCH

SW_RELEASED:
    ; Switch not pressed code here
    SJMP CHECK_SWITCH

SWITCH_PRESSED:
    ; Action when switch is pressed
    RET

Operation:

  • Switch Open: Pull-up resistor makes pin HIGH (logic 1)
  • Switch Pressed: Pin connected to GND, becomes LOW (logic 0)
  • Debouncing: May require software debouncing for reliable operation

Mnemonic: “Pull-up Switch Ground”

Question 5(b) OR [4 marks]
#

Interface DC Motor with 8051 microcontroller.

Answer:

805T11NIM+N1PPDoV4PKN1CtC0o2oC0r2r7t(1P2iCVno)BBP(l1F((aaoDl2rAPsswaeVec1eeercer.rltDwo0RioChs)eTnressrgMeiatolMsnotiotsnontoi)rgorsrtD)oirode

Motor Control Program:

MOTOR_ON:
    SETB P1.0       ; Turn motor ON
    RET

MOTOR_OFF:
    CLR P1.0        ; Turn motor OFF
    RET

MOTOR_SPEED_CONTROL:
    ; PWM for speed control
    SETB P1.0       ; Motor ON
    CALL DELAY_ON   ; ON time duration
    CLR P1.0        ; Motor OFF  
    CALL DELAY_OFF  ; OFF time duration
    RET

DELAY_ON:
    MOV R0, #100    ; ON time delay
    DJNZ R0, $
    RET

DELAY_OFF:
    MOV R0, #50     ; OFF time delay  
    DJNZ R0, $
    RET

Table: DC Motor Interface Components

ComponentFunctionSpecification
Power TransistorCurrent amplificationTIP122 (Darlington pair)
Base ResistorCurrent limiting1KΩ
Freewheeling DiodeBack EMF protection1N4007
DC MotorLoad device12V DC Motor

Operation Principle:

  • Motor ON: Port pin HIGH → Transistor saturated → Motor runs
  • Motor OFF: Port pin LOW → Transistor cut-off → Motor stops
  • Speed Control: PWM technique varies average power to motor
  • Protection: Diode protects transistor from back EMF

Mnemonic: “Transistor Resistor Diode Motor”

Question 5(c) OR [7 marks]
#

Interface LCD with 8051 microcontroller and write a program to display “Hello”.

Answer:

PPPPPo2222r....t012380251DDDD456716x2LCDDiVVVRERsCD0SN/pCDWlay(((+GCG5NoPPNVDn33D))t..)r01astAdj)

Complete LCD Interface Program:

ORG 0000H
LJMP MAIN

ORG 0030H
MAIN:
    CALL LCD_INIT       ; Initialize LCD
    MOV DPTR, #MESSAGE  ; Point to message string
    CALL DISPLAY_STRING ; Display the message
    SJMP $              ; Stop execution

LCD_INIT:
    CALL DELAY_15MS     ; Wait 15ms after power on
    MOV A, #38H         ; Function set: 8-bit mode, 2 lines, 5x7 matrix
    CALL COMMAND_WRITE
    MOV A, #0EH         ; Display on, cursor on, blink off
    CALL COMMAND_WRITE
    MOV A, #01H         ; Clear display
    CALL COMMAND_WRITE
    MOV A, #06H         ; Entry mode: increment cursor, no shift
    CALL COMMAND_WRITE
    RET

COMMAND_WRITE:
    MOV P2, A           ; Send command to data lines (D4-D7)
    CLR P3.0            ; RS = 0 for command
    SETB P3.1           ; Enable pulse high
    CALL DELAY_1MS
    CLR P3.1            ; Enable pulse low
    CALL DELAY_1MS
    RET

DATA_WRITE:
    MOV P2, A           ; Send data to data lines (D4-D7)
    SETB P3.0           ; RS = 1 for data
    SETB P3.1           ; Enable pulse high
    CALL DELAY_1MS
    CLR P3.1            ; Enable pulse low
    CALL DELAY_1MS
    RET

DISPLAY_STRING:
    CLR A
    MOVC A, @A+DPTR     ; Get character from string
    JZ STRING_END       ; If zero, end of string
    CALL DATA_WRITE     ; Display character
    INC DPTR            ; Point to next character
    SJMP DISPLAY_STRING ; Continue until end

STRING_END:
    RET

MESSAGE: DB "HELLO", 0  ; Message string with null terminator

DELAY_1MS:
    MOV R0, #4          ; Outer loop counter
DEL1: 
    MOV R1, #250        ; Inner loop counter  
DEL2: 
    DJNZ R1, DEL2       ; Inner delay loop
    DJNZ R0, DEL1       ; Outer delay loop
    RET

DELAY_15MS:
    MOV R2, #15         ; 15ms delay counter
DEL15: 
    CALL DELAY_1MS      ; Call 1ms delay
    DJNZ R2, DEL15      ; Repeat 15 times
    RET

END

Table: LCD Control Signals

SignalPinFunction
RSP3.0Register Select (0=Command, 1=Data)
ENP3.1Enable pulse for data latch
R/WGNDRead/Write (tied to GND for write only)
D4-D7P2.0-P2.34-bit data bus (upper nibble)

Table: Important LCD Commands

CommandHex CodeFunction
Function Set38H8-bit mode, 2 lines, 5x7 matrix
Display Control0EHDisplay ON, cursor ON, blink OFF
Clear Display01HClear entire display
Entry Mode06HIncrement cursor, no display shift

LCD Display Process:

  1. Initialization: Configure LCD parameters and clear display
  2. Command Mode: Send commands with RS=0
  3. Data Mode: Send characters with RS=1
  4. Enable Pulse: Latch data/command with EN signal
  5. String Display: Loop through message characters until null terminator

Character Display Steps:

  • Set RS=1 for data mode
  • Put character code on data bus
  • Generate enable pulse (HIGH to LOW)
  • Wait for LCD to process (1ms delay)
  • Repeat for next character

Mnemonic: “Initialize Command Data Enable Display”

Related

Microprocessor & Microcontroller Systems (1333202) - Winter 2023 Solution
21 mins
Study-Material Solutions Microprocessor Microcontroller 1333202 2023 Winter
Electronic Measurements and Instruments (4331102) - Summer 2024 Solution
Study-Material Solutions Electronic-Measurements 4331102 2024 Summer
Linux Operating System (4331602) - Summer 2024 Solution
Study-Material Solutions Linux 4331602 2024 Summer
Communication Engineering (1333201) - Summer 2024 Solution
16 mins
Study-Material Solutions Communication-Engineering 1333201 2024 Summer
Data Structure with Python (4331601) - Summer 2024 Solution
Study-Material Solutions Data-Structure Python 4331601 2024 Summer
Electronic Circuits & Networks (4331101) - Summer 2024 Solution
Study-Material Solutions Electronic-Circuits Networks 4331101 2024 Summer