Advanced Function Instruction
7 -5 0
FUN 67
P
CALL
CALL
FUN 67
P
CALL
LBL : The subroutine label name to be called.
z
When call control “EN”=1 or “EN
↑
” (
P
instruction) changes from 0
→
1, PLC will call (perform) the
subroutine bear the same label name as the one being called. When execute the subroutine, the program
will execute continuous as normal program does but when the program encounter the RTS instruction then
the flow of the program will return back to the address immediately after the CALL instruction.
z
All the subroutines must end with one “return from
subroutine instruction RTS” instruction; otherwise it
will cause executing error or CPU shut down.
Nevertheless, an RTS instruction can be shared by
subroutines (so called as multiple entering
subroutines; even though the entry points are
different, they have a same returning path) as
illustrated in the right diagram subroutine SUB1
~
3.
z
When main program called a subroutine, the
subroutine also can call the other subroutines (so
called the nested subroutines) for up to 5 levels at
the most (include the interrupt routine).
1X
2X
3X
4X
5X
RTS
RTS
RTS
RTS
Main program area
Subroutine area
CALL SUB1
LBL SUB1
CALL SUB2
CALL SUB3
CALL SUB4
LBL SUB2
LBL SUB3
LBL SUB4
65
LBL
SUB1
Program 1
65
LBL
SUB2
Program 2
66
JMP
SUB3
65
LBL
SUB3
Program 3
68
RTS
SUB3
SUB2
+
SUB1
z
Interrupt
service
programs
(
HSC0I
~
HSC7I
、
PSO0I
~
PSO3I
、
X0+I
~
X15+I
/
INT0
~
INT15
、
X0
−
I
~
X15
−
I
/
INT0
−
~
INT15
−
、
HSTAI
/
ATMRI
、
1MSI
/
1MS
、
2MSI
/
2MS
、
3MSI
/
3MS
、
4MSI
/
4MS
、
5MSI
/
5MS
、
10MSI
/
10MS
、
50MSI
/
50MS
、
100MSI
/
100MS
)
are also a kind of subroutine. It is also placed in sub
program area. However, the calling of interrupt service program is triggered off by the signaling of
hardware to make the CPU perform the corresponding interrupt service program (which we called as the
calling of the interrupt service program). The interrupt service program can also call subroutine or
interrupted by other interrupts with higher priority. Since it is also a subroutine (which occupied one level),
it can only call or interrupted by 4 levels of subroutine or interrupt service program. Please refer to RTI
instruction for explanation.