After first LCALL After PUSH 4 After PUSH 5

CALL
INSTRUCTIONS
Calling
Subroutines
;MAIN program calling subroutines
ORG 0
MAIN: LCALL SUBR_1
LCALL SUBR_2
LCALL SUBR_3
HERE: SJMP HERE
;-----------end of MAIN
SUBR_1: ...
...
RET
;-----------end of subroutine1
SUBR_2: ...
...
RET
;-----------end of subroutine2
SUBR_3: ...
...
RET
;-----------end of subroutine3
END ;end of the asm file
It is common to have one
main program and many
subroutines that are called
from the main program
This allows you to make
each subroutine into a
separate module
- Each module can be
tested separately and then
brought together with
main program
- In a large program, the
module can be assigned to
different programmers

CALL
INSTRUCTIONS
ACALL
􀂉 The only difference between ACALL
and LCALL is
􀂾 The target address for LCALL can be
anywhere within the 64K byte address
􀂾 The target address of ACALL must be
within a 2K-byte range
􀂉 The use of ACALL instead of LCALL
can save a number of bytes of
program ROM space

CALL
INSTRUCTIONS
ACALL
(cont’)
ORG 0
MOV A,#55H ;load A with 55H
BACK: MOV P1,A ;send 55H to port 1
ACALL DELAY ;time delay
CPL A ;complement reg A
SJMP BACK ;keep doing this indefinitely
...
END ;end of asm file
ORG 0
BACK: MOV A,#55H ;load A with 55H
MOV P1,A ;send 55H to port 1
LCALL DELAY ;time delay
MOV A,#0AAH ;load A with AA (in hex)
MOV P1,A ;send AAH to port 1
LCALL DELAY
SJMP BACK ;keep doing this indefinitely
...
END ;end of asm file
A rewritten program which is more efficiently

TIME DELAY
FOR VARIOUS
8051 CHIPS
􀂉 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
􀂉 In original 8051, one machine cycle
lasts 12 oscillator periods
Find the period of the machine cycle for 11.0592 MHz crystal
frequency
Solution:
11.0592/12 = 921.6 kHz;
machine cycle is 1/921.6 kHz = 1.085μs

Post a Comment

0 Comments

Close Menu