8051 assembly microcontroller rotating bits for LED.

Thread Starter

youdontknowme

Joined May 30, 2017
15
Hi,
my objective is to make the 8 leds (p2.0 , p2.1 , p2.2 ...... p2.7) blink 1 by 1 from left to right.
for example, 0 0 0 0 0 0 0 1 --> 0 0 0 0 0 0 1 0 --> 0 0 0 0 0 1 0 0 --> 0 0 0 0 1 0 0 0 --> 0 0 0 1 0 0 0 0 ---> ..... 1 0 0 0 0 0 0 0
however i'm stuck as only first led (0 0 0 0 0 0 0 1) lights up and it doesn't progress to the light up the next led (0 0 0 0 0 0 1 0).

CODE

Loop:
mov a,#00000001b ;led 1 lights up first.
mov p2,a ;move accumulator to port 2
rl a ;rotate left for accumulator
sjmp Loop ;jump back to loop


what am i doing wrong here ?
 

Papabravo

Joined Feb 24, 2006
21,225
the initialization step is INSIDE the loop. Move the the label Loop down one instruction so that you execute the initialization one time only.
 

Thread Starter

youdontknowme

Joined May 30, 2017
15
the initialization step is INSIDE the loop. Move the the label Loop down one instruction so that you execute the initialization one time only.
Hi, i moved the label loop down to below my delay instruction. but i'm still facing the same problem. only the first led light up and doesn't progress to the next led.
 

Papabravo

Joined Feb 24, 2006
21,225
Hi, i moved the label loop down to below my delay instruction. but i'm still facing the same problem. only the first led light up and doesn't progress to the next led.
No! No! No! You missed the point!

Begin:
mov a,#00000001b ;led 1 lights up first.
Loop:
mov p2,a ;move accumulator to port 2
rl a ;rotate left for accumulator
sjmp Loop ;jump back to loop

What you want is to:
  1. Goto Begin from power on RESET.
  2. Exeute the mov a,#1 -- ONE TIME ONLY
  3. Make the sjmp goto the "mov P2,a" instruction
What was it about my post#2 that was unclear!!??
 
Top