C Language Function Block
C Language Function Block
9-1.Functions Summary
9-2.Instrument Form
9-3.Operation Steps
9-6.Example Program
9-7.Application Points
9-8.Function List
9-1.Summary
This is the new added function in XCPPro software. This function enable the
customers to write function blocks with C language in XCPPo; and call the function
blocks at any necessary place. This function supports most of C language functions,
strength the program’s security. As users can call the function at many places and call
different functions, this function increase the programmer’s efficiency greatly.
9-2.Instruction Format
1、Instruction Summary
Call the C language Func Block at the specified place
Call the C language Func Block [NAME_C]
16 bits NAME_C 32 bits -
Instruction Instruction
Execution Normally ON/OFF, Suitable XC1、XC2、XC3、XC5、
Condition Rising/Falling Edge Models XCM
activation
Hardware V3.0C and above Software V3.0C and above
Requirement Requirement
2、Operands
Operands Function Type
S1 name of C Func Block, defined by the user String
S2 Correspond with the start ID of word W in C language 16bits, BIN
Function
S3 Correspond with the start ID of word B in C language 16bits, BIN
Function
l The name is composed by numbers, letters and underlines, the first character
can’t be numbers, the name’s length shouldn’t longer than 8 ASC.
l The name can’t be same with PLC’s self instructions like LD,ADD,SUB,PLSR
etc.
l The name can’t be same with the func blocks exist in current PLC;
9-3.Operation Steps
1、Open PLC edit tool, in the left “Project” toolbar, choose “Func Block”, right click it
and choose”Add New Func Block”
l Parameters’ transfer format: if call the Func Block in ladder, the transferred D
and M is the start ID of W and B. Take the above graph as the example, start with
D0 and M0, then W[0] is D0, W[10] is D10, B[0 is M0, B[10]is M10. If in the
ladder the used parameters are D100, M100, then W[0] is D100, B[0]is M100.
So, word and bit component’s start address is defined in PLC program by the
user.
l Parameter W: represent Word soft component, use in the form of data group. E.g.
W[0]=1;W[1]=W[2]+W[3]; in the program, use according to standard C language
rules.
l Parameter B: represent Bit soft component, use in the form of data group.
Support SET and RESET. E.g: B[0]=1;B[1]=0; And assignment, for example
B[0]=B[1]。
l Double-word operation: add D in front of W, e.g. DW[10]=100000, it means
assignment to the double-word W[10]W[11]
l Floating Operation: Support the definition of floating variable in the function, and
execute floating operation;
l Function Library: In Func Block, users can use the Functions and Variables in
function library directly. For the Functions and Variables in function library, see
the list in Appendix.
l The other data type supported:
BOOL; //BOOL Quantity
INT8U; //8 bits unsigned integral
INT8S; //8 bits signed integral
INT16U //16 bits unsigned integral
INT16S //8 bits signed integral
INT32U //32 bits unsigned integral
INT32S //32 bits signed integral
FP32; //Single precision Floating
FP64; // Doubleprecision Floating
l Predefined Marco #define true 1
#define false 0
#define TRUE 1
#define FALSE 0
1、Export
(1) Function: export the function as the file, then other PLC program can import to use;
(2) Export Format
a) Editable; export the source codes out and save as a file. If import again, the file is editable;
b) Not editable: don’t export the source code, if import the file, it’s not editable;
2、Import
Function; Import the exist Func Block file, to use in the PLC program;
Choose the Func Block, right click “Import Func Block From Disk”, choose the correct file,
then click OK.
Example: Add D0 and D1 in PLC’s registers, then assign the value to D2;
(1) In “Project” toolbar, new create a Func Block, here we name the Func Block as
ADD_2, then edit C language program;
(2) Click compile after edition
The information list
According to the information shown in the output blank, we can search and modify the
grammar error in C language program. Here we can see that in the program there is no “;” sign
behind W[2]=W[0]+W[1];
Compile the program again after modify the program. In the information list, we can corfirm
that there is no grammar error in the program;
(3) Write PLC program, assign value 10 and 20 into registers D0, D1 separately, then call Func
Block ADD_2, see graph below:
(4) Download program into PLC, run PLC and set M0.
(5) From Free Monitor in he toolbar, we can see that D2 changes to be 30, it means the assignment
is successful;
Free Monitor
9-6.Program Example
9-7.Application Points
l When upload the PLC program in which there are some Func Blocks, the Func
Blocks can’t be uploaded, there will be an error say: There is an unknown
instruction;
l In one Func Block file, you can write many subsidry functions, can call each
other;
l Each Func Block files are independent, they can’t call its owned functions;
l Func Block files can call C language library functions in form of floating,
arithmetic like sin, cos, tan etc.
9-8.Function Table