Alternate Flashing of 8 LEDs using 8051

Alternate Flashing of 8 LEDs using 8051




Assembly Program:

ORG 0

MOV A, #55H

AGAIN: MOV P0, A

ACALL DELAY

CPL A

SJMP AGAIN

DELAY: MOV R2, #7

HERE1: MOV R1, #255

HERE2: MOV R0, #255

HERE3: DJNZ R0, HERE3

DJNZ R1, HERE2

DJNZ R2, HERE1

RET

END


Delay Calculation:

Crystal used- 4 MHz

Machine cycle frequency = (Crystal Frequency) / (Clocks per machine cycle)

= 4/12

= 0.3333 MHz

Time Period of Machine Cycle = 1/0.33

= 3.003us (microseconds)

No. of machine cycles = 1(for MOV A, #55H) + 1(for MOV P0, A)

= 2 cycles

Total Delay = 7 * 255 * 255 * 2 * 3.003

= 2733781.05us

= 2.73 seconds

Thus the LEDs will show alternate blinking after every 2.73 seconds; the delay can be adjusted as per the requirement by just varying the values of registers R0, R1 or R2.

Why alternate blinking?

Initially value at P0 = #55h

55h in binary- 0 1 0 1 0 1 0 1.

Thus LEDs status is-

LED 1- 0(low) : GLOW

LED 2- 1(high) : OFF

LED 3- 0(low) : GLOW

LED 4- 1(high) : OFF

LED 5- 0(low) : GLOW

LED 6- 1(high) : OFF

LED 7- 0(low) : GLOW

LED 8- 1(high) : OFF


After delay of 2.7 seconds CPL A is executed

Now Value at P0 = #AAh

AAh in binary- 1 0 1 0 1 0 1 0

Thus LEDs status is-

LED 1- 1(high) : OFF

LED 2- 0(low) : GLOW

LED 3- 1(high) : OFF

LED 4- 0(low) : GLOW

LED 5- 1(high) : OFF

LED 6- 0(low) : GLOW

LED 7- 1(high) : OFF

LED 8- 0(low) : GLOW

Share on Google Plus

About sNova

This is a short description in the author block about the author. You edit it by entering text in the "Biographical Info" field in the user admin panel.

0 comments:

Post a Comment

Thanks for your Valuable comment