The text of a manual · part 13 of 17
1771-DB Basic Module User Manual, pages 121 to 130
Pages 121 to 130 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 121
Chapter 5 Operating Functions
5.10.3 String Support Calls (continued)
5.10.3.6 Replace a String in a String – CALL 65 This routine replaces a string within a string. Three arguments are expected. The first argument is the string number of the string which replaces the string identified by the second argument string number. The third argument is the base string’s string number. There are no return arguments.
u10 REM SAMPLE OF REPLACE STRING IN STRING u20 STRING 1000,20 u30 $(0)=“RED-LINES” u40 $(1)=“RED” u50 $(2)=“BLUE” u60 PRINT “BEFORE: $0=”,$(0) u70 PUSH 2 :REM STRING NUMBER OF THE STRING TO REPLACE WITH u80 PUSH 1 :REM STRING NUMBER OF THE STRING TO BE REPLACED u90 PUSH 0 :REM BASE STRING NUMBER u100 CALL 65 :REM INVOKE REPLACE STRING IN STRING ROUTINE u110 PRINT “AFTER: $0=”,$(0) u120 END RUN BEFORE: $=RED-LINES AFTER: $0=BLUE-LINES READY
5–84
Page 122
Chapter 5 Operating Functions
5.10.3 String Support Calls (continued)
u10 u20 u30 u40 u50 u60 u70 u80 u90 u91 u100 u110
5.10.3.7 Insert String in a String – CALL 66 This routine inserts a string within another string. The call expects three arguments. The first argument is the position at which to begin the insert. The second argument is the string number of the characters inserted into the base string. The third argument is the string number of the base string. This routine has no return arguments.
REM SAMPLE ROUTINE TO INSERT A STRING IN A STRING STRING 500,15 $(0)=“1234590” $(1)=“67890” PRINT “BEFORE: 0$=”,$(0) PUSH 6 :REM POSITION TO START THE INSERT PUSH 1 :REM STRING NUMBER OF THE STRING TO BE INSERTED PUSH 0 :REM BASE STRING NUMBER CALL 66 :REM INVOKE INSERT A STRING IN A STRING REM :REM ROUTINE PRINT “AFTER: 0$=”,$(0) END uRUN BEFORE: 0$=1234590 AFTER: 0$=1234567890 READY
5–85
Page 123
Chapter 5 Operating Functions
5.10.3 String Support Calls (continued)
5.10.3.8 Delete String from a String – CALL 67 This routine deletes a string from within another string. The call expects two arguments. The first argument is the base string number. The second is the string number of the string to be deleted from the base string. This routine has no return arguments. Important: This routine deletes only the first occurrence of the string.
u10 u20 u30 u40 u50 u60 u70 u80 u90 u100
REM ROUTINE TO DELETE A STRING IN A STRING STRING 200,14 $(1)=“123456789012” $(2)=“12” PRINT “BEFORE: $1=“,$(1) PUSH 1 :REM BASE STRING NUMBER PUSH 2 :REM STRING NUMBER OF THE STRING TO BE DELETED CALL 67 :REM INVOKE STRING DELETE ROUTINE PRINT “AFTER: $1=”,$(1) END uRUN BEFORE: $1=123456789012 AFTER: $1=3456789012 READY
5–86
Page 124
Chapter 5 Operating Functions
5.10.3 String Support Calls (continued)
u10 u20 u30 u40 u50 u60 u70 u80
5.10.3.9 Determine Length of a String – CALL 68 This routine determines the length of a string. One input argument is expected. This is the string number on which the routine acts. One output argument is required. It is the actual number of non-carriage return (CR) characters in this string. This is similar to the BASIC command LEN(str$). (Example: L=LEN($1)).
REM SAMPLE OF STRING LENGTH STRING 100,10 $(1)=“1234567” PUSH 1 :REM BASE STRING CALL 68 :REM INVOKE STRING LENGTH ROUTINE POP L :REM GET LENGTH OF BASE STRING PRINT “THE LENGTH OF ”,$(1),“ IS ”,L END uRUN THE LENGTH OF 1234567 IS 7 READY
5.11 Memory Support Calls
The following sections list and describe the memory support calls you can use with the BASIC Module. All strings, arrays and variables are shared.
5–87
Page 125
Chapter 5 Operating Functions
5.11.1 ROM to RAM Program Transfer – CALL 70
This routine shifts program execution from a running ROM program to the beginning of the RAM program. No arguments are PUSHed or POPed. Important: The first line of the RAM program is not executed. We recommend that you make it a remark. Example: ROM #5 u10 REM SAMPLE ROM PROG FOR CALL 70 u20 PRINT “NOW EXECUTING ROM #5” u30 CALL 70 :REM GO EXECUTE RAM u40 END RAM u10 REM SAMPLE RAM PROGRAM FOR CALL 70 u20 PRINT “NOW EXECUTING RAM” u30 END uRUN NOW EXECUTING ROM #5 NOW EXECUTING RAM
5.11.2 ROM/RAM to ROM Program Transfer – CALL 71
This routine transfers from a running ROM or RAM program to the beginning of any available ROM program. One argument is PUSHed (which ROM program). None are POPed. An invalid program error displays and you enter the command mode if the ROM number does not exist. Important: The first line of the ROM program is not executed. We recommend that you make it a remark. Example:
u10 u20 u30 u40 u50
REM THIS ROUTINE WILL CALL AND EXECUTE A ROM ROUTINE INPUT “ENTER ROM ROUTINE TO EXECUTE ”,N PUSH N CALL 71 END uRUN ENTER ROM ROUTINE TO EXECUTE 4
5–88
Page 126
Chapter 5 Operating Functions
5.11.2 ROM/RAM to ROM Program Transfer – CALL 71 (continued)
The user is now executing ROM 4 if it exists. If the ROM routine requested does not exist the result is:
5.11.3 RAM/ROM Return – CALL 72
This routine allows you to return to the ROM or RAM routine that called this ROM or RAM routine. Execution begins on the line following the line that CALLed the routine. No arguments are PUSHed or POPed. This routine works one layer deep. You may go back to the last CALLing program’s next line.
PROGRAM NOT FOUND. READY u
Important: There must be a next line in the ROM or RAM routine, otherwise unpredictable events could occur which may destroy the contents of RAM. For this reason always be sure that at least one END statement exists following a Call 70 or 71. Example: uROM #1 u10 u20 u30 u40 u50 u60
REM SAMPLE PROG FOR CALL 72 PRINT “NOW EXECUTING ROM #1 PUSH 3 CALL 71 :REM EXECUTE ROM #3 THEN RETURN PRINT “EXECUTING ROM #1 AGAIN” END
ROM #3 u10 u20 u30 u40
REM THIS LINE WONT BE EXECUTED PRINT “NOW EXECUTING ROM #3” CALL 72 END
With ROM #1 selected: uRUN NOW EXECUTING ROM #1 NOW EXECUTING ROM #3 EXECUTING ROM #1 AGAIN READY u
5–89
Page 127
Chapter 5 Operating Functions
5.11.4 Battery-backed RAM Disable – CALL 73
CALL 73 disables the battery-backed RAM, prints “Battery Backup Disabled” when executed and allows a purging reset. The next power loss destroys the contents of RAM. When power is reapplied, RAM is cleared and battery back-up is reenabled automatically.
5.11.5 Battery-backed RAM Enable – CALL 74
CALL 74 enables the battery-backed RAM and prints “Battery Backup Enabled” when executed. It is enabled on power-up and remains enabled until you execute a CALL 73 or until the battery fails.
5.11.6 Protected Variable Storage – CALL 77
Important: Change MTOP from command mode only to ensure proper operation CALL 77 reserves the top of RAM memory for protected variable storage. Values are saved if BATTERY-BACKUP is invoked. You store values with the ST @ command and retrieve them with the LD @ command. Each variable stored requires 6 bytes of storage space. You must subtract 6 times the number of variables to be stored from MTOP reducing available RAM memory. This value is PUSHed onto the stack as the new MTOP address. All appropriate variable pointers are reconfigured. Do this only in command mode. Important: Do not let the ST @ address write over the MTOP address. This could alter the value of a variable or string. Example: For saving 2 variables.
uPRINT MTOP 14335 uPRINT MTOP-12 14323 uPUSH 14323:REM NEW MTOP ADDRESS uCALL 77 u10 K = 678 * PI u15 L =520 PUSH K u30 ST @ 14335:REM STORE K IN PROTECTED AREA u40 PUSH L u50 ST @ 14329 u55 REM TO RETRIEVE PROTECTED VARIABLES u60 LD@ 14335:REM REMOVE K FROM PROTECTED AREA u70 POP K u80 LD@ 14329 u90 POP L u100 REM USE LD@ AFTER POWER LOSS AND BATTERY BACK-UP IS USED
5–90
Page 128
Chapter 5 Operating Functions
5.11.6 Protected Variable Storage – CALL 77 (continued)
Example: For using protected variable storage area. A. Scalar Variables Push all variables in one line: uPRINT MTOP 14335 uPRINT MTOP-24 14311 uPUSH 14311:REM NEW MTOP ADDRESS CALL 77 90 M1=14335 : REM BEGIN STORING HERE 100 PUSH A, B, C, D Use the ST @ and LD @ commands in a DO loop:
u200 DO u210 ST @ M1 u220 M1=M1-6 : REM EACH VARIABLE =6 BYTES u230 UNTIL M1=MTOP: REM YOU DEFINED THE NEW MTOP W/CALL 77 u290 M1=14335 u300 DO u310 LD @ M1 u320 M1 = M1-6 u330 UNTIL M1 = MTOP u360 POP A, B, C, D u370 PRINT A, B, C, D
5–91
Page 129
Chapter 5 Operating Functions
5.11.6 Protected Variable Storage – CALL 77 (continued)
B. Arrays Use an array to set up the data uPRINT MTOP 14335 uPRINT MTOP-24 14311 uPUSH 14311:REM NEW MTOP ADDRESS CALL 77 100 DIM A(4) 110 DATA 10, 20, 30, 40 120 FOR I=1 TO 4: READ A(I) : NEXT I Use ST@ and LD @ commands in a DO loop: u190 M1=14335 u200 DO u210 PUSH A(I) : ST @ M1 u220 I = I+1 : M1 = M1-6 u230 UNTIL I = 4 u290 M1=14335 u300 DO u310 LD @ M1 : POP A(I) u320 PRINT A(I) u330 I = I+1 : M1 = M1-6 u340 UNTIL I 10
5.12 Miscellaneous Calls
The following sections list and describe the miscellaneous calls you can use with the BASIC Module.
5.12.1 Program Port Baud Rate – CALL 78
CALL 78 allows you to change the program port baud rate from its default value (1200 baud) to one of the following: 300, 600,1200, 2400, 4800, 9600 or 19.2 K baud. PUSH the desired baud rate and CALL 78. The program port remains at this baud rate unless CALL 73 is invoked or the battery is removed and power is cycled. If this happens the baud rate defaults to 1200 baud. Example: u10 PUSH 4800 u20 CALL 78
5–92
Page 130
Chapter 5 Operating Functions
5.12.2 Blink the Active LED by Default – CALL 79
The Active LED is on constantly during program execution or command mode. When you issue a CALL 79 the Active LED remains on while a program executes and blinks every second when the module is in the command mode. Issue CALL 79 again to cancel the blinking LED.
5.12.3 Check Battery Condition – CALL 80
CALL 80 checks the module’s battery condition. If a 0 is POPed after a CALL 80, battery is okay. If a 1 is POPed a low battery condition exists. Example: u10 u20 u30 u40
5.12.4 User PROM Check and Description – CALL 81
CALL 80 POP C IF C tu0 THEN PRINT “BATTERY LOW” END
Use CALL 81 before burning a program into PROM memory. This routine: determines the number of PROM programs. determines the number of bytes left in PROM. determines the number of bytes in the RAM program. prints a message telling if enough space is available in PROM for the RAM program. checks PROM validity if no program is found. prints a good or bad PROM message. A bad PROM message with an address of 00xx indicates an incomplete program. cannot detect a defective PROM. No PUSHes or POPs are needed.
5–93