iBiJe

                          11011110101011011011111011101111

## LIFT (1 / 2)

  FUNCTION_BLOCK uRS
  VAR_INPUT
    SET: BOOL;
    RST: BOOL;
  END_VAR
  VAR_OUTPUT
    Q: BOOL;
  END_VAR
  
  |   SET     RST       Q    |
  |---| |-----|/|------( )---|
  |        |
  |    Q   |
  |---| |--
  
  
  FUNCTION_BLOCK uT
  VAR_INPUT
    X: BOOL;
  END_VAR
  VAR_OUTPUT
    Q: BOOL;
  END_VAR
  VAR
    M1: BOOL;
    M2: BOOL;
  END_VAR

  |   X        M2        M1    |
  |---| |------|/|-------( )---|
  |                            |
  |   X                  M2    |
  |---| |----------------( )---|
  |                            |
  |   Q      M1          Q     |
  |---|/|----| |---------( )---|
  |                 |          |
  |   Q      M1     |          |
  |---| |----|/|----           |
  

  FUNCTION_BLOCK PETROV
  VAR_INPUT
    RUN: BOOL;
  END_VAR
  VAR_OUTPUT
    X: BOOL;
  END_VAR
  VAR
    PAUSE: TP;
    PULSE: TP;
  END_VAR
  
  |                         PULSE                |
  |   RUN      X           -------         X     |
  |---| |------| |--------|IN TP Q|--------( )---|
  |                 T#1s -|PT   ET|-             |
  |                        -------               |
  |                                              |
  |                         PAUSE                |
  |   RUN      X           -------         X     |
  |---| |------|/|--------|IN TP Q|--------(/)---|
  |                 T#1s -|PT   ET|-             |
  |                        -------               |
  |                                              |


  FUNCTION_BLOCK CNT
  VAR_INPUT
    aUP: BOOL;
    aDN: BOOL;
  END_VAR
  VAR_OUTPUT
    a: BOOL;
    b: BOOL;
    c: BOOL;
    d: BOOL;
    e: BOOL;
    f: BOOL;
    g: BOOL;
  END_VAR
  VAR
    Q: INT := 0;
    oldUP: BOOL := FALSE;
    oldDN: BOOL := FALSE;
    x3: BOOL;
    x2: BOOL;
    x1: BOOL;
    x0: BOOL;
  END_VAR
  
  IF NOT oldUP AND aUP THEN
    IF Q < 15 THEN Q := Q + 1; END_IF
  END_IF
  IF NOT oldDN AND aDN THEN
    IF Q > 0 THEN Q := Q - 1; END_IF
  END_IF

  x3 := Q.3;
  x2 := Q.2;
  x1 := Q.1;
  x0 := Q.0;

  a := NOT x2 AND NOT x0 OR NOT x3 AND x1 OR NOT x3 AND x2 AND x0 OR
       x2 AND x1 OR x3 AND NOT x2 AND NOT x1 OR x3 AND NOT x0;
  b := NOT x3 AND NOT x2 OR NOT x3 AND NOT x1 AND NOT x0 OR NOT x2 AND
       NOT x0 OR NOT x3 AND x1 AND x0 OR x3 AND NOT x1 AND x0;
  c := NOT x3 AND NOT x1 OR NOT x3 AND x0 OR NOT x1 AND x0 OR NOT x3 AND
       x2 OR x3 AND NOT x2;
  d := NOT x3 AND NOT x2 AND NOT x0 OR NOT x2 AND x1 AND x0 OR x2 AND
       NOT x1 AND x0 OR x2 AND x1 AND NOT x0 OR x3 AND NOT x1;
  e := NOT x2 AND NOT x0 OR x1 AND NOT x0 OR x3 AND x1 OR x3 AND x2;
  f := NOT x1 AND NOT x0 OR NOT x3 AND x2 AND NOT x1 OR x2 AND NOT x0 OR
       x3 AND NOT x2 OR x3 AND x1;
  g := NOT x2 AND x1 OR x1 AND NOT x0 OR NOT x3 AND x2 AND NOT x1 OR x3
       AND NOT x2 OR x3 AND x0;

  oldDN := aDN;
  oldUP := aUP;


  FUNCTION_BLOCK BIN2UNARY
  VAR_INPUT
    x0: BOOL;
    x1: BOOL;
    x2: BOOL;
    x3: BOOL;
  END_VAR
  VAR_OUTPUT
    y0: BOOL;
    y1: BOOL;
    y2: BOOL;
    y3: BOOL;
    y4: BOOL;
    y5: BOOL;
    y6: BOOL;
    y7: BOOL;
    y8: BOOL;
    y9: BOOL;
    yA: BOOL;
    yB: BOOL;
    yC: BOOL;
    yD: BOOL;
    yE: BOOL;
    yF: BOOL;
  END_VAR
  VAR
  END_VAR

    y0 := NOT x3 AND NOT x2 AND NOT x1 AND NOT x0;
    y1 := NOT x3 AND NOT x2 AND NOT x1 AND     x0;
    y2 := NOT x3 AND NOT x2 AND     x1 AND NOT x0;
    y3 := NOT x3 AND NOT x2 AND     x1 AND     x0;
    y4 := NOT x3 AND     x2 AND NOT x1 AND NOT x0;
    y5 := NOT x3 AND     x2 AND NOT x1 AND     x0;
    y6 := NOT x3 AND     x2 AND     x1 AND NOT x0;
    y7 := NOT x3 AND     x2 AND     x1 AND     x0;
    y8 :=     x3 AND NOT x2 AND NOT x1 AND NOT x0;
    y9 :=     x3 AND NOT x2 AND NOT x1 AND     x0;
    yA :=     x3 AND NOT x2 AND     x1 AND NOT x0;
    yB :=     x3 AND NOT x2 AND     x1 AND     x0;
    yC :=     x3 AND     x2 AND NOT x1 AND NOT x0;
    yD :=     x3 AND     x2 AND NOT x1 AND     x0;
    yE :=     x3 AND     x2 AND     x1 AND NOT x0;
    yF :=     x3 AND     x2 AND     x1 AND     x0;


  PROGRAM PLC_PRG
  VAR
    ON: BOOL;
    OFF: BOOL;
    vRS: RS;
    QRS: BOOL;
    QT: BOOL;
    vT: uT;
    vPET: PETROV;
    AUTO: BOOL;
    vT0: uT;
    QT0: BOOL;
    vT1: uT;
    QT1: BOOL;
    QT2: BOOL;
    vT2: uT;
    vB2U: BIN2UNARY;
    QB0: BOOL;
    QB1: BOOL;
    QB2: BOOL;
    QB3: BOOL;
    QB4: BOOL;
    QB5: BOOL;
    QB6: BOOL;
    QB7: BOOL;
    QB8: BOOL;
    QB9: BOOL;
    QBA: BOOL;
    QBB: BOOL;
    QBC: BOOL;
    QBD: BOOL;
    QBE: BOOL;
    QBF: BOOL;
    vB2S: BIN2SEVEN;
    Q7A: BOOL;
    Q7B: BOOL;
    Q7C: BOOL;
    Q7D: BOOL;
    Q7E: BOOL;
    Q7F: BOOL;
    Q7G: BOOL;
  END_VAR
  
  |                vRS                    |
  |            -----------                |
  |    ON     |     RS    |       QRS     |
  |----| |----|SET      Q1|-------( )-----|
  |           |           |               |
  |    OFF ---|RESET1     |               |
  |            -----------                |
  |                                       |
  |                vPET                   |
  |            -----------                |
  |    AUTO   |  PETROV   |       QT      |
  |----| |----|RUN       X|-------(/)-----|
  |            -----------                |
  |                                       |
  |                vT0                    |
  |            -----------                |
  |    QT     |    uT     |       QT0     |
  |----|/|----|X         Q|-------(/)-----|
  |            -----------                |
  |                                       |
  |                vT1                    |
  |            -----------                |
  |    QT0    |    uT     |       QT1     |
  |----|/|----|X         Q|-------(/)-----|
  |            -----------                |
  |                                       |
  |                vT2                    |
  |            -----------                |
  |    QT1    |    uT     |       QT2     |
  |----|/|----|X         Q|-------(/)-----|
  |            -----------                |
  |                                       |
  |                vB2U                   |
  |            -----------                |
  |    QT     | BIN2UNARY |       QB0     |
  |----| |----|x0       y0|-------( )-----|
  |     QT0 --|x1       y1|-- QB1         |
  |     QT1 --|x2       y2|-- QB2         |
  |     QT2 --|x3       y3|-- QB3         |
  |           |         y4|-- QB4         |
   ..
  |           |         yF|-- QBF         |
  |            -----------                |
  |                                       |
  |                vB2S                   |
  |            -----------                |
  |    QT     | BIN2SEVEN |       Q7A     |
  |----| |----|x0        a|-------( )-----|
  |     QT0 --|x1        b|-- Q7B         |
  |     QT1 --|x2        c|-- Q7C         |
  |     QT2 --|x3        d|-- Q7D         |
  |           |          e|-- Q7E         |
  |           |          f|-- Q7F         |
  |           |          g|-- Q7G         |
  |            -----------                |
  