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:
| Topic | Marks (Avg) | Frequency |
|---|---|---|
| Stepper Motor Interfacing | 3–5 marks | Very High |
| LED/7-Segment Display Interfacing | 2–4 marks | High |
| LCD Interfacing | 2–3 marks | Medium |
| DC Motor with PWM | 2–3 marks | Medium |
| Keyboard Matrix | 2–3 marks | Medium |
| Sensor Interfacing | 2–3 marks | Medium |
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):
| Step | P1.0 | P1.1 | P1.2 | P1.3 | Hex |
|---|---|---|---|---|---|
| 1 | 1 | 0 | 0 | 1 | 09H |
| 2 | 1 | 1 | 0 | 0 | 0CH |
| 3 | 0 | 1 | 1 | 0 | 06H |
| 4 | 0 | 0 | 1 | 1 | 03H |
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):
- Rows connected to output port with pull-up resistors
- Columns connected to input port
- Scan algorithm: Activate one row LOW at a time, read columns
- Key press detected when column reads LOW (row-column shorted)
- 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 Pin | 8051 Connection |
|---|---|
| D0-D7 | P2.0-P2.7 (8-bit data bus) |
| RS | P1.0 (0 = command, 1 = data) |
| RW | P1.1 (0 = write, 1 = read) |
| E | P1.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:
- LM35 output → ADC0804 analog input (Vin+)
- ADC0804 digital output → 8051 Port 0
- ADC reference: Vref/2 = 2.56V (for 0-5V range)
- 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?