Browse
(440) 299-7778
Menu
(440) 299-7778
One-year parts and labor warranty30-day money-back guaranteeContact

The text of a manual · part 6 of 17

1771-DB Basic Module User Manual, pages 51 to 60

Pages 51 to 60 of 167

The original document is the PDF (943 KB). This is its text as extracted, unedited; tables and drawings read best in the PDF, and each page heading opens it at that page.

For the Allen-Bradley 1771-DB

Page 51

Chapter 5 Operating Functions

5.3.14 Command: PROG1

Action taken: You can use the PROG1 command to program the resident EPROM with baud rate information. When the module is “powered-up” the module reads this information and initializes the program port with the stored baud rate. The “sign-on” message is sent to the console immediately after the module completes its reset sequence. If the baud rate on the console device is changed you must program a new EPROM to make the module compatible with the new console. If you have already used a PROG2 command, you cannot use the PROG 1 command.

5.3.15 Command: PROG2

Action taken: The PROG2 command functions the same as the PROG1 command except for the following. Instead of “signing-on” and entering the command mode, the module immediately begins executing the first program stored in the resident EPROM, if no program is stored in RAM. Otherwise it executes the RAM program. You can use the PROG2 command to RUN a program on power-up without connecting to a console. Saving PROG2 information is the same as typing a ROM 1, RUN command sequence. This feature also allows you to write a special initialization sequence in BASIC and generate a custom “sign-on” message for specific applications. If you have already used a PROG1 command, PROG 2 command.

5–14 you cannot use the

Page 52

Chapter 5 Operating Functions

5.3.15 Command: PROG2 (continued)

Figure 5.1 Flow Chart of Power-up Operation

Figure 5.1 shows BASIC Module operation from a power-up condition using PROG1 or PROG2; or battery backed RAM.

5–15

Page 53

Chapter 5 Operating Functions

5.4 Description of Statements

The following sections list and describe the statements you can use with the BASIC Module.

5.4.1 Statement: CALL [integer]

Mode: COMMAND AND/ OR RUN Type: CONTROL You use the CALL [integer] statement to call specially written BASIC Module application programs. Specific call numbers are defined later in this chapter.

5.4.2 Statement: CLEAR

Mode: COMMAND AND/OR RUN Type: CONTROL The CLEAR statement sets all variables equal to 0 and resets all BASIC evoked interrupts and stacks. This means that after the CLEAR statement is executed an ONTIME statement must be executed before the module acknowledges the internal timer interrupts. ERROR trapping using the ONE RR statement also does not occur until an ONERR[integer] statement is executed. The CLEAR statement does not affect the real time clock that is enabled by the CLOCK1 statement. CLEAR also does not reset the memory that has been allocated for strings, so it is not necessary to enter the STRING [expr], [expr] statement to re-allocate memory for strings after the CLEAR statement is executed. In general, CLEAR is used to “erase” all variables.

5.4.3 Statement: CLEARI (clear interrupts)

Mode: COMMAND AND/OR RUN Type: CONTROL The CLEARI statement clears all of the BASIC evoked interrupts. The ONTIME interrupt disables after the CLEARI statement executes. CLEARI does not affect the real time clock enabled by the CLOCK1 statement. You can use this statement to selectively DISABLE ONTIME interrupts during specific sections of your BASIC program. You must execute the ONTIME statement again before the specific interrupts enable. Important: When the CLEARI statement is LISTED it appears as CLEAR I.

5–16

Page 54

Chapter 5 Operating Functions

5.4.4 Statement: CLEARS

Mode: COMMAND/RUN Type: CONTROL The CLEARS statement resets all of the module’s stacks. The control, argument and internal stacks all reset to their initialization values. You can use this command to reset the stack if an error occurs in a subroutine. Important: When the CLEARS statement is LISTed it appears as CLEAR S.

5.4.5 Statements: CLOCK1 and CLOCK0

Mode: COMMAND AND/OR RUN Type: CONTROL

CLOCK1 The CLOCK1 statement enables the real time clock feature resident on the BASIC Module. The special function operator TIME is incremented once every 5 milliseconds after the CLOCK1 statement is executed. The CLOCK1 STATEMENT uses an internal TIMER to generate an interrupt once every 5 milliseconds. Because of this, the special function operator TIME has a resolution of 5 milliseconds. The special function operator TIME counts from 0 to 65535.995 seconds. After reaching a count of 65535.995 seconds TIME overflows back to a count of zero. The interrupts associated with the CLOCK1 statement cause the module programs to run at about 99.6% of normal speed. That means that the interrupt handling for the REAL TIME CLOCK feature uses about .4% of the total CPU time.

CLOCK0 The CLOCK0 (zero) statement disables or “turns off” the real time clock feature. After CLOCK0 is executed, the special function operator TIME no longer increments. CLOCK0 is the only module statement that can disable the real time clock. CLEAR and CLEARI do NOT disable the real time clock, only its associated ONTIME interrupt. Important: CLOCK1 and CLOCK0 are independent of the wall clock.

5–17

Page 55

Chapter 5 Operating Functions

5.4.6 Statements: DATA – READ – RESTORE

Mode: RUN Type: Assignment

DATA DATA specifies expressions that you can retrieve using a READ statement. If multiple expressions per line are used, you MUST separate them with a comma. Example: u10 DATA 10,ASC(A), ASC(B), 35.627 Important: You cannot use the CHR() operator in a DATA statement.

READ READ retrieves the expressions that are specified in the DATA statement and assigns the value of the expression to the variable in the READ statement. The READ statement is always followed by one or more variables. If more than one variable follows a READ statement, they are separated by a comma.

RESTORE RESTORE “resets” the internal read pointer to the beginning of the data so that it may be read again. Example: u10 FOR I=1 TO 3 u20 READ A,B u30 PRINT A,B u40 NEXT I u50 RESTORE u60 READ A,B u70 PRINT A,B u80 DATA 10,20, 10/2,20/2,SIN(PI),COS(PI) uRUN 10 5 0 10

20 10 –1 20

Every time a READ statement is encountered the next consecutive expression in the DATA statement is evaluated and assigned to the variable in the READ statement. You can place DATA statements anywhere within a program. They are not executed and do not cause an error. DATA statements are considered to be chained together and appear to be one large DATA statement. If at anytime all the data is read and another READ statement is executed, the program terminates and the message ERROR: NO DATA – IN LINE XX prints to the console device.

5–18

Page 56

Chapter 5 Operating Functions

5.4.7 Statement: DIM

Mode: COMMAND AND/OR RUN Type: Assignment DIM reserves storage for matrices. The storage area is first assumed to be zero. Matrices in the BASIC Module may have only one dimension and the size of the dimensioned array may not exceed 254 elements. Once a variable is dimensioned in a program it may not be re-dimensioned. An attempt to re-dimension an array causes an ARRAY SIZE ERROR. If an arrayed variable is used that is not dimensioned by the DIM statement, BASIC assigns a default value of 10 to the array size. All arrays are set equal to zero when the RUN command, NEW command or the CLEAR statement is executed. The number of bytes allocated for an array is 6 times the array size plus 1. The array A(100) requires 606 bytes of storage. Memory size usually limits the size of a dimensioned array. Variations: More than one variable can be dimensioned by a single DIM statement. Example:

u10 DIM A(25), B(15), A1(20) Example: Default error on attempt to re-dimension array u10 A(5)10 –BASIC ASSIGNS DEFAULT OF 10 TO ARRAY SIZE HERE u20 DIM A(5) –ARRAY CANNOT BE RE–DIMENSIONED uRUN ERROR: ARRAY SIZE – IN LINE 20 20

DIM A(5)

-

X

5.4.8 Statements: DO – UNTIL [rel expr]

Mode: RUN Type: CONTROL The DO – UNTIL [rel expr] instruction provides a means of “loop control” within a module program. All statements between the DO and the UNTIL [rel expr] are executed until the relational expression following the UNTIL statement is TRUE. You may nest DO – UNTIL loops.

5–19

Page 57

Chapter 5 Operating Functions

5.4.8 Statements: DO – UNTIL [rel expr] (continued)

Examples: SIMPLE DO-UNTIL

NESTED DO-UNTIL u10 A=0 u20 DO u30 A=A+1 u10 DO u20 A=A+1 u30 DO u40 B=B+1 u50 PRINT A,B,A,*B u60 UNTIL B=3 u70 B=0 u80 UNTIL A=3 u90 END uRUN u40 PRINT A u50 UNTIL A=4 u60 PRINT “DONE” u70 END uRUN 1 2 3 4 DONE READY u

111 122 133 212 224 236 313 326 339 READY u

5–20

Page 58

Chapter 5 Operating Functions

5.4.9 Statements: DO – WHILE [rel expr] (continued)

Mode: RUN Type: CONTROL The DO – WHILE [rel expr] instruction provides a means of “loop control” within a module program. The operation of this statement is similar to the DO – UNTIL [rel expr] except that all statements between the DO and the WHILE [rel expr] are executed as long as the relational expression following the WHILE statement is true. You can nest DO – WHILE and DO – UNTIL statements. Examples: SIMPLE DO-WHILE

NESTED DO-WHILE - DO-UNTIL u10 DO u20 A=A+1 u30 PRINT A u40 WHILE At4 u50 PRINT “DONE” u60 END uRUN u10 DO u20 PRINT A=A+1 u25 DO u30 B=B+1 u40 A,B,A*B u50 WHILE Btu3 u60 B=0 u70 UNTIL A=3 u80 END uRUN 111 122 133 212 224 236 313 326 339

1 2 3 4 DONE READY u

READY u

5–21

Page 59

Chapter 5 Operating Functions

5.4.10 Statement: END

Mode: RUN Type: CONTROL The END statement terminates program execution. The continue comm and, CONT does not operate if the END statement is used to terminate execution. A CAN’T CONTINUE ERROR prints to the console. The last statement in a module program automatically terminates program execution if you do not use an end statement. You should always use an END statement to terminate a program. Examples: END STATEMENT TERMINATION u10 FOR I=1 TO 4 u20 GOSUB 100 u30 NEXT I u40 END u100 PRINT I u110 RETURN uRUN 1 2 3 4 READY u Variations: None

5.4.11 Statements: FOR – TO – (STEP) – NEXT

Mode: RUN Type: CONTROL Use the FOR – TO – (STEP) – NEXT statements to set up and control loops. Example: u5 B=0: C=10 : D=2 u10 FOR A= B TO C STEP D u20 PRINT A u30 NEXT A u40 END

5–22

Page 60

Chapter 5 Operating Functions

5.4.11 Statements: FOR – TO – (STEP) – NEXT (continued)

Since B=0, C=10 and D=2, the PRINT statement at line 20 executes 6 times. The values of “A” printed are 0, 2, 4, 6, 8 and 10. “A” represents the name of the index or loop counter. The value of “B” is the starting value of the index. The value of “C” is the limit value of the index and the value of “D” is the increment to the index. If the STEP statement and the value “D” are omitted, the increment value defaults to 1, therefore, STEP is an optional statement. The NEXT statement adds the value of “D” to the index. The index is then compared to the value of “C”, the limit. If the index is less than or equal to the limit, control transfers back to the statement after the FOR statement. Stepping “backwards” (FOR I= 100 TO 1 STEP–1) is permitted in the BASIC Module. You may not omit the index from the NEXT statement in the module (The NEXT statement is always followed by the appropriate variable). You may nest FOR-NEXT loops up to 9 times. Examples: u10 FOR I=1 TO 4 u20 PRINT I, u30 NEXT I u40 END uRUN 1234

READY u

5.4.12 Statements: GOSUB [ln num] – RETURN u10 FOR I=O TO 8 STEP 2 u20 PRINT I u30 NEXT I u40 END uRUN 0 2 4 6 8 READY u

Mode: RUN Type: CONTROL

GOSUB The GO SUB [ln num] statement causes the BASIC Module to transfer control of the program directly to the line number ([ln num]) following the GOSUB statement. In addition, the GOSUB statement saves the location of the statement following GOSUB on the control stack so that you can perform a RETURN statement to return control to the statement following the most recently executed GO SUB STATEMENT.

5–23