To: File

From: Jon Hagen

Date: Oct 2, 2000

Subject: PLC code - sample program

The attached listings are for a demo program that runs in the PLC (CPU928B)

crate. The program was written to gain familiarity with the PLC and its development system. The program requires that, in addition to the CPU928B, a digital output

card be plugged into the crate.

When started, this program runs for 5 seconds. While running, it

turns on Digital Output 0.0. A green LED on the digital output card indicates

that this output is HI. At the end of 10 seconds, the CPU stops. The CPU

run light goes off and Digital Output 0.0 goes low. Note: Thei DIP switch on the digital output card must be set to address set for 0000. (Thus the four digital output bytes provided by this card will be bytes 0,1,2, and 3). In addition, 24 VDC must be connected to the digital output card: positive to pin 3, negative(gnd) to pin 21. This voltage

is needed to light the LED. (It is also the voltage that the card would supply to

a load, e.g. a relay coil). If this voltage is not connected, the progam will still

run, but the LED won't light. However, if the card is not present or if the card address

is not set to 0000, the cpu will immediately STOP, illuminating the red ADF led "Address Fault". The digital output card should be in place at the time the PLC crate is powered up.

The entire program consists of five blocks, OB20, OB21, OB1, FB220, and FB221.

FB 220 -TEST C:JONPRGST.S5D LEN=14

Page 1

Segment 1

Name :TEST

:A -TIMER IF TIMER NOT ZERO

:BEC THEN RETURN

:STP ELSE, STOP

:BE END OF BLOCK

T 2 = TIMER TIMER T2

_________________________________________________________________________________________

FB 221 -START C:JONPRGST.S5D LEN=19

Page 1

Segment 1

Name :START

:L KT 010.2 10 x1SEC

:SE -TIMER START THE TIMER

:A -FLAG LOWER FLAG (3 LINES)

:AN -FLAG FLAG = FLAG AND FLAG*

:= -FLAG

:AN -FLAG TURN ON LAMP

:= -LAMP

:BE BLOCK END

T 2 = TIMER TIMER T2

F 10.0 = FLAG HIGH ON FIRST PASS

Q 0.0 = LAMP LAMP (Q0.0 LED)

________________________________________________________________________________________

OB 1 C:JONPRGST.S5D LEN=12

Page 1

Segment 1 THIS IS OB1

:A -FLAG FIRST TIME THRU?

:JC -START THEN CALL START

Name :START

:***

F 10.0 = FLAG HIGH ON FIRST PASS

FB 221 = START

Segment 2

:JU -TEST

Name :TEST

:BE

FB 220 = TEST TEST FOR TIMEOUT

__________________________________________________________________________________________

OB 20 C:JONPRGST.S5D LEN=10

Page 1

Segment 1 INITIALIZE

THIS SEGMENT IS CALLED BY SIMATIC SYSTEM AT RESET

:O -FLAG

:ON -FLAG

:= -FLAG

:JU OB 1

:BE

F 10.0 = FLAG HIGH ON FIRST PASS

______________________________________________________________________________________

OB 21 C:JONPRGST.S5D LEN=10

Page 1

Segment 1

:O -FLAG SET FLAG = 1

:ON -FLAG (FLAG = FLAG

:= -FLAG OR NOT FLAG)

:JU OB 1 JUMP TO MAIN LOOP

:BE END OF BLOCK

F 10.0 = FLAG HIGH ON FIRST PASS

_________________________________________________________________________________________

[1wFile C:JONXXXZ0.SEQ assignments list Page 1

Operand Symbol Comment

T2 TIMER TIMER T2

Q0.0 LAMP LAMP (Q0.0 LED)

F10.0 FLAG HIGH ON FIRST PASS

FB220 TEST TEST FOR TIMEOUT

FB221 START

____________________________________________________________________________________

cross reference list

[1wX reference list: inputs

Page 1

FB 220 : processed

FB 221 : processed

OB 1 : processed

OB 20 : processed

OB 21 : processed

X reference list: outputs

Page 2

Q 0.0 -LAMP FB221 1*

X reference list: flags

Page 3

F 10.0 -FLAG FB221 1*

OB 1 1

OB 20 1*

OB 21 1*

X reference list: timers

Page 4

T 2 -TIMER FB220 1

FB221 1*

X reference list: blocks

Page 5

FB 220 -TEST OB 1 2

FB 221 -START OB 1 1

OB 1 - OB 20 1

OB 21 1

_____________________________________________________________________________________

[1w P r o g r a m o v e r v i e w w i t h o u t D B

Page 1

FB 220 :-TEST Length : 14

FB 221 :-START Length : 19

OB 1 :- Length : 12

OB 20 :- Length : 10

OB 21 :- Length : 10

Length : PB 0

Length : SB 0

Length : FB 33

Length : FX 0

Length : OB 32

Length : DB 0

Length : DX 0

Length : 65

P r o g r a m o v e r v i e w w i t h o u t D B

Page 2

+-OB 1-+=FB221-

I

+-FB220-

+-OB 20-

+-OB 21-+-OB 1-+=FB221-

I

+-FB220-

[1w I / Q / F l i s t

Page 1

FB 220 : processed

FB 221 : processed

OB 1 : processed

OB 20 : processed

OB 21 : processed

__________________________________________________________________________________

I / Q / F l i s t

Page 2

Existing inputs in program

I7 6 5 4 3 2 1 0 I B W DI I7 6 5 4 3 2 1 0 I B W DI

I----------------I------I I----------------I------I

Byte 0 I- - - - - - - - I - - -I Byte 1 I- - - - - - - - I - - -I

Byte 2 I- - - - - - - - I - - -I Byte 3 I- - - - - - - - I - - -I

Byte 4 I- - - - - - - - I - - -I Byte 5 I- - - - - - - - I - - -I

Byte 6 I- - - - - - - - I - - -I Byte 7 I- - - - - - - - I - - -I

Byte 8 I- - - - - - - - I - - -I Byte 9 I- - - - - - - - I - - -I

Byte 10 I- - - - - - - - I - - -I Byte 11 I- - - - - - - - I - - -I

Byte 12 I- - - - - - - - I - - -I Byte 13 I- - - - - - - - I - - -I

Byte 14 I- - - - - - - - I - - -I Byte 15 I- - - - - - - - I - - -I

Byte 16 I- - - - - - - - I - - -I Byte 17 I- - - - - - - - I - - -I

Byte 18 I- - - - - - - - I - - -I Byte 19 I- - - - - - - - I - - -I

Byte 20 I- - - - - - - - I - - -I Byte 21 I- - - - - - - - I - - -I

Byte 22 I- - - - - - - - I - - -I Byte 23 I- - - - - - - - I - - -I

Byte 24 I- - - - - - - - I - - -I Byte 25 I- - - - - - - - I - - -I

Byte 26 I- - - - - - - - I - - -I Byte 27 I- - - - - - - - I - - -I

Byte 28 I- - - - - - - - I - - -I Byte 29 I- - - - - - - - I - - -I

Byte 30 I- - - - - - - - I - - -I Byte 31 I- - - - - - - - I - - -I

Byte 32 I- - - - - - - - I - - -I Byte 33 I- - - - - - - - I - - -I

Byte 34 I- - - - - - - - I - - -I Byte 35 I- - - - - - - - I - - -I

Byte 36 I- - - - - - - - I - - -I Byte 37 I- - - - - - - - I - - -I

Byte 38 I- - - - - - - - I - - -I Byte 39 I- - - - - - - - I - - -I

Byte 40 I- - - - - - - - I - - -I Byte 41 I- - - - - - - - I - - -I

Byte 42 I- - - - - - - - I - - -I Byte 43 I- - - - - - - - I - - -I

Byte 44 I- - - - - - - - I - - -I Byte 45 I- - - - - - - - I - - -I

Byte 46 I- - - - - - - - I - - -I Byte 47 I- - - - - - - - I - - -I

Byte 48 I- - - - - - - - I - - -I Byte 49 I- - - - - - - - I - - -I

Byte 50 I- - - - - - - - I - - -I Byte 51 I- - - - - - - - I - - -I

Byte 52 I- - - - - - - - I - - -I Byte 53 I- - - - - - - - I - - -I

Byte 54 I- - - - - - - - I - - -I Byte 55 I- - - - - - - - I - - -I

Byte 56 I- - - - - - - - I - - -I Byte 57 I- - - - - - - - I - - -I

Byte 58 I- - - - - - - - I - - -I Byte 59 I- - - - - - - - I - - -I

Byte 60 I- - - - - - - - I - - -I Byte 61 I- - - - - - - - I - - -I

Byte 62 I- - - - - - - - I - - -I Byte 63 I- - - - - - - - I - - -I

I----------------I------I I----------------I------I

REST OF LIST DELETED