Advertisement
mskram

XOR4

Sep 5th, 2019
2,937
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SCL 0.72 KB | None | 0 0
  1. FUNCTION "XOR4" : BOOL
  2. TITLE = 4 way XOR - OON
  3. { S7_Optimized_Access := 'TRUE' }
  4. AUTHOR : MSKRAM
  5. VERSION : 0.1
  6. //One and Only One
  7.    VAR_INPUT
  8.       IN1 : BOOL;
  9.       IN2 : BOOL;
  10.       IN3 : BOOL;
  11.       IN4 : BOOL;
  12.    END_VAR
  13.  
  14.    VAR_OUTPUT
  15.       MoreThanOne : BOOL;   // More than one active inputs
  16.       ActiveInputs : USInt;   // Number of active inputs
  17.    END_VAR
  18.  
  19.    VAR_TEMP
  20.       usiCount : USInt;
  21.    END_VAR
  22.  
  23.  
  24. BEGIN
  25.     #usiCount := 0;
  26.    
  27.     IF #IN1 THEN #usiCount += 1; END_IF;
  28.     IF #IN2 THEN #usiCount += 1; END_IF;
  29.     IF #IN3 THEN #usiCount += 1; END_IF;
  30.     IF #IN4 THEN #usiCount += 1; END_IF;
  31.    
  32.     #ActiveInputs := #usiCount;
  33.     #MoreThanOne := #usiCount > 1;
  34.     #XOR4 := (#usiCount = 1);
  35.    
  36. END_FUNCTION
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement