MODE: COMMAND AND/OR RUN
TYPE: CONTROL
The BAUD [expr] statement is used to set the baud rate for the software line printer port resident on the MCS BASIC-52 device. In order for this STATEMENT to properly calculate the baud rate, the crystal (special function operator - XTAL) must be correctly assigned (e.g. XTAL = 9000000). MCS BASIC-52 assumes a crystal value of 11.0592 MHz if no XTAL value is assigned. The software line printer port is P1.7 on the 8052AH device. The main purpose of the software line printer port is to let the user make a "hard copy" of program listings and/or data. The COMMAND LIST# and the STATEMENT PRINT# direct outputs to the software line printer port. If the BAUD [expr] STATEMENT is not executed before a LIST# or PRINT# command/statement is entered, the output to the software line printer port will be at about 1 BAUD and it will take A LONG TIME to output something. You may even think that BASIC has crashed, but it hasn't. It's just outputting at a VERY SLOW rate. So be sure to assign a BAUD rate to the software printer port BEFORE using LIST# or PRINT#. The maximum baud rate that can be assigned by the BAUD statement depends on the crystal. In general, 4800 is a reasonable maximum baud rate, however the user may want to experiment with different rates. The software serial transmits 8 data bits, 1 start bit, and two stop bits. No parity is transmitted.
EXAMPLE:
>BAUD 1200
Will cause the line printer port to output data at 1200 BAUD.
MODE: COMMAND AND/OR RUN
TYPE: CONTROL
The CALL [integer] STATEMENT is used to call an assembly language program. The integer following CALL is the address where the user must provide the assembly language routine. To return to BASIC the user must execute an assembly language RET i nstruction. Examples of how to use the CALL [integer] instruction are given in the ASSEMBLY LANGUAGE LINKAGE section of this manual.
EXAMPLE:
>CALL 5000H
Will cause the 8052AH to execute the assembly language program beginning at location 5000H (i.e. the program counter will be loaded with 5000H).
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 ONEX1 or ONTIME statement must be executed before MCS BASIC-52 will acknowledge interrupts. ERROR trapping via the ONERR statement will also not occur until an ONERR[integer] STATEMENT is executed. The CLEAR STATEMENT does not affect the real time clock that is enabled by the CLOCK 1 STATEMENT. CLEAR also does not reset the me mory 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 simply used to "erase" all variables.
STATEMENTS: CLEARI (clear interrupts) CLEARS (clear stacks)
MODE: COMMAND AND/OR RUN
TYPE: CONTROL
CLEARI
The CLEARI STATEMENT clears all of the BASIC evoked interrupts. Specifically, the ONTIME and ONEX1 interrupts are DISABLED after the CLEARI STATEMENT is executed. This is accomplished by clearing bits 2 and 3 of the 8052AH's special function r egister, IE and by clearing the status bits that determine whether MCS BASIC-52 or the user is controlling these interrupts. The real time clock, which is enabled by the CLOCK1 STATEMENT is not affected by CLEARI. This statement can be used to selectively DISABLE interrupts during specific sections of the users BASIC program. The ONTIME and/or ONEX1 STATEMENTS MUST BE EXECUTED AGAIN before the specific interrupts will be enabled.
CLEARS
The CLEARS statement RESETS all of DS5000's STACKS. The CONTROL and ARGUMENT STACKS are reset to their initialization value, 12542 (30FEH) and 12798 (31FEH) respectively. The INTERNAL STACK (the 8052AH's STACK POINTER, SPECIAL FUNCTION REGISTE R-SP) is loaded with the value that is in INTERNAL RAM location 62 (3EH). This statement can be used to "purge" the stack should an error occur in a subroutine. In addition, this statement can be used to provide a "special" exit from a FOR-NEX T, DO-WHILE, or DO-UNTIL loop.
EXAMPLE OF CLEARS:
>10 PRINT "MULTIPLICATION TEST, YOU HAVE 5 SECONDS"
>20 FOR I = 2 TO 9
>30 N = INT(RND*10) : A - N*I
>40 PRINT "WHAT IS ",N,"*",I, "?": CLOCK1
>50 TIME = 0 : ONTIME 5,200 : INPUT R : IF R<>A THEN 100
>60 PRINT "THAT'S RIGHT":TIME=0 : NEXT I
>70 PRINT "YOU DID IT, GOOD JOB" : END
>100 PRINT "WRONG TRY AGAIN" : GOTO 50
>200 REM WASTE CONTROL STACK, TOO MUCH TIME
>210 CLEARS : PRINT "YOU TOOK TOO LONG":GOTO 10
NOTE: When the CLEARS and CLEARI STATEMENTS are LISTED they will appear as CLEAR S and CLEAR I respectively. Don't be alarmed by the space, that is the way it's supposed to work.
MODE: COMMAND AND/OR RUN
TYPE: CONTROL
CLOCK1
The CLOCKI STATEMENT enables the REAL TIME CLOCK feature resident on the MCS BASIC-52 device. The special function operator TIME is incremented once every 5 milliseconds after the CLOCK1 STATEMENT has been executed. The CLOCK1 STATEMENT uses T IMER/COUNTER 0 in the 13-bit mode to generate an interrupt once every 5 milliseconds. Because of this, the special function operator TIME has a resolution of 5 milliseconds.
MCS BASIC-52 automatically calculates the proper reload value for TIMER/COUNTER 0 after the crystal value has been assigned (i.e. XTAL = value). If no crystal value is assigned, MCS BASIC-52 assumes a value of 11.0592 MHz. 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. Because the CLOCK1 STATEMENT uses the interrupts associated with TIMER/COUNTER 0 (the CLOCK1 statement sets bits 7 and 2 in the 8052AH's special function register, IE), the user may not use this interrupt in an assembly language routine if the CLOCK1 STATEMENT is executed in BASIC. The interrupts associated with the CLOCK1 STATEMENT cause MCS BASIC-52 pro grams to run at about 99.6% of normal speed. That means that the interrupt handling for the REAL TIME CLOCK feature only consumes about .4% of the total CPU time. This very small interrupt overhead is attributed to the very fast and effective interrupt handling of the 8052AH device.
CLOCK0
The CLOCK0 (zero) STATEMENT disables or "turns off" the REAL TIME CLOCK feature. This statement clears bit 2 in the 8052AH's special function register, IE. After CLOCK0 is executed, the special function operator TIME will no longer increment. The CLOCK0 STATEMENT also returns control of the interrupts associated with TIMER/COUNTER 0 back to the user, so this interrupt may be handled at the assembly language level. CLOCK0 is the only MCS BASIC-52 statement that can disable the REAL TIME CLOCK. CLEAR and CLEARI will NOT disable the REAL TIME CLOCK.
STATEMENTS: DATA - READ [vars] - RESTORE
MODE: RUN
TYPE: ASSIGNMENT
DATA
DATA specifies expressions that may be retrieved by a READ STATEMENT. If multiple expressions per line are used, they MUST be separated by a comma.
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 MUST ALWAYS be followed by one or more variables. If more than one variab le follows a READ STATEMENT, they MUST be separated by a comma.
RESTORE
RESTORE "resets" the internal read pointer back to the beginning of the data so that it may be read again.
EXAMPLE:
10 20
>10 FOR I=1 TO 3
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. DATA STATEMENTS may be placed anywhere within a program, they will NOT be executed nor
will they cause an error. DATA STATEMENTS are considered to be chained together and appear to be one BIG DATA STATEMENT. If at anytime all the DATA has been read and another READ STATEMENT is executed then the program is terminated and the mes
sage ERROR: NO DATA -IN LINE XX is printed to the console device.
>20 READ A,B
>30 PRINT A,B
>40 NEXT I
>50 RESTORE
>60 READ A,B
>70 PRINT A,B
>80 DATA 10,20,10/2,20/2,SIN(PI),COS(PI)
>RUN
5 10
0 -1
10 20
MODE: COMMAND AND/OR RUN
TYPE: ASSIGNMENT
DIM reserves storage for matrices. The storage area is first assumed to be zero. Matrices in MCS BASIC52 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 will cause an ARRAY SIZE ERROR. If an arrayed variable is used that has NOT been dimensioned by the DIM STATEMENT, BASIC will assign 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). So, the array A(100) would require 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, i.e., DIM A(10), B(15), A1(20).
EXAMPLE:
>10 A(5)=10 - BASIC ASSIGNS DEFAULT OF 10 TO ARRAY SIZE HERE
Error: Array size - in line 20
20 DIM A(5)
DEFAULT ERROR ON ATTEMPT TO RE-DIMENSION ARRAY
>20 DIM A(5) - ARRAY CANNOT BE RE-DIMENSIONED
>RUN
---------------^
STATEMENTS: DO - UNTIL [rel expr]
MODE: RUN
TYPE: CONTROL
The DO - UNTIL [rel expr] instruction provides a means of "loop control" within an MCS BASIC-52 program. All statements between the DO and the UNTIL [rel expr] will be executed until the relational expression following the UNTIL statement is true. DO - UNTIL loops may be nested.
EXAMPLES:
SIMPLE DO-UNTIL
NESTED DO-UNTIL
 
>10 A=O
>10 DO : A=A+1 : DO : B=B=1
>20 DO
>20 PRINT A,B,A+B
>30 A=A+1
>30 UNTIL B=3
>40 PRINT A
>40 B=0
>50 UNTIL A=4
>50 UNTIL A=3
>60 PRINT "DONE"
>RUN
>RUN
1 1 1
1
1 2 2
2
1 3 3
3
2 1 2
4
2 2 4
DONE
2 3 6
3 1 3
READY
3 2 6
>
3 3 9
 
READY
>
STATEMENTS: DO - WHILE [rel expr]
MODE: RUN
TYPE: CONTROL
The DO - WHILE [rel expr] instruction provides a means of "loop control" within an MCS BASIC-52 program. This operation of this statement is similar to the DO - UNTIL [rel expr] except that all statements between the DO and the WHILE [rel expr] will be executed as long as the relational expression following the WHILE statement is true. DO - WHILE and DO - UNTIL statements can be nested.
EXAMPLES:
SIMPLE DO-WHILE
NESTED DO-WHILE - DO-UNTIL
 
>10 DO
>10 DO : A=A+1 : B=B=1
>20 A=A+1
>20 PRINT A,B,A+B
>30 PRINT A
>30 WHILE B<>3
>40 WHILE A<4
>40 B=0
>50 PRINT "DONE"
>50 UNTIL A=3
>RUN
>RUN
 
1
1 1 1
2
1 2 2
3
1 3 3
4
2 1 2
DONE
2 2 4
2 3 6
READY
3 1 3
>
3 2 6
3 3 9
 
READY
>
MODE: RUN
TYPE: CONTROL
The END STATEMENT terminates program execution. The continue command, CONT will not operate if the END STATEMENT is used to terminate execution (i.e., a CAN'T CONTINUE ERROR will be printed to the console). The last statement in an MCS BASIC-5 2 program will automatically terminate program execution if no END STATEMENT is used.
EXAMPLES:
LAST STATEMENT TERMINATION
END STATEMENT TERMINATION
>10 FOR 1=1 TO 4
>10 FOR I=1 TO 4
>20 PRINT I
>20 GOSUB 100
>30 NEXT I
>30 NEXT I
>RUN
>40 END
>100 PRINT I
1
>110 RETURN
2
>RUN
3
4
1
2
READY
3
>
4
 
READY
>
STATEMENTS: FOR - TO - {STEP} - NEXT
MODE: COMMAND AND/OR RUN
TYPE: CONTROL
The FOR - TO - {STEP} - NEXT STATEMENTS are used to set up and control loops.
EXAMPLE:
10 FOR A=B TO C STEP D
20 PRINT A
30 NEXT A
If B = 0, C = 10, and D = 2, the PRINT STATEMENT at line 20 will be executed 6 times. The values of "A" that will be printed are 0, 2, 4, 6, 8, 10. "A" represents the name of the index or loop counter. The value of "B" is the starting va lue 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 causes the value of "D" to be added 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 will be transferred back to the statement after the FOR STATEMENT. Stepping "backwards" (i.e. FOR I = 100 TO 1 STEP-1) is permitted in MCS BASIC-52. Unlike some BASICS, the index MAY be omitted from the NEXT STATEMENT in MCS BASIC-52.
EXAMPLES:
>10 FOR I=l TO 4
>10 FOR 1=0 TO 8 STEP 2
>20 PRINT I
>20 PRINT I
>30 NEXT I
>30 NEXT I
>RUN
>RUN
 
1
0
2
2
3
4
4
6
8
READY
>
READY
>
In MCS BASIC-52 it is possible execute the FOR-TO-{STEP}-NEXT statement in the Command Mode. This makes it possible for the user to do things like display regions of memory by writing a short program like FOR I = 512 TO 560: PH0. XBY(I): NEXT I.
STATEMENTS: GOSUB[ln num] - RETURN
MODE: RUN
TYPE: CONTROL
GOSUB
The GOSUB [ln num] STATEMENT will cause MCS BASIC-52 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 a RETURN STATEMENT can be performed to return control.
RETURN
This statement is used to "return" control back to the STATEMENT following the most recently executed GOSUB STATEMENT. The GOSUB-RETURN sequence can be "nested" meaning that a subroutine called by the GOSUB STATEMENT can call another subroutine with another GOSUB STATEMENT.
EXAMPLES:
SIMPLE SUBROUTINE
NESTED SUBROUTINES
 
>10 FOR I = 1 TO 5
>10 FOR I = 1 TO 3
>20 GOSUB 100
>20 GOSUB 100
>30 NEXT I
>30 NEXT I
>100 PRINT I
>40 END
>110 RETURN
>100 PRINT I,
>RUN
>110 GOSUB 200
>120 RETURN
1
>200 PRINT I*I
2
>210 RETURN
3
>RUN
4
5
1 1
2 4
READY
3 9
>
READY
>
NOTE - The Control Stack permits a graceful exit from incomplete control loops, as shown in the following example where X might equal I returning from the GOSUB before the FOR - NEXT loop was finished.
EXAMPLE:
.
50 GOSUB 1000
.
1000 FOR I = 1 TO 10
1010 IF X = I THEN 1040
1020 PRINT I*X
1030 NEXT I
1040 RETURN
MODE: COMMAND AND/OR RUN
TYPE: CONTROL
The GOTO [ln num] STATEMENT will cause BASIC to transfer control directly to the line number ([ln num]) following the GOTO STATEMENT.
EXAMPLE:
50 GOTO 100
Will, if line 100 exists, cause execution of the program to resume at line 100. If line number 100 does not exist the message ERROR: INVALID LINE NUMBER will be printed to the console device.
Unlike the RUN COMMAND the GOTO STATEMENT, if executed in the COMMAND MODE, does not CLEAR the variable storage space or interrupts. However, if the GOTO STATEMENT is executed in the COMMAND MODE after a line has been edited, MCS BASIC-52 will CLEAR the variable storage space and all BASIC evoked interrupts. This is a necessity because the variable storage and the BASIC program reside in the same RAM memory. So editing a program can destroy variables.
STATEMENTS: ON [expr] GOTO [ln num], [ln num],...[ln num]
MODE: RUN
TYPE: CONTROL
The value of the expression following the ON statement is the number in the line list that control will be transferred to. This is similar to a CASE statement in other languages.
EXAMPLE:
10 ON Q GOTO 100,200,300
If Q was equal to 0, control would be transferred to line number 100. If Q was equal to 1, control would be transferred to line number 200. If Q was equal to 2, GOTO line 300, etc. All comments that apply GOTO and GOSUB apply to the ON S TATEMENT. If Q is less than ZERO a BAD ARGUMENT ERROR will be generated. If Q is greater than the line number list following the GOTO or GOSUB STATEMENT a BAD SYNTAX ERROR will be generated. The ON STATEMENT provides "conditional branchi ng" options within the constructs of an MCS BASIC-52 program.
MODE: RUN
TYPE: CONTROL
The IF statement sets up a conditional test. The generalized form of the IF - THEN - ELSE statement is as follows:
[ln num] IF [rel expr]THEN valid STATEMENT ELSE valid STATEMENT
A specific example is as follows:
>10 IF A=100 THEN A=0 ELSE A=A+l
Upon execution of line 10 if A is equal to 100, THEN A would be assigned a value of 0. IF A does not equal 100, A would be assigned a value of A + 1. If it is desired to transfer control to different line number using the IF statement, the GOT O statement may be omitted. The following examples would yield same results:
>20 IF INT(A)< 10 THEN 100 ELSE 200
>20 IF INT(A)< 10 THEN GOTO 100 ELSE GOTO 200
Additionally, the THEN statement can be replaced by any valid MCS BASIC-52 statement, as shown below:
>30 IF A<>10 PRINT A ELSE 10
>30 IF A<>10 THEN PRINT A ELSE 10
The ELSE statement may be omitted. If it is, control will pass to the next statement.
EXAMPLE:
>20 IF A=10 THEN 40
In this example, IF A equals 10 then control would be passed to line number 40. If A does not equal 10 line number 30 would be executed.
COMMENTS ON IF-THEN-ELSE
When the IF-THEN-ELSE STATEMENT is used with multiple statements per line the delimiter (:) is treated differently than a carriage-return (cr). MCS-52 BASIC executes the remainder of the line if and only if the test A=B proves to be true.
EXAMPLE 1:
10 IF A=B THEN C=A : A=A/2 : GOTO 100
20 PRINT A
EXAMPLE 2:
10 IF A=B THEN C=A
12 A=A/2
14 GOTO 100
20 PRINT A
This means in EXAMPLE 1 IF A did equal B, it would then set C=A, then A=A/2, and then execute line 100. IF A did not equal B, it would then PRINT A and ignore the statements C = A : A = A/2 : GOTO 100. BASIC5000 executes the remainder of the l ine only if the test A=B proves to be true. In EXAMPLE 2, C=A executes only if A=B. Lines 12 and 14 always execute. This same logical interpretation holds true for the ELSE statement as well.
MODE: RUN
TYPE: INPUT/OUTPUT
The INPUT statement allows users to enter data from the console during program execution. One or more variables may be assigned data with a single input statement. The variables must be separated by a comma.
EXAMPLE:
INPUT A,B
Would cause the printing of a question mark (?) on the console device as a prompt to the operator to input two numbers separated by a comma. If the operator does not enter enough data, then MCS BASIC-52 responds by sending the message TRY AGAIN to t he console device.
EXAMPLE:
?1
?1,2
READY
>10 INPUT A,B
>20 PRINT A,B
>RUN
TRY AGAIN
1 2
>
The INPUT statement may be written so that a descriptive prompt is printed to tell the user what to type. The message to be printed is placed in quotes after the INPUT statement. If a comma appears before the first variable on the input list, the question mark prompt character will not be displayed.
EXAMPLES:
ENTER A NUMBER
READY
ENTER A NUMBER 100
READY
>10 INPUT "ENTER A NUMBER" A
>20 PRINT SQR(A)
>RUN
?100
10
>
>10 INPUT "ENTER A NUMBER",A
>20 PRINT SQR(A)
>RUN
10
>
Strings can also be assigned with an INPUT statement. Strings are always terminated with a carriage return (cr). So, if more than one string input is requested with a single INPUT statement, MCS BASIC-52 will prompt the user with a question ma rk.
EXAMPLES:
NAME: SUSAN
READY
NAMES: BILL
READY
>10 STRING 100,10
>20 INPUT "NAME: ",$(1)
>30 PRINT "HI ",$(1)
>RUN
HI SUSAN
>
>10 STRING 110,10
>20 INPUT "NAMES: ",$(1),$(2)
>30 PRINT "HI ",$(1)," AND ",$(2)
>RUN
?ANN
HI BILL AND ANN
>
Additionally, strings and variables can be assigned with a single INPUT statement.
EXAMPLE:
NAME(CR), AGE - FRED
READY
>10 STRING 100,10
>20 INPUT "NAME(CR), AGE - ",$(l),A
>30 PRINT "HELLO ",$(1),", YOU ARE ",A,"YEARS OLD"
>RUN
?15
HELLO FRED, YOU ARE 15 YEARS OLD
>
MODE: COMMAND AND/OR RUN
TYPE: ASSIGNMENT
The LET statement is used to assign a variable to the value of an expression. The generalized form of LET is:
LET [var] = [expr]
EXAMPLES:
LET A = A + 1LET A = 10*SIN(B)/100
Note that the = sign used in the LET statement is not an equality operator, but rather a "replacement" operator and that the statement should be read A is replaced by A plus one. THE WORD LET IS ALWAYS OPTIONAL, i.e LET A = 2 is the same as A = 2
When LET is omitted the LET statement is called an IMPLIED LET. This document will use the word LET to refer to both the LET statement and the IMPLIED LET statement.
The LET statement is also used to assign the string variables, i.e:
LET $(2)=$(1)
LET $(1)="THIS IS A STRING" or
Before Strings can be assigned the STRING [expr], [expr] STATEMENT MUST be executed, or else a MEMORY ALLOCATION ERROR will occur.
SPECIAL FUNCTION VALUES can also be assigned by the LET statement, i.e.:
LET XBY(2000H)=5AH or
LET DBY(25)=XBY(1000)
LET IE = 82H or
MODE: RUN
TYPE: CONTROL
The ONERR[ln num] statement lets the programmer handle arithmetic errors, should they occur, during program execution. Only ARITH. OVERFLOW, ARITH. UNDERFLOW, DIVIDE BY ZERO, and BAD ARGUMENT errors can be "trapped" by the ONERR statement, all other errors are not. If an arithmetic error occurs after the ONERR statement is executed, the MCS BASIC-52 interpreter will pass control to the line number following the ONERR[lin num] statement. The programmer can handle the error condition in an y suitable manner. Typically, the ONERR[ln num]statement should be viewed as an easy way to handle errors that occur when the user provides inappropriate data to an INPUT statement.
With the ONERR[ln num] statement, the programmer has the option of determining what type of error occurred. This is done by examining external memory location 12545 (3101H) after the error condition is trapped. The error codes are as follows:<
p>
This location may be examined by using an XBY(12545) statement.
MODE: RUN
TYPE: CONTROL
The ONEX1 [ln num] statement lets the user handle interrupts on the 8052AH's INT1 pin with a BASIC program. The line number following the ONEXI statement tells the MCS BASIC-52 interpreter which line to pass control to when an interrupt occurs. &nbs p;In essence, the ONEXI statement "forces" a GOSUB to the line number following the ONEXI statement when the INTI pin on the 8052AH is pulled low. The programmer must execute a RETI statement to exit from the ONEX1 interrupt routine. If this i s not done all future interrupts on the INT1 pin will be "locked out" and ignored until a RETI is executed. ONEX1 need be executed only once during the program. During CAPTURE, the time of the interrupt is stored in locations internal memory locatio ns 74h, 75h, and 76h as milliseconds x5, and lsbyte seconds and msbyte seconds respectively.
The ONEXI statement sets bits 7 and 3 of the 8052AH's interrupt enable register IE. Before an interrupt can be processed, the MCS BASIC-52 interpreter must complete execution of the statement it is currently processing. Because of this, interr upt latency can vary from microseconds to tens of milliseconds or even longer if PRINT, TEK or DUMP or some other extensive statement is being executed. ONEX1 and ONTIME take the DS5000 out of the state entered by executing the IDLE statement.   ;The ONTIME [expr], [in num] interrupt has priority over the ONEX1 interrupt. So, the ONTIME interrupt can interrupt the ONEX1 interrupt routine.
EXAMPLE:
READY
10 CLOCK 1
20 ONEX1 100
30 GOTO 30
100 PRINT TIME
110 RETI
>RUN
10 CLOCK 1
20 ONEX1 100
30 IDLE
40 GOTO 30
100 PRINT TIME
110 RETI
2.31 (low transition supplied to INT1 at 2.31 seconds, etc.)
3.435
4.725
6.225
STATEMENT: ONTIME [expr], [ln num]
MODE: RUN
TYPE: CONTROL
Since MCS BASIC-52 processes a line in the millisecond time frame and the timer/counters on the 8052AH operate in the micro-second time frame, there is an inherent incompatibility between the timer/counters on the 8052AH and MCS BASIC-52. To help so lve this situation the ONTIME [expr], [ln num] statement was devised. What ONTIME does is generate an interrupt every time the SPECIAL FUNCTION OPERATOR, TIME, is equal to or greater than the expression following the ONTIME statement. Actually , only the integer portion of TIME is compared to the integer portion of the expression. The interrupt forces a GOSUB to the line number ([ln num]) following the expression ([expr]) in the ONTIME statement.
Since the ONTIME statement uses the SPECIAL FUNCTION OPERATOR, TIME, the CLOCK 1 statement must be executed in order for ONTIME to operate. If CLOCK 1 is not executed the SPECIAL FUNCTION OPERATOR, TIME, will never increment and not much will happen .
Since the ONTIME statement generates an interrupt when TIME is greater than or equal to the expression following the ONTIME statement, how can periodic interrupts be generated? That's easy, the ONTIME statement must be executed again in the interrupt rou tine:
EXAMPLE:
TIMER INTERRUPT AT - 2.045 SECONDS
READY
>10 TIME=0 : CLOCK1 : ONTIME 2,100 : DO
>20 WHILE TIME<10 : END
>100 PRINT "TIMER INTERRUPT AT - ",TIME,"SECONDS"
>110 ONTIME TIME+2,100 : RETI
>RUN
TIMER INTERRUPT AT - 4.045 SECONDS
TIMER INTERRUPT AT - 6.045 SECONDS
TIMER INTERRUPT AT - 8.045 SECONDS
TIMER INTERRUPT AT - 10.045 SECONDS
>
You may wonder why the TIME that was printed out was 45 milliseconds greater than the time that the interrupt was supposed to be generated. That's because the terminal used in this example was running at 4800 BAUD and it takes about 45 milliseconds to print the message "TIMER INTERRUPT AT - "
If the programmer does not want this delay, a variable should be assigned to the SPECIAL FUNCTION OPERATOR, TIME, at the beginning of the interrupt routine.
EXAMPLE:
TIMER INTERRUPT AT - 2 SECONDS
READY
>10 TIME=0 : CLOCK 1 : ONTIME 2,100: DO
>20 WHILE TIME<10 : END
>100 A=TIME
>110 PRINT "TIMER INTERRUPT AT - ",A,"SECONDS"
>120 ONTIME A+2,100 : RETI
>RUN
TIMER INTERRUPT AT - 4 SECONDS
TIMER INTERRUPT AT - 6 SECONDS
TIMER INTERRUPT AT - 8 SECONDS
TIMER INTERRUPT AT - 10 SECONDS
>
Like the ONEXI statement, the ONTIME interrupt routine must be exited with a RETI statement. Failure to do this will "lock-out" all future interrupts.
The ONTIME interrupt has priority over the ONEX1 interrupt. This means that the ONTIME interrupt can interrupt the ONEX1 interrupt routine. This priority was established because time related functions in control applications were viewed as cri tical routines. If the user does not want the ONEX1 routine to be interrupted by the ONTIME interrupt, a CLOCK0 or a CLEARI statement should be executed at the beginning of the ONEX1 routine. The interrupts would have to be re-enabled before t he end of the ONEX1 routine. The ONEX1 interrupt cannot interrupt an ONTIME routine.
The ONTIME statement in MCS BASIC-52 is unique, relative to most BASICS. This powerful statement eliminates the need for the user to "test" the value of the TIME operator periodically throughout the BASIC program.
The ONTIME statement can break out of the state entered by executing IDLE.
EXAMPLE:
Ready
Timer 17.255
>10 CLOCK 1
>20 ONTIME 2,100
>30 IDLE
>40 GOTO 30
>100 PRINT "Timer ",TIME
>110 ONTIME TIME+2,100
>120 RETI
>RUN
Timer 19.005
Timer 21.005
Timer 23.005
Timer 25.005
The IDLE statement reduces power consumption, electrical noise and uncertainty about program-state. But it also delays processing keyboard entry. For example, if you entered control-C to break out of the program loop, nothing would happen unti l the interrupt occurred and the program executed the line after the appearance of the IDLE statement.
MODE: COMMAND and/or RUN
TYPE: INPUT/OUTPUT
The PRINT statement directs MCS BASIC-52 to output to the console device. The value of expression strings, literal values, variables or test strings may be printed out. The various forms may be combined the print list by separating them with c ommas. If the list is terminated with a comma, the carriage return/line feed will be suppressed. P. and ? are "shorthand" notation for PRINT.
EXAMPLES:
>PRINT 10*10,3*3
>PRINT "MCS-51"
>PRINT 5, 1E3
100 9
MCS-51
5 1000
Values are printed next to one another with two intervening blanks. A PRINT statement with no argument causes a carriage retum/line feed sequence to be sent to the console device.
SPECIAL PRINT FORMATTING STATEMENTS
TAB([expr])
The TAB([expr]) function is used in the PRINT statement to cause data to be printed out in exact locations on the output device. TAB([expr]) tells MCS BASIC-52 which position to begin printing the next value in the print list. If the printhead or cursor is on or beyond the specified TAB position, MCS BASIC will ignore the TAB function.
EXAMPLE:
>PRINT TAB(5),"X",TAB(10),"Y"
X Y
SPC([expr])
The SPC([expr]) function is used in the PRINT statement to cause MCS BASIC-52 to output the number of spaces in the SPC argument.
EXAMPLE:
A B
>PRINT "A", SPC(5), "B"
CR
The CR function is interesting and unique to MCS BASIC-52. CR used in a PRINT statement will force a carriage return, but not a line feed. This can be used to create one line on a CRT device that repeatedly updated.
EXAMPLE:
>10 FOR I = 1 TO 1000
>20 PRINT I,CR,
>30 NEXT I
will cause the output to remain only on one line. No line feed will be sent to the console device until the program finishes.
USING(special characters)
The USING function tells MCS BASIC-52 what format to display the values that are printed. MCS BASIC-52 "stores" the desired format after the USING statement is executed. So, all output following a USING statement will be in the format evoked by the last USING statement executed. The USING statement need not be executed within every PRINT statement unless the programmer wants change the format. U. is a "shorthand" notation for USING. The options for USING are as follows:
USING(Fx)- This will force MCS BASIC-52 to output all numbers using the floating point format. The value of x determines how many significant digits will be printed. If x equals 0, MC BASIC-52 will not output any trailing zeros, s
o the number of digits will vary depending upon the number. MCS BASIC-52 will always output at least 3 significant digits even if x is 1 or 2. The maximum value for x is 8.
EXAMPLE:
1.00 E 0 2.00 E 0 3.00 E 0
READY
>10 PRINT USING(F3),1,2,3
>20 PRINT USING(F4),1,2,3
>30 PRINT USING(F5),1,2,3
>40 FOR 1=10 TO 40 STEP 10
>50 PRINT I
>60 NEXT I
>RUN
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+l
2.0000 E+l
3.0000 E+l
4.0000 E+l
>
USING(#.#) - This will force MCS BASIC-52 to output all numbers using an integer and/or decimal format. The number of "#" 's before the decimal point represents the number of significant integer digits that will be printed in the fracti
on. The decimal point may omitted, in which case only integers will be printed. USING may be abbreviated U. USING(###.###), USING(######) and USING(######.##) are all valid in MCS BASIC-52. The maximum number of "#" characters is 8
. If MCS BASIC cannot output the value in the desired format (usually because the value is too large) question mark (?) will be printed to console device, then BASIC will output the number in the FREE FORMAT described below.
EXAMPLE:
1.00 2.00 3.00
READY
>10 PRINT USING(##.##)
>15 PRINT 1, 2, 3
>20 FOR I=1 TO 120 STEP 20
>30 PRINT I
>40 NEXT I
>RUN
1.00
21.00
41.00
61.00
81.00
? 101
? 121
>
NOTE: The USING(FX) and the USING(#.#) formats will always "align" the decimal points when printing a number. This feature makes displayed columns of numbers easy to read.
USING(0) - This argument lets MCS BASIC-52 determine what format to use. The rules are simple, if the number is between ± 99999999 and ± .1, BASIC will display integers and fractions. If it is out of this range, BASIC will use the
USING(F0) format. Leading and trailing zero will always be suppressed. After reset, MCS BASIC-52 is placed in the USING(0) form.
STATEMENT: PRINT# or P.# or ?#
MODE: COMMAND and/or RUN
TYPE: INPUT/OUTPUT
The PRINT#, P.#, and ?# statement does the same thing as the PRINT, P. and ? statements except that the output is directed to the list device instead of the consol device. The BAUD rate to the list device must be initialized by the STATEMENT - BAUD[ expr] before the PRINT#, P.#, or, ?# statement is used. All comments that apply to the PRINT, P. or ? statements apply to the PRINT#, P.#, or ? statements. P.# and ?# are "shorthand" notation for PRINT#.
STATEMENTS: PH0., PH1., PH0.#, PH1.#
MODE: COMMAND and/or RUN
TYPE: INPUT/OUTPUT
The PH0. and PH1. statements do the same thing 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 to be 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 to be printed is no t within the range of valid integer (i.e. between 0 and 65535 (0FFFFH) inclusive), MCS BASIC-52 will default to the normal mode of print. If this happens no "H" will be printed out after the value. Since integers can be entered in either decim al or hexadecimal form, the statements PRINT, PH0., and PH1. can be used to perform decimal to hexadecimal and hexadecimal to decimal conversion. All comments that apply to the PRINT statement apply to PH0. and PH1. statements. PH0.# and PH1.# do the same thing as PH0. and PH1. respectively, except that the output is directed to the list device instead of the console device.
EXAMPLES:
>PH0. 2*2
04H
>PH1. 2*2
0004H
>PRINT 99H
153
>PH0. 100
64H
>PH0. 1000
3E8H
>PH1. 1000
03E8H
>P. 3E8H
1000
>PH0. PI
03H
STATEMENT: PRINT@, PH0.@, PH1.@
MODE: COMMAND AND/OR RUN
TYPE: INPUT/OUTPUT
The PRINT@ (P.@ OR ?@), PH0.@, and PH1.@ statements do the same thing as the PRINT (P.@),or ?@), PH0., and PH1. statements respectively except that the output is directed to a user defined output driver. These statements assume that the user has pla ced an assembly language output routine in external code memory location 403CH. To enable the @ driver routine the user must SET BIT 27H (39D) in internal memory of the MCS BASIC-52 device. BIT 27H (39D) is BIT 7 of internal memory location (3 6D). This BIT can be set by the BASIC statement DBY(27H) = DBY(27H) .OR. 80H or by a user supplied assembly language routine. If the user evokes the driver routine and this bit is not set, the output will be directed to the console driver. &nb sp;The only reason this BIT must be set to enable the @ driver is this adds a certain degree of protection from accidentally typing LIST@ when no assembly language routine exists. The philosophy here is that if the user sets the bit, the user provid es the driver or else!!!
When MCS BASIC-52 calls the user output driver routine at location 403CH, the byte to output is in accumulator and R5 of register bank 0 (RBO). The user may modify the accumulator (A) and the data pointer (DPTR) in the assembly language output routi ne, but cannot modify any of the registers in RB0. This is intended to make it real easy for the user to implement a parallel or serial output driver without having to do a PUSH or a POP.
MODE: COMMAND AND / OR RUN
TYPE: ASSIGNMENT
The arithmetic expression, or expressions following the PUSH statement are evaluated and then sequentially placed on MCS BASIC-52's ARGUMENT STACK. This statement, in conjunction with the POP statement provides a simple means of passing parameters t o assembly language routines. In addition, the PUSH and POP statements can be used to pass parameters to BASIC subroutines and to "SWAP" variables. The last value PUSHED onto the ARGUMENT STACK will be the first value POPPED off the ARGUMENT S TACK.
VARIATIONS:
More than one expression can be pushed onto the ARGUMENT stack with a single PUSH statement. The expressions are simply followed by a comma: PUSH[expr],[expr],...,[expr]. The last value PUSH'ed onto the ARGUMENT STACK is the last expression [e xpr] encountered in the PUSH statement
EXAMPLES:
SWAPPING
VARIABLES
SUBROUTINE
PASSING
>10 A=10
>10 PUSH 1,3,2
>20 B=20
>20 GOSUB 100
>30 PRINT A,B
>30 POP RI,R2
>40 PUSH A,B
>40 PRINT RI,R2
>50 POP A,B
>50 END
>60 PRINT A,B
>100 REM QUADRATIC A-2,B-3,C=1 IN EXAMPLE
>RUN
>110 POP A,B,C
>120 PUSH (-B+SQR(B*B-4*A*C))/(2*A)
10 20
>130 PUSH (-B-SQR(B*B-4*A*C))/(2*A)
20 10
>140 RETURN
>RUN
READY
>
nbsp;-1 -.5
READY
>
MODE: COMMAND AND / OR RUN
TYPE: ASSIGNMENT
The top of the ARGUMENT STACK is assigned to the variable following the POP statement and the ARGUMENT STACK is "POPPED" (i.e. incremented by 6). Values can be placed on the stack by either the PUSH statement or by assembly language CALLS. NOT E - If a POP statement is executed and no number is on the ARGUMENT STACK, an A-STACK ERROR will occur.
VARIATIONS:
More than one variable can be popped off the ARGUMENT stack with a single POP statement. The variables are simply followed by a comma (i.e. POP [var],[var],...,[var]).
EXAMPLE:
See PUSH statement.
COMMENT:
The PUSH and POP statements are unique to MCS BASIC-52. These powerful statements can be use "get around" the GLOBAL variable problems so often encountered in BASIC PROGRAMS. This problem arises because in BASIC the "main" program and all subr outines used by the main program are required to use the same variable names (i.e. GLOBAL VARIABLES). It is not always convenient to use the same variables in a subroutine as in the main program and you often see programs re-assign a number of varia bles (i.e. A= Q) before a GOSUB STATEMENT is executed. If the user reserves some variable names JUST for subroutines (i.e. SI, S2) and passes variables on the stack as shown in the previous example, you avoid any GLOBAL variable problems in MCS BASI C-52.
STATEMENT: PWM [expr], [expr], [expr]
MODE: COMMAND and/or RUN
TYPE: INPUT/OUTPUT
PWM stands for PULSE WIDTH MODULATION. It generates a user defined pulse sequence on P1.2 (bit 2 of I/0 PORT 1) of the MCS BASIC-52 device. The first expression following the PWM statement is the number of clock cycles the pulse will remain hi gh. A clock cycle is equal to 12/XTAL, which is 1.085 microseconds at 11.0592 MHz. The second expression is the number of clock cycles the pulse will remain low and the third expression is the total number of cycles the user wishes to output. All expressions in the PWM statement must be valid integers (i.e. between 0 and 65535 (0FFFFH) inclusive). Additionally, the minimum value for the first two expressions in the PWM statement is 25.
The PWM statement uses TIMER1, which is also used for serial communications. It does not restore the correct parameters nor does it disable the serial interrupt. Thus, you must reload Special Control Variable TIMER1 after executing PWM.
EXAMPLE:
>PWM 100,100,1000 :TIMER1=0FAFDH
At 11.0592 MHz, this would generate 1000 cycles of a square wave that has a period of 217 microseconds (4608 Hz) on P1.2.
MODE: COMMAND AND/OR RUN
TYPE: CONTROL - PERFORMS NO OPERATION
REM is short for REMark. It does nothing, but allows the user to add comments to a program. Comments are usually needed to make a program a little easier to understand. Once a REM statement appears on a line the entire line is assumed to be a remark, so a REM statement may not be terminated by a colon (:), however, it may be placed after a colon. This can be used to allow the programmer to place a comment on each line.
EXAMPLES:
>10 INPUT A : REM INPUT ONE VARIABLE
>10 REM INPUT ONE VARIABLE
>20 INPUT A
>30 REM INPUT ANOTHER VARIABLE
>40 INPUT B
>50 REM MULTIPLY THE TWO
>60 Z=A*B
>70 REM PRINT THE ANSWER
>80 PRINT Z
>20 INPUT 3 : REM INPUT ANOTHER VARIABLE
>30 Z=A*B : REM MULTIPLY THE TWO
>40 PRINT Z : REM PRINT THE ANSWER
The following will NOT work because the entire line would be interpreted as a REMark, so the PRINT statement would not be executed:
>10 REM PRINT THE NUMBER : PRINT A
NOTE - The reason the REM statement was made executable in the command mode in MCS BASIC-52 is that if the user is employing some type of UPLOAD/DOWNLOAD routine with a computer, this lets the user insert REM statements, without line numbers in the text and not download them to the MCS BASIC-52 device. This helps to conserve memory.
MODE: RUN
TYPE: CONTROL
The RETI statement is used to exit from interrupts that are handled by an MCS BASIC-52 program. Specifically, the ONTIME and the ONEXI interrupts. The RETI statement functions like the RETURN statement except that it also clears all software i nterrupt flags so interrupts can again be acknowledged. If the user fails to execute the RETI statement in the interrupt procedure, all future interrupts will be ignored.
MODE: RUN
TYPE: CONTROL
The STOP statement allows the programmer to break program execution at specific points in a program. After a program is STOPped variables can be displayed and/or modified. Program execution may be resumed with a CONTinue command. The pur pose of the STOP statement is to allow for easy program "debugging." More details of the STOP-CONT sequence are covered in the DESCRIPTION OF COMMAND - CONT section of this manual.
EXAMPLE:
>10 FOR I= 1 TO 100
1
READY
2
>20 PRINT I
>30 STOP
>40 NEXT I
>RUN
STOP - IN LINE 40
>CONT
Note that the line number printed out after the STOP statement is executed is the line number following the STOP statement, NOT the line number that contains the STOP statement!!!
STATEMENT: STRING [expr], [expr]
MODE: COMMAND and/or RUN
TYPE: CONTROL
The STRING [expr],[expr] statement allocates memory for strings. Initially, no memory is allocated for strings. If the user attempts to define a string with a statement such as LET $(1)= "HELLO" before memory has been allocated for strings, a MEMORY ALLOCATION ERROR will be generated. The first expression in the STRING [expr],[expr] statement is the total number of bytes the user wishes to allocate for string storage. The second expression denotes the maximum number of bytes that a re in each string. These two numbers determine the total number of defined string variables.
You might think that the total number of defined strings would be equal to the first expression in the STRING [expr],[expr] statement divided by the second expression. Such is not the case. MCS BASIC-52 requires one additional byte for each st ring, plus one additional byte overall. This means that the statement STRING 100,10 would allocate enough memory for 9 string variables, ranging from $(0) to $(8) and all of the 100 allocated bytes would be used. Note that $(0) is a valid stri ng in MCS BASIC-52.
After memory is allocated for string storage, neither commands, such as NEW nor statements, such as CLEAR, will "de-allocate" this memory. The only way memory can be de-allocated is to execute a STRING 0,0 statement. STRING 0,0 will allocate n o memory to string variables.
IMPORTANT NOTE
Every time the STRING [expr],[expr] statement is executed, MCS BASIC-52 executes the equivalent of a CLEAR statement. This is a necessity because string variables and numeric variables occupy the same external memory space. So, after the STRIN G statement is executed, all variables are "wiped-out". Because of this, string memory allocation should be performed early in a program (like the first statement or so) and string memory should never be "re-allocated" unless the programmer is willing to destroy all defined variables.
STATEMENTS: UI1 and UIO (USER INPUT)
MODE: COMMAND and/or RUN
TYPE: CONTROL
UI1
The UIl statement permits the user to write specific console input drivers for MCS BASIC-52. After UIl is executed BASIC will call external program memory location 4033H when a console input is requested. The user must provide a JUMP instructi on to an ASSEMBLY LANGUAGE INPUT ROUTINE at this location. The appropriate ASCII input from this routine is placed in the 8052AH's accumulator and the user input routine returns back to BASIC by executing an ASSEMBLY LANGUAGE RET instruction. The user must NOT modify any of the 8052AH's registers in the assembly language program with the exception of the MEMORY and REGISTER BANK allocated to the USER. THE ASSEMBLY LANGUAGE LINKAGE section of this manual explains what memory MCS BASIC-52 allocates to the user and how the user may allocate additional memory if needed.
In addition to providing the INPUT driver routine for the UIl statement, the user must also provide a CONSOLE STATUS CHECK routine. This routine checks to see if the CONSOLE DEVICE has a character ready for MCS BASIC-52 to read. BASIC CALLS ex ternal memory location 4036H to check the CONSOLE STATUS. The CONSOLE STATUS ROUTINE sets the CARRY BIT to 1 (C = 1) if a character is ready for BASIC to read and CLEARS the CARRY BIT (C = 0) if no character is ready. Again, the contents of th e REGISTERS must not be changed. MCS BASIC-52 uses the CONSOLE STATUS CHECK routine to examine the keyboard for a control-C character during program execution and during a program LISTING. This routine is also used to perform the GET operation .
UI0
The UI0 statement assigns the console input console routine back to the software drivers resident on the MCS BASIC-52 device. UI0 and UIl may be placed anywhere within a program. This allows the BASIC program to accept inputs from different de vices at different times.
NOTE: The UI0 and UIl functions are controlled by BIT 30 (IEH) in the 8052AH's internal memory. BIT 30 is in internal memory location 35.6 (23.6H) i.e. the sixth bit in internal memory location 35 (23H). When BIT 30 is SET (BIT 30 = 1), the user routine will be called. When BIT 30 is CLEARED (BIT 30 = 0), the MCS BASIC-52 input driver routine will be used. The assembly language programmer can use this information to change the input device selection in assembly language.
STATEMENTS: UO1 and UO0 (USER OUTPUT)
MODE: COMMAND AND/OR RUN
TYPE: CONTROL
UO1
The UO1 STATEMENT permits the user to write specific console output drivers for MCS BASIC-52. After UO1 is executed BASIC will call external program memory location 4030H when a console output is requested. The user must provide a JUMP instruc tion to an ASSEMBLY LANGUAGE OUTPUT ROUTINE at this location. MCS BASIC-52 places the output character in REGISTER 5 (R5) of REGISTER BANK 0 (RBO). The user returns back to BASIC executing an assembly language RET instruction. The user m ust NOT modify any of the 8052AH's REGISTERS, including the ACCUMULATOR during the user output procedure with the exception of the MEMORY and REGISTER BANK allocated to the user. UO1 gives the user the freedom to write custom output routines for MCS BASIC-52.
UO0
UO0 STATEMENT assigns the console output routine back to the software drivers resident on the MCS BASIC-52 device. UO0 and UO1 may be placed anywhere within a program. This allows the BASIC program to output characters to different devices at different times.
NOTE: The UO0 and UO1 functions are controlled by BIT 28 (ICH) in the 8052AH's internal memory. BIT 28 is in the internal memory location 35.4 (23.4H), i.e. the fourth bit in the internal memory location 35 (28H). When BIT 28 is SET (BI T 28 = 1), the user routines will be called. When BIT 28 is cleared, (BIT 28 = 0), the MCS BASIC-52 output drivers will be used. The assembly language programmer can use this information to change the output device selection in assembly langua ge.
MODE: RUN
TYPE: CONTROL
The IDLE statement forces the MCS BASIC-52 device into a "wait until interrupt mode." Execution of statements is halted until either an ONTIME [expr], [ln num] or an ONEX1 [ln num] interrupt is received. The user must make sure that one or both of t hese interrupts have been enabled before executing the IDLE instruction or else the MCS BASIC-52 device will enter a "wait forever mode" and for all practical purposes the system will have crashed.
When an ONTIME [expr], [ln num] or an ONEX1 [ln num] is received while in the IDLE mode, the MCS BASIC-52 device will execute the interrupt routine and then execute the statement following the IDLE instruction. Hence, the execution of the IDLE instr uction is terminated when either a timer or an external event interrupt is received. Serial communication continues to operate, but the consequence may not be visible until the IDLE is completed. For example, sending Control-C to break the pro gram won't respond until ONTIME or ONEX1 is satisfied.
While in the IDLE mode, the MCS BASIC-52 device asserts the DMA ACKNOWLEDGE pin (PORT 1, BIT 6 = 0) to indicate that the IDLE instruction is active and that no external bus activity will occur. This PIN is physically pin 7 on the MCS BASIC-52 device . When the MCS BASIC-52 device exits from the IDLE mode, this pin is placed back into the logically I (non-active) state.
The user may also exit from the IDLE mode with an assembly language interrupt routine. This is accomplished by setting BIT 33 (21H) (which is in Bit addressable RAM location 36.1) when returning from the assembly language interrupt routine. If this bit is not set by the user, the MCS BASIC-52 device will remain in the IDLE mode when the user assembly language routine returns to BASIC.
An attempt to execute the IDLE statement in the direct mode will yield a BAD SYNTAX ERROR.
MODE: COMMAND AND/OR RUN
TYPE: CONTROL
RROM stands for RUN ROM. It selects a program in the EPROM file, then execute the program. The integer after the RROM statement selects what program in the EPROM file is to be executed. In the COMMAND mode RROM 2 would be equivalent to t yping ROM 2, then RUN. But, notice that RROM [integer] is also a statement. This means that a program that is already executing can actually force the execution of a completely different program that is in the EPROM file. This gives the user the ability to "change programs" on the fly.
If the user executes a RROM [integer] statement and an invalid integer is entered (say 6 programs are contained in the EPROM file and the user enters RROM 8 no error will be generated and MCS BASIC-52 will execute the statement following the RROM [integer ] statement.
NOTE: Every time the RROM [integer] statement is executed, all variables and strings are set equal to zero, so variables and strings CANNOT be passed from one program to another by using the RROM [integer] statement. Additionally, all MCS BAS IC-52 evoked interrupts are cleared.
STATEMENTS: LD@ [expr] and ST@ [expr]
MODE: COMMAND AND/OR RUN
TYPE: INPUT/OUTPUT
ST@
The ST@ [expr] statement lets the user specify where MCS BASIC-52 floating-point numbers are to be stored. The expression [expr] following the ST@ statement specifies the address of where the number is to be stored and the number is assumed to be on the argument stack. The ST@ [expr] statement is designed to be used in conjunction with the LD@[expr] statement. The purpose of these two statements is to allow the user to save floating point numbers anywhere in memory with the assumption th at the user will employ some type of battery back-up or non-volatile scheme with this memory. Since all memory in the DS5000 is battery-backed, these statements are included for compatibility.
LD@
The LD@ [expr] statement lets the user retrieve floating-point numbers that were saved with the ST@ [expr] statement. The expression [expr] following the LD@ statement specifies where the number is stored and after executing the LD@ [expr] statement , the number is placed on the argument stack.
EXAMPLE: Saving and retrieving a ten-element array at location array at location 0F000H
10 REM *** ARRAY SAVE***
20 FOR I= 0 TO 9
30 PUSH A(l) : REM PUT ARRAY VALUE ON STACK
40 ST@ 0F005H+6*I : REM STORE IT, SIX BYTES PER NUMBER
50 NEXT I
60 REM *** GET ARRAY ***
70 FOR I = 0 TO 9
80 LD@ 0F005H+6*1
90 POP B(I)
100 NEXT I
Remember that each floating-point number requires 6 bytes of storage. Also note that expression in the ST@ [expr] and LD@ [expr] statements point to the most significant byte of the stored number. Hence, ST@ (0F005H) would save the number in l ocations 0F005H, 0F004H, 0F003H, 0F002H, 0F00IH, and 0F000H.
MODE: COMMAND AND/OR RUN
TYPE: INPUT/OUTPUT
Not implemented in DS5000 BASIC.