You are on page 1of 19

LAB 3

Problems Faced in Previous Labs

How to Use Port 0?

How to use Single Bit Value (Single Pin of Port)?

How to avoid rewriting delays program repeatedly?


How to Use Port 0?

 Each pin must be connected externally to a 10K


ohm pull-up resistor
How to use Single Bit Value?
Bit Addressable
Subroutine

used to perform tasks that need to be performed


frequently (like functions in C++)
Subroutine
Subroutine

 LCALL (long call)


 Subroutine is located anywhere within 64K byte address space
 ACALL (absolute call)
 Used for address within 2K-byte range

 After finishing execution of the subroutine


 The instruction RET bring back to the caller
 Every subroutine needs RET as the last instruction
Program using Subroutine

 Write a program to blink leds connected to all four


ports by sending ffh and 00h to ports continuously.
Blinking can be produced by introducing delay
between both transfers
 7 x 255 x 255 times
Time Delay Using Loop
 CPU executing an instruction takes a certain number of clock
cycles
 These are referred as to as machine cycles

 The length of machine cycle depends on the frequency of the


crystal oscillator connected to 8051

 one machine cycle takes 12 oscillator periods


Time Delay Using Loop
Time Delay Using Loop
MOV A,#55H
AGAIN: MOV P1,A
ACALL DELAY
CPL A
SJMP AGAIN

;---time delay-------
DELAY:
MOV R3,#200
HERE: DJNZ R3,HERE
RET
Time Delay Using Loop
MOV A,#55H
AGAIN: MOV P1,A
ACALL DELAY
CPL A
SJMP AGAIN

;---time delay-------
DELAY:
MOV R1,#7
HERE3:
MOV R2,#255
HERE2:
Delay = 7 x 255 x 255 x 2MC x 1.085usec= 0.988
MOV R3,#255
sec
HERE1:
DJNZ R3,HERE1
DJNZ R2,HERE2
DJNZ R1,HERE3
RET
Conditional Jump Instructions

Determine

•if P1 contains the value 0. Send 55H to P3 else send AAH


to P3
Format:
CJNE A,#20,LOOP
Compare accumulator with 20. If they are not equal, jump to the address marked as LOOP
HARDWARE
Seven-Segment Display
 The seven-segment display is a numerical display
device used to show digital circuit outputs as decimal
digits. It is called a seven-segment display because it
consists of seven LEDs or liquid crystals.

 We can display any decimal digit by turning on the


appropriate elements, designated by lowercase
letters,
a through g. It is conventional to designate the top segment as a
and progress clockwise around the display, ending with g as the
center element.
 Common Anode Display
A seven-segment LED display where the anodes of all
the LEDs are connected to the circuit supply
voltage. Each segment is activated by a logic LOW at
its cathode.

 Common Cathode Display


A seven-segment display in which the cathodes of all
LEDs are connected together and grounded. Each
segment is activated by a logic HIGH at its anode.
Physical Placement of LEDs
in
Common Anode Display

You might also like