Back to the 2023 paper

Module 6: Applications

20237m

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 SolutionAI Assisted

Travelling 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 tick

C (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.

Similar questions

Official AppAndroid App

PYQDeck for Android

Solve BEU previous-year exam papers anywhere, anytime. Fast search, offline paper viewing, and step-by-step solutions designed specifically for your phone.