You are on page 1of 8

LED INTERFACING

Interfacing comprises of hardware (Interface device) and Software


(source code to communicate, also called as the Driver).
Simply, to use an LED as the output device, LED should be connected to
Microcontroller port and the MC has to be programmed inside make
LED ON or OFF or blink.
Light Emitting Diodes or LEDs are the mostly commonly used
components in many applications, mostly used for signal transmission
/power indication purposes.
It is very cheaply and easily available in a variety of shape, color, and
size.
The LEDs are also used for design message display boards and traffic
control signal lights etc.
It has two terminals positive and negative as shown in the figure.
Observe carefully the interface LED interface 2 is in forward biased
because the input voltage of 5v connected to the positive terminal of the
LED, So here the Microcontroller pin should be at LOW level and vice
versa with the LED interface 1 connections.
LED INTERFACING WITH 8051
PROGRAM FOR BLINKING OF LEDS
ORG 00H ; Assembly Starts from 0000H.
START: MOV P1, #0FFH ; Move 11111111 to PORT1.
ACALL WAIT ; Call WAIT
MOV A, P1 ; Move P1 value to ACC
CPL A ; Complement ACC
MOV P1, A ; Move ACC value to P1
ACALL WAIT ; Call WAIT
SJMP START ; Jump to START
WAIT: MOV R2, #10 ; Load Register R2 with 10 (0x0A)
WAIT1: MOV R3, #200 ; Load Register R3 with 10 (0xC8)
WAIT2: MOV R4, #200 ; Load Register R4 with 10 (0xC8)
WAIT3: DJNZ R4, WAIT3 ; Decrement R4 till it is 0. Stay there if not 0.
DJNZ R3, WAIT2 ; Decrement R3 till it is 0. Jump to WAIT2 if not 0.
DJNZ R2, WAIT1 ; Decrement R2 till it is 0. Jump to WAIT1 if not 0.
RET ; Return to Main Program
END ; End Assembly
SEVEN SEGMENT DISPLAY
7 segment LED display is very popular and it can display digits
from 0 to 9 and quite a few characters like A, b, C, ., H, E, e, F, n,
o, t, u, y, etc.
A seven segment display consists of seven LEDs arranged in the
form of a squarish 8 slightly inclined to the right and a single
LED as the dot character.
Different characters can be displayed by selectively glowing the
required LED segments.
Seven segment displays are of two types, common cathode and
common anode.
In common cathode type, the cathode of all LEDs are tied
together to a single terminal which is usually labeled as .
In common anode type, the anode of all LEDs are tied together
as a single terminal and cathodes are left alone as individual pins.
SEVEN SEGMENT DISPLAY INTERFACING

Since these are basically LEDs arranged as a group they can


either have the anode in common or cathode thus they are
named as Common-Anode/Common-Cathode displays.

Common Cathode: In this type of segments all the cathode


terminals are made common and tied to GND. Thus the
segments a to g needs a logic High signal(5v) in order to
glow.

Common Anode: In this type of segments all the anodes


terminals are made common and tied to VCC(5v). Thus the
segments a to g needs a logic LOW signal(GND) in order to
glow.
Assembly language program to interface seven segment display (0-9) when it
connected to port1
ORG 0000H
MAIN: MOV DPTR, #400H
REPEAT: CLR A
MOVC A, @A+DPTR ; Copy data from external location to accumulator
MOV P1, A ; Move the pattern of the digit into port P1
ACALL DELAY ; Call a delay to so that the transition is visible
INC DPTR ; Point to the next pattern
CJNE A, 0, REPEAT ; Repeat till 0 (Stop bit) is received
SJMP MAIN ; Run this forever till externally stopped
DELAY:
MOV R0, #08H
LP2: MOV R1, #0FFH
LP1: MOV R2, #0FFH
LP3: DJNZ R2, LP3
DJNZ R1, LP1
DJNZ R0, LP2
RET
ORG 400H
DB 3FH, 06H, 5BH, 4FH, 66H, 6DH, 7DH, 07H, 7FH, 6FH, ; Lookup table for digits 0 to 9
END
Write a program to display
by using seven
segment display while it is
connected to port 0 of 8051.
ORG 0000H
MAIN: MOV DPTR, #200H
MOV R0,#05H
REPEAT: CLR A
MOVC A, @A+DPTR ; Copy data from external location to accumulator
MOV P0, A ; Move the pattern of the digit into port 0
ACALL DELAY ; Call a delay to so that the transition is visible
INC DPTR ; Point to the next pattern
DJNZ R0, REPEAT ; Repeat till R0 = 0
SJMP MAIN ; Run this forever till externally stopped

DELAY:
MOV R0, #08H
LP2: MOV R1, #0FFH
LP1: MOV R2, #0FFH
LP3: DJNZ R2, LP3
DJNZ R1, LP1
DJNZ R0, LP2
RET

ORG 200H
DB 76H, 79H, 38H, 38H, 3FH ; Lookup table for alphabets

You might also like