MICROPROCESSORS
100504Module 6: Applications
Q1i. Interfacing a DC motor generally requires (i) Driver circuit (ii) Counter (iii) Keyboard (iv) Crystal oscillator20252m
Module 6: Applications
View this question on its own page →Interfacing a DC motor generally requires
(i) Driver circuit
(ii) Counter
(iii) Keyboard
(iv) Crystal oscillatorWorked SolutionAnswer: (i) Driver circuit
Explanation: 8051 I/O pins source/sink only ~mA, insufficient for DC motor (hundreds of mA, inductive). Interfacing requires driver circuit (transistor, MOSFET, L293D/L298 motor driver IC) plus flyback diode, not counter/keyboard/crystal.
Q2b. What value should be loaded into timer register so as to have a time delay of 5 ms? Write a program to create a pulse width of 5 ms on pin P2.3. Assume crystal frequency to be 11.0592 MHz.20207m
Module 6: Applications
View this question on its own page →What value should be loaded into timer register so as to have a time delay of 5 ms? Write a program to create a pulse width of 5 ms on pin P2.3. Assume crystal frequency to be 11.0592 MHz.
Worked Solution5 ms Delay Calculation & Program for P2.3 Pulse (11.0592 MHz)
Machine cycle: Fosc/12 = 11059200/12 = 921600 Hz → Tcy = 1.085 µs. Timer increments every 1.085 µs.
Counts needed for 5 ms = 5ms /1.085us = 4608 decimal = 1200H.
For 16-bit timer mode 1: TH:TL = 10000H - 1200H = EE00H. So TH=0EEH, TL=00H. For mode 1 with auto-reload? Use TL load accordingly. Alternative using 50 counts errors small.
If using Timer 0 mode 1:
TH0 = 0EEH, TL0 = 00H yields 5 ms.
For 5 ms high pulse on P2.3:ORG 0000H MAIN: MOV TMOD,#01H ; T0 mode1 16-bit LOOP: SETB P2.3 MOV TH0,#0EEH MOV TL0,#00H SETB TR0 WAIT: JNB TF0,WAIT CLR TR0 CLR TF0 CLR P2.3 ; after 5ms low (or keep high pulse 5ms) MOV TH0,#0EEH MOV TL0,#00H SETB TR0 WAIT2:JNB TF0,WAIT2 CLR TR0 CLR TF0 SJMP LOOP ENDAlternative C:
TH0=0xEE; TL0=0x00;loop. If using 12 MHz crystal, Tcy=1us, counts=5000=1388H, TH=0ECH, TL=78H.
Note: For exact 5ms pulse, set P2.3 high, delay, clear, delay.
If only delay value asked: 4608 counts → EE00H reload.Q2b. Interface 4-digit seven-segment display with 8051 and write a program to display BCD number 1234 on it.20217m
Module 6: Applications
View this question on its own page →Interface 4-digit seven-segment display with 8051 and write a program to display BCD number 1234 on it.
Worked Solution4-Digit Seven-Segment Display Interface with 8051 + Program to Display 1234
Hardware: Common anode/cathode displays via BCD to 7-seg decoder (7447) or direct port driving via current limiting resistors. Use multiplexing: Segments (a-g,dp) to P0 (8 bits), Digit common (COM1-4) via NPN/ULN2003 to P2.0-P2.3. Or use 8255.
Connections: P0.0-P0.7 → a,b,c,d,e,f,g,+dp (or via 74LS244), P2.0→DIG1, P2.1→DIG2, etc., active low/high depending on type. Use multiplexing: enable one digit at a time ~5 ms persistence.
Program (Assembly) to display 1234:
ORG 0000H MOV P0,#00H MOV P2,#00H MAIN: MOV DPTR,#SEG_TABLE MOV R0,#01H ; digit 1 = "1" MOV R1,#02H ; digit 2 = "2" etc for demo constant 1234 ; Multiplex loop LOOP: MOV A,#01H ; enable DIG1 MOV P2,A MOV A,#06H ; code for "1" (common cathode 06H) from table MOV P0,A ACALL DELAY_5MS MOV A,#02H ; DIG2 MOV P2,A MOV A,#5BH ; "2" MOV P0,A ACALL DELAY_5MS MOV A,#04H ; DIG3 "3" MOV P2,A MOV A,#4FH MOV P0,A ACALL DELAY_5MS MOV A,#08H ; DIG4 "4" MOV P2,A MOV A,#66H MOV P0,A ACALL DELAY_5MS SJMP LOOP SEG_TABLE: DB 3FH,06H,5BH,4FH,66H,6DH,7DH,07H,7FH,6FH ; 0-9 CC DELAY_5MS: MOV TH0,#0EEH ; as before MOV TL0,#00H SETB TR0 W: JNB TF0,W CLR TR0 CLR TF0 RET ENDGeneric BCD display routine: Fetch BCD nibbles from memory, look up segment codes, multiplex digits sequentially. Time-division multiplexing with persistence gives steady 1234 view.
Q3b. Demonstrate interfacing of a 4x4 (16-key) keyboard with 8051, with neat circuit diagram and display using 8051 Microcontroller.20247m
Module 6: Applications
View this question on its own page →Demonstrate interfacing of a 4x4 (16-key) keyboard with 8051, with neat circuit diagram and display using 8051 Microcontroller.
Worked Solution4×4 Keypad Interfacing with 8051 + Display
Hardware: Rows R1-R4 → P1.0-P1.3 (output), Columns C1-C4 → P1.4-P1.7 (input with pull-ups) or via P2. Keypad matrix 4×4=16 keys (0-9,A-F or 1-9,* #). Supply decoupling, debounce capacitors.
Scanning Algorithm:
- Drive all rows high.
- Set one row low at a time, read columns. Column low = key pressed at (row, col).
- Debounce 20 ms delay, re-read.
- Compute key code = row*4+col, look up ASCII in table.
- Display on 7-seg/LCD at P0.
Program sketch (assembly):
SCAN: MOV P1,#0F0H ; rows outputs pull? ROW_LOOP: MOV A,#0FEH ; row0 low MOV P1,A MOV A,P1 ANL A,#0F0H CJNE A,#0F0H,FOUND ; next row 0FDH etc FOUND: ; compute MOV DPTR,#KEYMAP MOVC A,@A+DPTR MOV P2,A ; display ACALL DEBOUNCEDisplay: Send decoded hex to LCD via P0 data + P2 control (RS,RW,EN) or to 7-seg via P0 segments + P2 digit select as in Q38. Multiplex display continuously.
Circuit: P1.0-3 via 470Ω to row lines, P1.4-7 via 10k pull-up to Vcc + column lines, optional 74C922 encoder alternative.Q6a. Write a C or assembly language program for 8051 microcontroller to create a travelling light pattern connected at port 0 after every 500 ms. Assume there are 8 LEDs connected to 8 pins of port 0. Initially after startup, the LED connected to Pin 0 should be ON. Then after 500 ms, the next LED should be ON. Only one LED should be ON at a time and remaining should stay OFF. Continue this pattern forever. Assume the crystal frequency to be 12 MHz.20237m
Module 6: Applications
View this question on its own page →Write a C or assembly language program for 8051 microcontroller to create a travelling light pattern connected at port 0 after every 500 ms. Assume there are 8 LEDs connected to 8 pins of port 0. Initially after startup, the LED connected to Pin 0 should be ON. Then after 500 ms, the next LED should be ON. Only one LED should be ON at a time and remaining should stay OFF. Continue this pattern forever. Assume the crystal frequency to be 12 MHz.
Worked SolutionTravelling Light Pattern on Port 0 – 500 ms delay 12MHz
One LED ON at a time moving left→right. Fosc 12MHz → Tcy=1µs, 500ms = 500000 counts = ~7×65536 so use loop with timer + software.
ORG 0000H MOV P0,#01H ; LED0 ON MOV TMOD,#01H LOOP: MOV A,P0 RL A ; rotate left -> next LED MOV P0,A JNB ACC.0,NO_RST ; if wrapped? Actually RL 80H->01H ; delay 500ms ACALL DELAY500 SJMP LOOP DELAY500: ; 500ms via Timer0 loops 50×10ms MOV R7,#50 D500L: MOV TH0,#0DCH ; 10ms =10000 counts → DC00H (12MHz Tcy1us, 65536-10000=55536= D8F0? Need compute; here approximated) MOV TL0,#00H SETB TR0 W: JNB TF0,W CLR TR0 CLR TF0 DJNZ R7,D500L RET END ; Corrected 10ms calc: 10000 decimal=2710H, TH= D8H, TL= F0H for 1us tickC (more accurate using Timer): Loop 500×1ms interrupts, or use Timer ISR with reload. Principle: load 01H to P0, delay, RL A, write.
Calculation: 12MHz → 1 machine cycle 1µs → Timer mode1 16-bit counts to 65536. 500ms needs 500000 counts → 7 overflows + remainder. Easiest: loop 50 times 10ms delay.
Q6b. Interface 4-digit seven-segment display with 8051 and write a program to display BCD numbers from 0-9 after every 1 second.20237m
Module 6: Applications
View this question on its own page →Interface 4-digit seven-segment display with 8051 and write a program to display BCD numbers from 0-9 after every 1 second.
Worked Solution4-Digit Seven-Segment Display 0-9 Sequence (1 sec) – Hardware as Q38
Use multiplexed P0 segments + P2 digit select.
ORG 0000H MOV TMOD,#01H MAIN: MOV R0,#00H ; digit 0 NEXTDIG: MOV A,R0 MOV DPTR,#SEG MOVC A,@A+DPTR MOV P0,A ; segments MOV A,R0 ; multiplex? Actually display single digit repeated or multiplex all 4 with same? ; For 0-9 counter on all digits, display number as 0000-0009 etc - loop multiplex ACALL DELAY_1S_4DIGITS ; time-share INC R0 CJNE R0,#10,NEXTDIG SJMP MAIN SEG: DB 3FH,06H,5BH,4FH,66H,6DH,7DH,07H,7FH,6FH DELAY_1S: ; via timer outer loop 100×10ms MOV R7,#100 L1: MOV TH0,#0D8H MOV TL0,#0F0H SETB TR0 W: JNB TF0,W CLR TR0 CLR TF0 DJNZ R7,L1 RETLogic: Increment 0-9, look up cathode code, output to multiplexed display, 1 sec delay using Timer0 counts. For 4-digit, drive same code to all digits simultaneously or BCD increment with carry.
Q8. With the help of schematic diagram, explain the interfacing of stepper motor with 8051 Microcontroller. Also, write ALP to change the speed and direction of motor.202414m
Module 6: Applications
View this question on its own page →With the help of schematic diagram, explain the interfacing of stepper motor with 8051 Microcontroller. Also, write ALP to change the speed and direction of motor.
Worked SolutionStepper Motor Interfacing with 8051 + ALP for Speed/Direction
Hardware: 4-phase unipolar stepper (e.g., 28BYJ-48) requires driver ULN2003 (Darlington) or L293D; 12V supply, common +12V, 4 coils → ULN2003 outputs 1A-4A→ P1.0-P1.3. Diode protection. Bipolar uses L298 with 2 coils.
Sequence (full-step): Wave: 08H→04H→02H→01H→08H (clockwise), reverse anticlockwise 01→02→04→08. Half-step interleaves. Supply via external.
Circuit description: P1.0-P1.3→ULN2003 IN1-4 → OUT1-4 → motor coils, COM to +12V, GND common.
ALP to control speed/direction:
ORG 0000H MOV TMOD,#01H MAIN: JB P2.0,CLKWISE ; switch on P2.0 selects direction MOV R0,#08H ; start sequence anticlk ACW: MOV P1,R0 ACALL DELAY ; speed control delay value RR A MOV R0,A SJMP MAIN CLKWISE: MOV A,R0 MOV P1,A ACALL DELAY RL A MOV R0,A SJMP MAIN DELAY: MOV TH0,#HIGH(-counts) ; variable counts via potentiometer ADC or fixed R7 ; delay = speed: shorter→faster. Adjust R7 value or TH/TL. ; example 10ms per step = 100 steps/sec RET ENDSpeed: Change delay between steps; shorter delay = faster; Direction: reverse sequence. Use Timer interrupt for precise speed.
Q9b. Write short notes on: Interfacing a stepper motor20237m
Module 6: Applications
View this question on its own page →Write short notes on: Interfacing a stepper motor
Worked SolutionShort Notes: Interfacing Stepper Motor – see Q128
Unipolar/Bipolar via ULN2003/L293D to P1, sequence 08-04-02-01, speed via delay, direction via sequence reversal. Needs external 12V, diode protection.
Q9e. Explain the working and applications of stepper motors.20253.5m
Module 6: Applications
View this question on its own page →Explain the working and applications of stepper motors.
Worked SolutionStepper Motors – Working & Applications
Working: Converts electric pulses to discrete mechanical rotation steps. Stator has multiple coils energized sequentially (full/half/micro-step), rotor (permanent magnet/iron) aligns to magnetic field each pulse, giving precise angular steps (e.g., 1.8° →200 steps/rev for 2-phase). 8051 drives via sequence (as Q128): energize coils in order, no feedback needed (open-loop).
Types: Unipolar (4-5 wires), Bipolar (4 wires), Variable Reluctance.
Applications: Printers, CNC, robotics, cameras, ATMs, medical pumps, textile machines, antenna positioning – where precise position/open-loop control needed, not high speed. Advantages: precise, holding torque, no feedback. Disadvantages: resonance, limited high-speed torque vs servo.