SCRNUM Encoding a Siemens OP Screen Number into Flags with a Function Block Written for a Siemens S5 PLC An Automation List PLC Archive Document • • • • • • • • • Author: Document Date: Date Originally Written: Type: PLC Model: Application History: Known Problems: Current Revision: Algorithm Source: Michael Griffin 23-JUL-2000 1997 PLC subroutine. Siemens S5 series (used with Siemens text OP). More than 3 dozen systems in current use. None. 1998. The algorithm was created for this application. This document describes a simple method of determining which is the current screen displayed on a Siemens text OP (operator panel with display and keypad). These OPs include the OP20, OP5, OP15, OP7, or OP17. It is often convenient to determine this screen number in order to limit specified actions to when a particular screen is selected by the operator. The screen number can be determined by examining a byte the operator writes into the PLC memory. However, examining an integer repeatedly is often not convenient. The function block described here converts this integer into a series of flags. For example, when screen ten is displayed, bit ten in a selected word can be turned on, while the remaining bits are turned off. Also included in this function block is the ability to include a screen number offset as a parameter to allow this block to be called multiple times. This means the block can be used to decode more than sixteen screens. Application Example The following is an example showing the function block being called from within a program block. Notice that it is being called unconditionally. In this example, the OP uses data words in data block DB42 as its interface area. • • • DB042:DW002 is the "OP Screen Number Word". This is the word the OP uses to signal which screen it is currently displaying. OFST = Constant 16D is the "offset". This is the offset which is subtracted from the OP screen number before it is converted into a bit position. FW006 is a word which other logic elsewhere in the program reads to determine which screen is currently displayed. If screen 17 is displayed (note the offset is 16), then F7.0 will be turned on (an S5 PLC addresses flag words as pair of sequential bytes). If screen 32 is displayed, then F6.7 will be turned on. Note that screen numbers begin from 1 on a Siemens OP. This function block can be called as many times as necessary, but of course different parameters must be used with each instance. I typically put these calls into a program block (PB) which contains other miscellaneous OP functions PB002 SEGMENT 8 Determine which screen is currently displayed on the OP. | +JUMP TO SUBROUTINE--+ | | FB212 SCRNUM | | | | | | | [---------------------------------------] [----------| |SCNO: DB042:DW002 | | |IN | | | | | | | | | | [ | [----------| |OFST: Constant | | |IN 16 D | | | | | | [ | | | | | [ | | | | | | | |BPOS: FW006 | |OUT OP SCREEN | | NUMBER | | 17-32 FW6 | | | | | +--------------------+ Algorithm The algorithm can be reduced to as follows: 1) Check the screen number for a valid number (zero is not a valid screen number). 2) Subtract the offset from the lower byte of the screen number word. 3) Perform a range check. 4) Left shift a '1' by the calculated amount. Note that in a Siemens S5 PLC, the 'DO' instruction can be used to modify the operation of the instruction following. FB Source Code FB212 Michael Griffin 1998 Convert the screen integer number to a binary pattern (0 - 15). SCNO - Integer number representing the screen number. OFST - Offset to subtract from actual screen number. BPOS - One bit is set in this word which represents SCNO with bit 0 indicating screen 1, and bit 15, screen 16. (e.g. SCNO=4, BPOS=0000 0000 0000 1000). SEGMENT 1 NAME: DECL: DECL: DECL: SCRNUM SCNO I, W OFST D, KF BPOS Q, W : ;RESET DEFAULTS : L KH 0000 : T FW254 : T =BPOS : : L =SCNO : !=F : BEC : : L KH 00FF : AW : LW =OFST : -F : D 1 : L KF +15 : >F : BEC : TAK : L KF +0 : <F : BEC : TAK : : T FY255 : L KH 0001 : DO FW254 : SLW 0 : T =BPOS : : BE ;Screen number input. ;Screen number offset. ;Output screen indicator. ;Reset a scratch word. ;Reset the result. ;Load the screen number. ;Is it equal to zero? ;If so, exit. ;Mask off the upper byte, ;lower byte contains screen number. ;Subtract the screen offset. ;Change range from 1-16 to 0-15. ;Is it greater than 15? ;If so, then exit. ;Is it less than 0? ;If so, then exit. ;else, transfer it to a scratch word. ;Convert this to a bit position. ;Transfer the result to the output. Note: I have not experienced any problems with the program code in this document in my own applications so far. I have provided this example for illustrative purposes only. You are free to use the information in this document for your own purposes, but in doing so you must of course accept complete responsibility for any problems, bugs, unintended consequences, etc. you may encounter. In other words, use at your own risk.
* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project