Dhynesh J - 715522243017
Write an 8051 program to create a left-to-right LED
chaser effect on Port 2 using logical shift
Algorithm:
1. Initialize the microcontroller.
2. Set Port 2 as output.
3. Start with the leftmost bit (0x01).
4. Output this bit to Port 2.
5. Wait using a delay.
6. Perform a logical left shift (i.e., << 1).
7. If the shifted value exceeds 0x80, reset it to 0x01.
8. Repeat the process infinitely.
Delay function:
1. MOV R7, #100 ; Outer loop count (adjust for longer delay)
2. OUTER_LOOP:
3. MOV R6, #200 ; Inner loop count (adjust for fine-tuning delay)
4. INNER_LOOP:
5. DJNZ R6, INNER_LOOP ; Decrement R6 until zero
6. DJNZ R7, OUTER_LOOP ; Decrement R7, repeat outer loop if not zero
7. RET.
Program:
ORG 0000H ; Start of the program
MOV P2, #00H ; Clear Port 2
MOV A, #01H ; Start with first LED ON
MAIN:
MOV P2, A ; Output to Port 2
ACALL DELAY ; Call delay
RL A ; Logical Left Shift (Rotate Left through Carry)
CJNE A, #00H, NEXT
MOV A, #01H ; Reset to first LED if all shifted out
NEXT:
SJMP MAIN ; Repeat forever
; Delay routine
DELAY:
MOV R2, #255
MOV R3, #255
D1: DJNZ R3, D1
DJNZ R2, D1
RET
OUTPUT: