Coursify

Microprocessor

PYQ Analysis and Exam Preparation

1.5 hours

Learning Goals

  • Solve previous year exam questions on LED, LCD, keyboard, stepper motor, DC motor, and sensor interfacing
  • Master circuit design calculations, interfacing diagrams, and programming for peripheral devices
  • Identify important application topics for the upcoming exam

PYQ Analysis — Module 6: Applications

Topic Distribution Analysis

Module 6 carries 8–12 marks in the exam. Focus on:

TopicMarks (Avg)Frequency
Stepper Motor Interfacing3–5 marksVery High
LED/7-Segment Display Interfacing2–4 marksHigh
LCD Interfacing2–3 marksMedium
DC Motor with PWM2–3 marksMedium
Keyboard Matrix2–3 marksMedium
Sensor Interfacing2–3 marksMedium

High-Weightage Questions (Expected Tomorrow)

Q1: Explain stepper motor interfacing with 8051. Write a program to rotate a stepper motor 90 degrees clockwise. (5 marks)

Stepper Motor Basics:

  • Step angle: 1.8 degrees per step → 200 steps/revolution
  • 4 stator coils require driver circuit (ULN2003 Darlington array)
  • Full-step sequence: 4 states per complete electrical cycle

Full-Step Sequence (Clockwise):

StepP1.0P1.1P1.2P1.3Hex
1100109H
211000CH
3011006H
4001103H

Program for 90 degrees (50 steps):

1MOV R0, #50 ; 50 full steps = 90 degrees 2MOV DPTR, #TABLE 3LOOP: MOV R1, #04 ; 4 states per step 4CYCLE: MOV A, #04H 5SUBB A, R1 6MOVC A, @A+DPTR 7MOV P1, A 8CALL DELAY 9DJNZ R1, CYCLE 10DJNZ R0, LOOP 11RET 12TABLE: DB 09H, 0CH, 06H, 03H

Q2: Calculate resistor value for an LED (2V forward drop, 10 mA current). (3 marks)

R = (Vcc - Vf) / I = (5 - 2) / 0.01 = 300 ohms (use 330 ohms standard)

Q3: Write a program to generate PWM for DC motor speed control. (4 marks)

1; 50% duty cycle PWM on P1.0 2MOV TMOD, #01H ; Timer 0, Mode 1 3LOOP: 4SETB P1.0 ; Motor ON 5MOV TH0, #0FCH ; Load for 1 ms ON time 6MOV TL0, #18H 7SETB TR0 8WAIT1: JNB TF0, WAIT1 9CLR TR0 10CLR TF0 11CLR P1.0 ; Motor OFF 12MOV TH0, #0FCH ; Load for 1 ms OFF time 13MOV TL0, #18H 14SETB TR0 15WAIT2: JNB TF0, WAIT2 16CLR TR0 17CLR TF0 18SJMP LOOP

Q4: Explain matrix keyboard interfacing with 8051. (4 marks)

4x4 Matrix = 16 keys using only 8 pins (4 rows + 4 columns):

  1. Rows connected to output port with pull-up resistors
  2. Columns connected to input port
  3. Scan algorithm: Activate one row LOW at a time, read columns
  4. Key press detected when column reads LOW (row-column shorted)
  5. Debounce: Wait 20 ms after first detection, verify again

Scanning logic:

1; Scan all 4 rows 2MOV P1, #0FH ; Rows as output, Columns as input 3MOV R0, #04 ; 4 rows to scan 4MOV R1, #00 ; Row counter 5SCAN: 6MOV A, #0FH 7CPL A 8RL A ; Rotate to next row 9MOV P1, A ; Activate row 10CALL DELAY_20MS 11MOV A, P1 ; Read columns 12ANL A, #0FH ; Mask rows 13CJNE A, #0FH, KEY_DETECTED 14INC R1 15DJNZ R0, SCAN

Q5: Interface an LCD with 8051 in 8-bit mode. (4 marks)

LCD Connections (16x2 alphanumeric LCD):

LCD Pin8051 Connection
D0-D7P2.0-P2.7 (8-bit data bus)
RSP1.0 (0 = command, 1 = data)
RWP1.1 (0 = write, 1 = read)
EP1.2 (Enable pulse)

Initialization sequence:

1MOV A, #38H ; 8-bit, 2 lines, 5x7 font 2CALL CMD_WR 3MOV A, #0EH ; Display ON, cursor ON 4CALL CMD_WR 5MOV A, #06H ; Auto-increment cursor 6CALL CMD_WR 7MOV A, #01H ; Clear display 8CALL CMD_WR

Command write subroutine:

1CMD_WR: 2MOV P2, A ; Send command to data lines 3CLR P1.0 ; RS = 0 (command mode) 4CLR P1.1 ; RW = 0 (write mode) 5SETB P1.2 ; E = 1 6CALL DELAY 7CLR P1.2 ; E = 0 (falling edge latches data) 8RET

Q6: Interface a temperature sensor (LM35) with 8051. (3 marks)

LM35: Output = 10 mV per degree Celsius. At 25 degrees C, output = 250 mV.

Interfacing:

  1. LM35 output → ADC0804 analog input (Vin+)
  2. ADC0804 digital output → 8051 Port 0
  3. ADC reference: Vref/2 = 2.56V (for 0-5V range)
  4. Temperature = (Digital_Value x 5) / 255 x 100 = (Digital_Value x 500) / 255

Quick Revision Notes

  • Stepper motor: 4-state sequence (09H, 0CH, 06H, 03H) for clockwise
  • Reverse sequence (03H, 06H, 0CH, 09H) for counter-clockwise
  • ULN2003 Darlington driver needed for motor coils (high current)
  • LED resistor: Always calculate using Ohm's Law
  • LCD commands: 38H (init), 0EH (display on), 01H (clear), 80H+ (set cursor position)
  • PWM duty cycle: ON_time / (ON_time + OFF_time) x 100%
  • H-bridge (L298N): Controls DC motor direction and speed
  • Debounce: 20 ms delay after first key detection

Knowledge Check

Question 1 of 5
Q1Single choice

How many steps are needed for a stepper motor (1.8 degrees per step) to rotate 90 degrees?