Many people don't realize that it is possible to write a function in the PLC5 and SLC500 processors that you can pass values to and receive an answer back. This is very useful when you have a great deal of code to place in multiple places. Example of adding 100 to a number below:
1) Create a new file for you function routine
2) The first instruction will be an SBR N7: An integer address for holding the number you want to add (N7:10 example) but make it unique or create a new data file with local scope. Then place an output instruction, OTE B/100 for example.
3) Next rung start do an ADD 100 N7:10 N7:11 to add 100 to your number.
4) The final rung is RET N 7:11 N7:11 is the result of the ADD instruction and this will be sent back to the calling JSR below.
5) In your LAD 2 File, add a JSR with your function program file number and add an input parameter of N7:0 at the end of the logic and keep hitting the enter in the graphic until you see Return Parameter and enter N7:1.
6) Put a value in N7:0 and run the program, N7:1 will always show as 100 more than N7:0.
1) Create a new file for you function routine
2) The first instruction will be an SBR N7: An integer address for holding the number you want to add (N7:10 example) but make it unique or create a new data file with local scope. Then place an output instruction, OTE B/100 for example.
3) Next rung start do an ADD 100 N7:10 N7:11 to add 100 to your number.
4) The final rung is RET N 7:11 N7:11 is the result of the ADD instruction and this will be sent back to the calling JSR below.
5) In your LAD 2 File, add a JSR with your function program file number and add an input parameter of N7:0 at the end of the logic and keep hitting the enter in the graphic until you see Return Parameter and enter N7:1.
6) Put a value in N7:0 and run the program, N7:1 will always show as 100 more than N7:0.