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

The text of a manual · part 8 of 17

1771-DB Basic Module User Manual, pages 71 to 80

Pages 71 to 80 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 71

Chapter 5 Operating Functions

5.4.22 Special Print Formatting Statements (continued)

5.4.22.4 PRINT USING (special characters) Use the USING function to tell the BASIC Module what format to use when displaying printed values. The module “stores” the desired format after the USING statement is executed. All outputs following a USING statement are in the format evoked by the last USING statement executed. You do not need to execute the USING statement within every PRINT statement unless you want to change the format. U. is a “shorthand” notation for USING. Important: The USING statement applies to numbers following it until another USING statement is encountered.

5.4.22.5 PRINT USING(Fx) This forces the BASIC Module to output all numbers using the floating point format. The value of x determines how many significant digits are printed. If x equals 0, the module does not output any trailing zeros, so the number of digits varies depending upon the number. The module always outputs at least 3 significant digits even if x is 1 or 2. The maximum value for x is 8. Example: u10 PRINT USING(F3),1,2,3 u20 PRINT USING(F4),1,2,3 u30 PRINT USING(F5),1,2,3 u40 FOR I=10 TO 40 STEP 10 u50 PRINT I u60 NEXT I uRUN 1.00 E 0 2.00 E 0 3.00 E 0 1.000 E 0 2.000 E 0 3.000 E 0 1.0000 E 0 2.0000 E 0 3.0000 E 0 1.0000 E+1 2.0000 E+1 3.0000 E+1 4.0000 E+1 READY

5–34

Page 72

Chapter 5 Operating Functions

5.4.22 Special Print Formatting Statements (continued)

5.4.22.6 PRINT USING(#.#) This forces the module to output all numbers using an integer and/or fraction format. The number of “#”’s before the decimal point represents the number of significant integer digits that are printed and the number of “#”’s after the decimal point represents the number of digits that are printed in the fraction. Omit the decimal point to print integers only. You may use the abbreviation U for USING. USING(###.###), USING(######) and USING(######.##) are all valid in the BASIC Module. The maximum number of “#” characters is 8. If the module cannot output the value in the desired format (usually because the value is too large) a question mark (?) is printed to the console device. BASIC then outputs the number in the FREE FORMAT described below (refer to section 5.4.22.7). Example: u10 PRINT USING(##.##),1,2,3 u20 FOR I=1 TO 120 STEP 20 u30 PRINT I u40 NEXT I u50 END uRUN 1.00 2.00 3.00 1.00 21.00 41.00 61.00 81.00 ? 101 READY Important: The USING(Fx) and the USING(#.#) formats always “align” the decimal points when printing a number. This makes displayed columns of numbers easy to read.

5.4.22.7 PRINT USlNG(0) This argument lets the BASIC Module determine what format to use. If the number is between +/–99999999 and +/–.1, BASIC displays integers and fractions. If it is out of this range, BASIC uses the USING (F0) format. Leading and trailing zeros are always suppressed. After reset, the module is placed in the USING(0) format.

5–35

Page 73

Chapter 5 Operating Functions

5.4.22 Special Print Formatting Statements (continued)

5.4.22.8 Reset Print Head Pointer – CALL 99 You can use CALL 99 when printing out wide forms to reset the internal print read/character counter and prevent the automatic CR/LF at character 79. You must keep track of the characters in each line. You can solve this problem in revision A or B modules using DBY(1 6H) 0 Example: u10 REM THIS PRINTS TIME BEYOND 80TH COLUMN u20 PRINT TAB (79), u30 CALL 99 40 PRINT TAB (41), “TIME –”, u50 PRINT H , “:” , M , “:” ,S u60 GOTO 20 u70 END

5.4.23 Statement: PRINT# or P.#

Mode: COMMAND and/or RUN Type: INPUT/OUTPUT The PRINT# (PRINT @) or P.# statement functions the same as the PRINT or P. statement except that the output is directed to the list device instead of the console device. The baud rate and peripheral port parameters must match your device. See Chapter 3 Section 3.2.4 titled, “Configuration Plugs” and Chapter 5 Section 5.8.1 titled, “Peripheral Port Support – Parameter Set – CALL 30″. All comments that apply to the PRINT or P. statement apply to the PRINT# or P.# statement. P.# is a “shorthand” notation for PRINT#.

5–36

Page 74

Chapter 5 Operating Functions

5.4.24 Statements: PH0., PH1., PH0.#, PH1.#

Mode: COMMAND and/or RUN Type: INPUT/OUTPUT The PH0. and PH1. statements function the same as the PRINT statement except that the values are printed out in a hexadecimal format. The PH0. statement suppresses two leading zeros if the number printed is less than 255 (0FFH). The PH1. statement always prints out four hexadecimal digits. The character “H” is always printed after the number when PH0. or PH1. is used to direct an output. The values printed are always truncated integers. If the number printed is not within the range of valid integer (i.e. between 0 and 65535 (0FFFFH) inclusive), the BASIC Module defaults to the normal mode of print. If this happens no “H” prints out after the value. Since integers are entered in either decimal or hexadecimal form the statements PRINT, PH0., and PH1. are used to perform decimal to hexadecimal and hexadecimal to decimal conversion. All comments that apply to the PRINT statement apply to the PH0. and PH1. statements. PH0.# and PH 1.# function the same as PH0. and PH1. respectively, except that the output is directed to the list device instead of the console device. The baud rate and peripheral port parameters must match your device. See Chapter 3 Section 3.2.4 titled, “Configuration Plugs” and Chapter 5 Section 5.8.1 titled, “Peripheral Port Support – Parameter Set – CALL 30″. Examples: uPH0.2*2 uPH1.2*2 uPRINT 99 H uPH0.100

04H

0004H

153

64H uPH0. 1000 uPH1. 1000 uP. 3E8H uPH0.PI

3E8H

03E8H

1000

03H

5–37

Page 75

Chapter 5 Operating Functions

5.4.25 Statement: PUSH[expr]

Mode: COMMAND AND/OR RUN Type: ASSIGNMENT The arithmetic expression, or expressions, following the PUSH statement are evaluated and then placed in sequence on the BASIC Module’s ARGUMENT STACK. This statement, in conjunction with the POP statement, provides a simple means of passing parameters to assembly language routines. In addition, the PUSH and POP statements are used to pass parameters to BASIC subroutines and to “SWAP” variables. The last value PUSHed onto the ARGUMENT STACK is the first value POPed off the ARGUMENT STACK. Variations: You can push more than one expression onto the ARGUMENT stack with a single PUSH statement. The expressions are followed by a comma: PUSH[expr],[expr],......... [expr]. The last value PUSHed onto the ARGUMENT STACK is the last expression [expr] encountered in the PUSH STATEMENT. Examples:

SWAPPING CALL VARIABLES ROUTINE u10 A=10 u10 PUSH 3 u20 B=20 u20 CALL 10 u30 PRINT A,B u30 POP W u40 PUSH A,B u40 REM PUSH VALUE ON STACK, CALL u50 POP A,B u50 REM CONVERSION, POP RESULT IN W u60 PRINT A,B u60 END u70 END uRUN 10 20 20 10 READY u

5–38

Page 76

Chapter 5 Operating Functions

5.4.26 Statement: POP[var]

Mode: COMMAND AND/OR RUN TYPE: ASSIGNMENT The value on top of the ARGUMENT STACK is assigned to the variable following the POP statement and the ARGUMENT STACK is “POPed” (i.e. incremented by 6). You can place values on the stack using either the PUSH statement or assembly language CALLS. Important: If a POP statement executes and no number is on the ARGUMENT STACK, an A-STACK ERROR occurs. Variations: You can pop more than one variable off the ARGUMENT stack with a single POP statement. The variables are followed by a comma (i.e. POP [var],[var], ............ [var]). Examples: See PUSH statement above (section 5.4.25). You can use the PUSH and POP statements to minimize GLOBAL variable problems. These are caused by the “main” program and all subroutines used by the main program using the same variable names (i.e. GLOBAL VARIABLES). If you cannot use the same variables in a subroutine as in the main program you can re–assign a number of variables (i.e. A=Q) before a GOSUB statement is executed. If you reserve some variable names just for subroutines (S1, S2) and pass variables on the stack as shown in the previous example, you can avoid any GLOBAL variable problems in the BASIC Module. The PUSH and POP statements accept dimensioned variables A(4) and S1(12) as well as scalar variables. This is useful when large amounts of data must be PUSHed or POPed when using CALL routines. Example: u40 FOR I=1 TO 64 u50 PUSH I u60 CALL 10 u70 POP A(I) u80 NEXT I

5–39

Page 77

Chapter 5 Operating Functions

5.4.27 Statement: REM

Mode: COMMAND and/or RUN Type: CONTROL – Performs no operation REM is short for REMark. REM allows you to add comments to a program to make it easier to understand. If a REM statement appears on a line the entire line is used for the REM statement. You cannot terminate a REM statement using a colon (:), however, you can place a REM statement after a colon. This allows you to place a comment on each line. Example: u10 REM INPUT ONE VARIABLE u20 INPUT A u30 REM INPUT ANOTHER VARIABLE u40 INPUT B u50 REM MULTIPLY THE TWO u60 Z=A*B u70 REM PRINT THE ANSWER u80 PRINT Z u90 END u10 INPUT A: REM INPUT ONE VARIABLE u20 INPUT B : REM INPUT ANOTHER VARIABLE u30 Z=A*B : REM MULTIPLY THE TWO u40 PRINT Z :REM PRINT THE ANSWER u50 END The following example does NOT work because the entire line is interpreted as a REMark. The PRINT statement is not executed: Example: u10 REM PRINT THE NUMBER: PRINT A Important: REMark statements add time to program execution. Use them selectively or place them at the end of the program where they do not affect program execution speed. Do not use REMark statements in frequently called loops or subroutines.

5–40

Page 78

Chapter 5 Operating Functions

5.4.28 Statement: RETI

Mode: RUN Type: CONTROL Use the RETI statement to exit from the ONTIME interrupts that are handled by a BASIC Module program. The RETI statement functions the same as the RETURN statement except that it also clears a software interrupt flag so interrupts can again be acknowledged. If you fail to execute the RETI statement in the interrupt procedure, all future interrupts are ignored.

5.4.19 Statement: ST@ [expr]

Mode: COMMAND AND/OR RUN

5.4.30 Statement: STOP

Mode: RUN Type: CONTROL

This statement, along with CALL 77, allows you to save/retrieve variables to/from a protected area of memory. This protected area is not zeroed on power-up or when the RUN command is issued. The ST@ statement takes the argument on top of the argument stack and moves it to the address location specified by [expr]. For more information on protecting variables, see section 5.11.6, “Protected Variable Storage – CALL 77”.

The STOP statement allows you to break program execution at specific points in a program. After a program is STOPped you can display or modify variables. You can resume program execution with a CONTinue command. The purpose of the STOP statement is to allow for easy program “debugging” More details of the STOP-CONT sequence are covered in Section 5.3.2 titled, “Command: CONT”. Example: u10 FOR I=1 TO 100 u20 PRINT I u30 STOP u40 NEXT I uRUN 1 STOP – IN LINE 40 READY uCONT 2

5–41

Page 79

Chapter 5 Operating Functions

5.4.30 Statement: STOP (continued)

Note that the line number printed out after execution of the STOP statement, is the line number following the STOP statement, not the line number that contains the STOP statement.

5.4.31 Statement: STRING

Mode: COMMAND and/or RUN Type: CONTROL The STRING [expr], [expr] statement allocates memory for strings. Initially, no memory is allocated for strings. If you attempt to define a string with a statement such as LET $(1)“HELLO” before memory is allocated for strings, a MEMORY ALLOCATION ERROR is generated. The first expression in the STRING [expr],[expr] statement is the total number of bytes you want to allocate for string storage. The second expression gives the maximum number of bytes in each string. These two numbers determine the total number of defined string variables. The BASIC Module requires one additional byte for each string, plus one additional byte overall. The additional character for each string is allocated for the carriage return character that terminates the string. This means that the statement STRING 100,10 allocates enough memory for 9 string variables, ranging from $(0) to $(8) and all of the 100 allocated bytes are used. Note that $(0) is a valid string in the BASIC Module. Refer to the following Section 5.10 titled, “Description of String Operators” for further discussion of strings and example programs for string memory allocation. Important: After memory is allocated for string storage, commands (e.g. NEW) and statements (e.g. CLEAR) cannot “de-allocate” this memory. Cycling power also cannot de-allocate this memory unless battery backup is disabled. You can de-allocate memory by executing a STRING 0,0 statement. STRING 0,0 allocates no memory to string variables. Important: The BASIC Module executes the equivalent of a CLEAR statement every time the STRING [expr],[expr] statement executes. This is necessary because string variables and numeric variables occupy the same external memory space. After the STRING statement executes, all variables are “wiped-out”. Because of this, you should perform string memory allocation early in a program (during the first statement if possible). If you re-allocate string memory you destroy all defined variables.

5–42

Page 80

Chapter 5 Operating Functions

5.5 Description of Arithmetic, and Logical Operators and Expressions

The BASIC Module contains a complete set of arithmetic and logical operators. We divide the operators into two groups, dual operand (dyadic) operators and single operand (unary) operators.

5.5.1 Dual Operand (dyadic) Operators

The general form of all dual operand instructions is: (expr) OP (expr), where OP is one of the following operators. + Addition Operator Example: PRINT 3+2 5 / Division Operator Example: PRINT 100/5 20 ** Exponentiation Operator The Exponentiation Operator raises the first expression to the power of the second expression. The maximum power to which you raise a number is 255. Example: PRINT 2**3 8 * Multiplication Operator Example: PRINT 3*3 9 – Subtraction Operator Example: PRINT 9–6 3 .AND. Logical AND Operator Example: PRINT 3.AND.2 2 .OR. Logical OR Operator Example: PRINT 1.OR.4 5. .XOR. Logical EXCLUSIVE OR operator Example: PRINT 7.XOR.6 1

5–43