COPYRIGHT Copyright 1988-1994 – Octagon Systems and Remote Processing Corp. All rights reserved. Modifications by Remote Processing Corporation, Copyright 1999 The software described in this manual is furnished under a license agreement and may be used only in accordance with the terms of the agreement. The contents of this manual and the specifications herein may change without notice. TRADEMARKS CAMBASIC™, Micro PC™, PC SmartLINK™ and Event Multitasking™ are trademarks of Octagon Systems.
HOW TO USE THIS MANUAL This manual contains information on CAMBASIC and its commands. You will find that some information is duplicated in this manual. This is done on purpose, as you will probably want to skip over some sections to read those of immediate interest. We have included caution and warning notes that are designed to steer you away from potential trouble areas.
PRODUCT SUPPORT If you have a question about CAMBASIC and you cannot find the answer in this manual, call Technical Support at the number listed below during normal business hours. They will be ready to give you the support you need to successfully use CAMBASIC with your Systems card.
ABOUT CAMBASIC CAMBASIC is the logical result of 13 years of industrial language development at Octagon. Its major strengths are ease–of–use, unequaled performance and the rich vocabulary of industrial BASIC commands. This version was written for Remote Processing Corporation. CAMBASIC is a real time, multitasking, language for control and data acquisition applications. It programs easily and has most of the BASIC language commands found on personal computers.
4. Event Multitasking CAMBASIC provides several types of multitasking. All defined tasks operate in the background and are checked 200 times per second on 18 Mhz systems and 100 times per second on 9 Mhz systems. This includes periodic interrupts, counting, timed outputs, checking the keypad input, checking input combinations, and checking inputs for a change of state. 5. Individual Bit Manipulation Most industrial control is done on a line or bit basis, rather than an 8–line port basis.
machine code segments are executed with the CALL statement. You can pass up to 20 parameters to the machine code program. Small programs can be stored in DATA statements and POKEd into memory. 16. Other features include: a. Line renumbering b. 48 error messages to pinpoint problem areas c. Access to system information d. Bit, BCD, byte, word, and floating point data supported e.
Getting Started To program in CAMBASIC you will need a terminal to interface with your CPU card. This may be a CRT terminal or a PC configured as a terminal. If you use the PC, you will need additional software for your PC to communicate. SmartLINK turns your PC into a program development workstation. See your hardware manual for setup instructions. You should review the CAMBASIC commands in Chapter 4 of this manual. Don’t be overwhelmed by the number of commands available.
Line Labels You can write a program to GOTO or gosub to a label instead of a line number. This makes for more readable code. 90 A3 = AIN(0) 100 GOSUB ..FILTER 110 IF FL > 138 THEN GOTO ..OVER_LIMIT . . . 5460 ..FILTER 5470 FL=.875 *FL+.125*A3 5480 RETURN . . . 8950 ..OVER_LIMIT 8960 OUT 49,3 :’shut down . . . Using line labels makes it easier to review code. You would probably know what “FILTER” does before remembering the line number it is on. Line labels must be the first and only information on a line.
Real time Multitasking CAMBASIC can perform several kinds of tasks at assembly language speed while the program is running. See the Multitasking Chapter for more information. Reserved Words CAMBASIC comprises a set of statements, commands and function names which are treated as reserved words and cannot be used at the beginning of variable names. These are sometimes referred to as keywords.
Below is a list of CAMBASIC commands. Some CPU Cards do not use all of the commands. Refer to your hardware manual for exceptions, if any.
Software and Hardware Interrupts CAMBASIC supports multiple hardware and software interrupts. These interrupts causes the program to branch to an interrupt service routine which acts exactly like a GOSUB. The syntax of a typical routine is: 10 ON KEYPAD$ GOSUB 50 NOTE: Not all products support all the interrupts. See your hardware manual for more information. Hardware Interrupts CAMBASIC supports up to three hardware interrupts. Not all hardware products implement these hardware interrupts.
SAVING AND LOADING PROGRAMS Saving and loading programs to and from nonvolatile memory is as easy as typing “SAVE” and “LOAD”. You can download programs through a modem hundreds of miles from the computer. AUTORUN OPERATION Once a program has been stored in nonvolatile memory, it can autorun on power–up. PROTECTING YOUR PROGRAMS You can cause your program to be completely hidden so that it cannot be viewed by unauthorized people. Once hidden, the program cannot be modified or listed.
Variables may contain keywords, as long as the keyword is not first. Keywords may be imbedded in variable names. For example, GOTOE is not ok EGOTO is ok String variables are limited to 255 characters. Arrays may be any length, may be multidimensional, and include strings. String and array space is limited only by available memory. Numeric variables take seven bytes of memory. Two bytes for the name, one byte for the length and four bytes for the value.
Lower–case characters have a higher ASCII value than upper–case characters. If two strings are identical up to the point that one string ends, the shorter string is said to have a lower value. Array Variables An array is a group or table of values referenced by the same name. Each individual value in the array is called an element. Array elements are variables and can be used in expressions and in any CAMBASIC statement or function that uses variables.
error message. Subsequent lines will become garbled as the synchronous nature of data transmission is lost. When numeric constants are printed in a program listing, they are always followed by a space. The space is added by the LIST statement and is not stored in your program. OPERATORS Arithmetic Operators: CAMBASIC is capable of manipulating single bits within an 8–bit field, packed BCD data, 8–bit bytes, 16–bit words, and real (floating point) numbers.
> < >= greater than less than greater than or equal to less than or equal to <= X>Y X=Y X<=Y Relational operations return a value of “0” if false, – “1” if true. Logical Operators Logical operators perform logical, or Boolean operations on numeric values. Just as relational operators usually make decisions regarding program flow, logical operators usually connect two or more relations and return a true or false value to be used in a decision (see “IF statement” in CAMBASIC COMMANDS).
The NOT operator performs a logical negative of a value. Operand 1 0001 0111 NOT Operand 1 1110 1000 Value of expression 1 2 –2 –1 NOTE: = = 23 232 Value of NOT expression –2 –3 1 0 The NOT expression is false only if the expression evaluates to a value of –1. If you define Boolean constants or variables for use in your programs, use –1 for true. The XOR operator essentially detects the presence of a binary “1” in either operand.
>= (greater than or equal to) 7. NOT (logical bitwise complement) 8. AND (logical bitwise and) 9. OR (logical bitwise or) 10. XOR (logical bitwise exclusive OR). 11. MOD (remainder from integer divide) All operators listed at the same level are evaluated left to right in an expression. All logical operations convert their operands to 16–bit integer values prior to the operation. These operands must be in the range 0 to 65,535 or –32,768 to 32,767.
CAMBASIC EDITOR Using the Line Editor When using a CRT terminal to write programs, the resources of the PC are not available. CAMBASIC has a line editor that may be used with any “smart” or “dumb” terminal. You can also use these commands when using your PC with terminal software other than PC SmartLINK. There are 12 editing commands. Your program can be edited a line at a time. Since you are talking through a serial port to your PC or terminal, full screen editing like that on your PC is not possible.
CURSOR MOVEMENT The display will appear as above. Press twice. You will notice that the first two characters appear as the cursor moves to the right. Now press <4> and then . The cursor now moves 4 spaces to the right. Press twice. The characters seem to be erased but are not. You can confirm this by pressing twice again. You cannot move the cursor with the beyond the end of the line or with the to the left of the text. Editing the line number is not allowed.
Move the cursor to the “e” in edit. 10 PRINT "This is";:PRINT" a simple edit" 10 PRINT "This is";:PRINT" a simple _ Now type and then the phrase ("hack") and, finally, . 10 I PRINT " This is"; : PRINT " a simple hack" Insert The key is used for insert. The cursor is normally a blinking underline character. When in the Insert Mode, this changes to a blinking block character. When using a CRT terminal, turns on the Insert Mode and turns it off.
10 PRINT "This is";:PRINT" a s_ Type and then . You have replaced the “a” with an “i”. Finally, type . 10 PRINT "This is";:PRINT" a sample edit" 10 PRINT "This is";:PRINT" a si 10 PRINT "This is";:PRINT" a simple edit" If you change your mind in the middle of a Replace, you can exit by pressing X Extend The Line To add more to the end of an existing line type . This command moves the cursor to the next character past the end of the line and enters the Insert Mode.
How to Maximize Execution Speed 1. Use the precompiled variable A% to Z%. In an average program these will run 50% faster. Use as many as possible, especially in FOR/NEXT loops and software counters. For other variables there is a lookup time. To minimize lookup time declare the variables at the beginning of the program to force them to be at the beginning of the variable table. Put the variables which need to execute fastest at the beginning. 10 A=0:B=0:C=0:A$="" 2.
10. Spaces have no affect on speed since they are eliminated in the compiling process. 11. Data statements execute slowly. If you need large data tables, load them into RAM at the start of the program, and access them with the PEEK function. While this is less convenient, it is faster. 12. The PRINT USING statement takes longer to execute than PRINT, as it must format before sending the characters. 13. FPOKE and FPEEK are the fastest memory accesses. They move four bytes at a time.
second software interrupt occurs while the system is in a subroutine for another interrupt, nesting occurs. This means that the second interrupt will interrupt the first subroutine. After the second subroutine finishes executing, the first subroutine can finish executing. Use LOCK and UNLOCK if this will cause a problem in your program. Nesting can occur at any level, limited only by the amount of memory.
Command Syntax Purpose ABS n=ABS(m) Returns absolute value of a number AIN n=AIN(channel) Returns result of A/D conversion AND n = a AND b Performs logical AND AOT AOT channel,value Sends data to a D/A converter ASC n=ASC(m$) Returns ASCII code for first character ATN n = ATN(m) Returns the arctangent BCD n = BCD(m) Converts binary to BCD BIN n=BIN(m) Converts packed BCD to binary BIN$ a$ = BIN$(m) Converts 8–bit number to string BIT n=BIT(I/O address,bit) Reads specific bit
Command Syntax Purpose DO/UNTIL DO list UNTIL expr.
Command Syntax Purpose LINE a = LINE(n) Read and write single bit LINE n, m LIST LIST Outputs program listing LOAD LOAD Moves program from memory to RAM LOCK LOCK Lock out interrupts at a critical time in a program LOG n=LOG(m) Returns natural log of m MID$ n$=MID$(m$,p,q) Returns part of string m$ MID$(m$,p,q)=n$ Inserts a string into a string MOD n=a MOD b Returns remainder of integer division MON MON Invokes the minimonitor NEW NEW Initializes for a new program NOT n = NO
Command Syntax Purpose PRINT$ PRINT$ char [,char] Prints string of characters PULSE n=PULSE(m) Returns time from pulsed output PULSE n,m Pulses an output bit READ READ variable Reads DATA statement values REMARK ' Allows program comments RENUM RENUM [newline] . .
Command Syntax Purpose TIME$ n$=TIME$(n) Reads calendar/clock TIME$=n$ Writes to calendar/clock TROFF TROFF Stops the trace TRON TRON Starts the trace UNLOCK UNLOCK Unlocks interrupt lock out UNNEW UNNEW Restores a program USING USING Formats a printed output VAL n=VAL(m$) Converts m$ to a number VARPTR VARPTR(variable) Returns address of variable XOR n = a XOR b Performs a logical exclusive OR / / Lists entire program to screen Command Summary - 5
ABS Numeric Function Syntax: n = ABS(m) Purpose: To return the absolute value of the expression m. Remarks: The absolute value of a number is always positive or zero.
AIN Process Function SYNTAX: a = AIN(channel) PURPOSE: To return the analog input value. REMARKS: The channel is the channel number of the A/D converter. The maximum channel number varies from card to card. See your hardware manual for more information. EXAMPLE: See your hardware manual.
AOT Process Statement SYNTAX: AOT channel,value PURPOSE: To write data to a analog output port. REMARKS: AOT causes the analog output voltage to move to a level specified by the value. The voltage will remain constant until another AOT statement is executed. The analog output ICs change voltage as fast as the CPU can write to them. See your hardware manual for more information. RELATED: CONFIG AOT EXAMPLE: See your hardware manual.
ASC Numeric Function SYNTAX: n = ASC(m$) PURPOSE: To return the ASCII code for the first character of the string m$. REMARKS: The result of the ASC function is a numerical value that is the ASCII code of the first character of the string. The CHR$ function is the inverse of the ASC function, and is used to convert from the ASCII code to a character.
ATN Numeric Function SYNTAX: n = ATN(m) PURPOSE: To return the arctangent of m. REMARKS: The result, n, of the ATN function is a value in radians in the range of –PI/2 to PI/2, where PI = 3.141593. The expression may be integer, but the evaluation is always performed in floating point. To obtain the tangent of m when m is in degrees, use TAN (m* 180). Trigonometric functions are computed as a power series in CAMBASIC.
BCD Numeric Function SYNTAX: n = BCD(m) PURPOSE: To return four digits in packed BCD format from a number. REMARKS: The four BCD digits are stored in the variable n. Each BCD digit is 4–bits and the four BCD digits are stored in 16–bit form. These are known as packed BCD numbers. One common use is to convert a count to BCD to send to displays that have BCD inputs. RELATED: BIN EXAMPLE: A = 456 PRINT BCD(A) 1110 At first, the answer above appears to be wrong.
BIN Numeric Function SYNTAX: n = BIN(m) PURPOSE: To return a number from a packed BCD number. REMARKS: This function assumes that the BCD digits are packed. That is, there are four BCD digits per 16–bits. EXAMPLE: A = BIN(B) Normally, the only way BCD data can enter the system is through an I/O port like those on the 82C55 (e.g. reading a two digit BCD thumbwheel switch). Each of the two switches has four outputs. Together, the eight lines are connected to an I/O port input.
BIN$ String Function SYNTAX: n$ = BIN$(m) PURPOSE: Returns an 8–bit binary representation of a number. REMARKS: The most significant bit (bit 7) is on the left and the least significant is on the right. If a string argument is inadvertently used, the result will be zero. This function is primarily used with the INP function to display the status of each input line. RELATED: The HEX$ function and the “@” binary prefix.
BIT Process Function SYNTAX: n = BIT(I/O address,bit) PURPOSE: To read a specified bit at a specified I/O address. REMARKS: This function returns a “1” if the bit is high and a “0” if it is low. This function will operate only with I/O addresses, not memory addresses.
BIT Process Statement SYNTAX: BIT BIT BIT BIT PURPOSE: To set or turn on an individual bit at the specified I/O address without affecting the other bits. REMARKS: This statement will operate only with I/O addresses, not memory addresses. This program works by reading the last byte written to this port, performing the bit operation and writing it back to the same I/O address. Ports like those on the 82C55 can be read back. The BIT statement cannot be used with ports that lack read back capability.
CALL Statement SYNTAX: CALL address [,m1] [,m2]. . . PURPOSE: To execute an assembly language program at the specified address and, optionally, to pass data. REMARKS: The specified address may be an expression and is the absolute address of the assembly language program. The optional data may be expressions. After conversion to 16–bit integers, the data is pushed on the CPU stack for use by the CALLed routine.
NOTE3: The CALL statement saves all the registers needed by CAMBASIC except IY. If this register is used, it must be restored before returning. EXAMPLE: CALL 0 This causes the system to reinitialize. If an autorun EEPROM is present, its program will execute.
CHR$ String Function SYNTAX: n$ = CHR$(m) n$ = CHR$(m,n) PURPOSE: To convert an ASCII code to its character equivalent. Also, to return a string of like characters. REMARKS: The CHR$ function returns the one–character string with ASCII code m. CHR$ is commonly used to send a special character to the screen or printer. The second syntax will generate a string of n characters all with the character m. This is useful for printing graphics. It can be used to simulate SPACE$ and STRING$ in other BASICS.
CLEAR Statement SYNTAX: CLEAR [string] PURPOSE: To set all numeric variables to zero, set all string variables to null, restore the data pointer, and negate all DIM statements. You can optionally set the string space size. REMARKS: If the optional parameter string is specified, variables are cleared and the string space is made equal to the number of bytes specified. 100 bytes is the default value on power–up. NOTE: You do not need to clear string space for string arrays.
CLEAR COM$ Process Statement SYNTAX: CLEAR COM$ n PURPOSE: To reset a serial port input buffer to the power–up condition. REMARKS: Executing this statement will clear the serial input buffer specified by n. n = legal serial port number. The input buffer parameters are reset. Any previous CONFIG COM$ and ON COM$ commands will be cancelled. This statement does not clear serial output buffers. See the Multitasking Chapter for more information.
CLEAR COUNT Tasking Statement SYNTAX: CLEAR COUNT n [,n1] . . . [,nm] PURPOSE: To clear the accumulated count in a software event counter. REMARKS: CLEAR COUNT is functional both during timed operation and when the counter is stopped. The counter number n ranges from 0 to 7. See the Multitasking Chapter for more information. NOTE: This statement has no effect on 82C54 hardware counters.
CLEAR TICK Tasking Statement SYNTAX: CLEAR TICK n PURPOSE: To reset the internal TICK clock to zero. This does not affect a calendar/clock or the counter for the ON TICK statement. REMARKS: There are three TICK timers in CAMBASIC. The parameter n is the timer number and the range is 0 to 2. All TICK timers are independent. This statement can be used as an electronic stop watch. It can be used in conjunction with the ON BIT statement to measure how long an input is active.
CLEAR PULSE Tasking Statement SYNTAX: CLEAR PULSE n [,n1] . . . [,nm] PURPOSE: To clear the remaining time in a software timer and clear the parameters specified by CONFIG TIMER. REMARKS: Once a timer has been defined with the CONFIG PULSE statement, the CLEAR PULSE statement can be used to abort the timing sequence. A CONFIG PULSE statement must be executed after CLEAR PULSE in order for the PULSE commands to work again.
CLS Statement SYNTAX: CLS [#n] PURPOSE: To clear the screen of a terminal connected to a serial port using PC SmartLINK. REMARKS: This statement sends a string of control characters out the serial port. n = legal serial port number. When #n is not present, the COM1 port is cleared.
COM$ Process Function SYNTAX: n$ =COM$(n) PURPOSE: To return a string from the serial input buffer. This function is usually used in conjunction with ON COM$. REMARKS: n = legal serial port number. COM$ returns the characters in the buffer up to the terminating character (if specified) or the total number of characters in the buffer. When COM$ is executed, the characters in the buffer are removed. Immediately executing COM$ again will produce a null string.
CONFIG Statement SYNTAX: CONFIG command [list] PURPOSE: The CONFIG statement is used to set parameters for a number of industrial commands REMARKS: Each subcommand has a list of parameters. See the CONFIG Chapter for details.
CONT Command SYNTAX: CONT PURPOSE: To resume program execution after a break. REMARKS: The CONT command may be used to resume program execution after a break from the serial port, or an END or STOP statement has been executed. Execution continues at the point where the break happened. CONT is invalid if the program has been edited during the break or if any statements have been executed in the immediate mode. WARNING: All tasks are cancelled when a program stops.
COS Numeric Function SYNTAX: n = COS(m) PURPOSE: To return the trigonometric cosine function. REMARKS: m must be in radians. To convert from degrees to radians, multiply by PI/180 where PI = 3.141593. Trigonometric functions are computed as a power series in CAMBASIC. Calculations are done in single precision floating point to seven digits of precision. Since the power series is an approximation, the result will be accurate to four to six digits, depending upon the value of m.
COUNT Process Function Syntax: n =count(channel) Purpose: To return the count in the software event counters and return the count of the hardware counters. Remarks: The COUNT function returns the accumulated high to low transitions at a specified input, independent of program execution. The software counters are set up using the ON COUNT statement. channel is the counter number, and ranges from 0 to 7. See the Multitasking Chapter for more information.
DATA Statement SYNTAX: DATA constant [,constant] . . . . PURPOSE: To provide a means to store numeric and string constants and object code programs. The data may be accessed by the READ statement. REMARKS: DATA statements are skipped over during execution and may be placed anywhere in the program. A DATA statement may contain as many constants as will fit on a line, and any number of DATA statements may be used in a program.
DATE$ System Statement SYNTAX: DATE$ = date string PURPOSE: DATE$ is used to set the date on the system calendar clock. The system clock keeps time on a 24 hour basis, with a resolution of one second. REMARKS: The date string may be a variable or a constant. In either case the format is the same. The string must be in one of the forms below: "mm-dd-yy" "mm-dd-yy,dw" where mm is the month and ranges from 01 to 12, dd is the day (01-31), yy is the year (00-99) and dw is the day of the week (0-6).
DATE$ System Function SYNTAX: a$ = DATE$(n) PURPOSE: The DATE$ function is used read the date of the system calendar clock. The system clock keeps time on a 24 hour basis with a resolution of one second. REMARKS: The date is returned in two forms depending upon the value of the argument n. When n=0, the months, days and years are returned. When n=1, the day of the week is returned. The clock is set by the DATE$ statement.
DEC & DECF Statements SYNTAX: DEC variable DECF variable PURPOSE: To decrement a variable by one (DEC) or four (DECF). REMARKS: This is a fast way to decrement a simple or array variable. A = A–1 slow DEC A fast A = A–4 slow DECF A fast DEC executes more than twice as fast as the statement it replaces. Valid for simple and array variables.
DELETE Command SYNTAX: DEL [–] line [–line] [–] PURPOSE: To delete CAMBASIC program lines. REMARKS: The DEL command erases the specified range of lines from the program. CAMBASIC always returns to the Immediate Mode after a DELETE is executed. RELATED: None EXAMPLE: DEL 10 Deletes line 10 DEL 30–78 Deletes lines 30 through 78. DEL –40 DEL 100– Deletes all lines from the beginning of the program up to and including line 40. Delete all lines from 100 to the end of the program.
DELAY Statement SYNTAX: DELAY n PURPOSE: To create a precision delay. The resolution is 5 mS (10 ms on 9 Mhz systems). REMARKS: Program execution is suspended during the delay period. Interrupt service will be delayed until the end of the delay period. For breakable delays, use a FOR/NEXT loop. For applications which require high accuracy, the execution of the DELAY statement itself and the number of interrupts occurring must be considered. If a delay of 0 is specified, the delay will be less than 0.
DIM Statement SYNTAX: DIM variable (value) [,variable (value)] . . . PURPOSE: To specify the maximum size for array variables and reserve memory accordingly. REMARKS: The DIM statement sets all elements of the specified numerical arrays to an initial value of zero. String array elements are of variable length, with an initial value of zero (null). The default value is 11 for numerical values and 253 for strings. This means that the numerical array subscripts for 0 to 10 are allowed.
DISPLAY Process Statement SYNTAX: DISPLAY data [,][;][data] . . . DISPLAY$ data [,data] . . . DISPLAY! "format";data [,][;] DISPLAY (row,column) data [,][;][data] . . . DISPLAY (row,column)$ data [,data] . . . DISPLAY (row,column)USING "format";data [,][;] PURPOSE: To write information to Vacuum fluorescent and LCD displays. REMARKS: The three basic syntaxes above can be used to write to the DP series and LCD series displays.
CLEAR DISPLAY Clears graphics and characters from display CLEAR DISPLAY LINE Clears characters at current line CLEAR DISPLAY LINE (x1,y1),(x2,y2) Clears graphics line CLEAR DISPLAY P(x,y) Clears a point on a graphics screen CLEAR DISPLAY C Clears all characters, graphics not affected CLEAR DISPLAY G Clears all graphics, characters not affected DISPLAY P(x,y) Prints a point at x,y DISPLAY LINE(x1,y1),(x2,y2) Draws a line DISPLAY OFF [type] Turns display off. type is C or G.
Line 130 is a 0.5 second delay and the program repeats.
DO/UNTIL Statements SYNTAX: DO . . . UNTIL expression is true PURPOSE: To execute a conditional loop structure. REMARKS: The DO/UNTIL statements cause a list of statements to be executed until a condition is met. You may exit a DO/UNTIL with the EXIT statement EXAMPLE: 10 20 30 50 A= - 45 DO INC A:PRINT A UNTIL A=0 Nesting DO/UNTIL loops is permitted. Care must be taken in the construct.
DPEEK and DPOKE Memory Function and Statement SYNTAX: n = DPEEK(address) n = DPEEK (address, segment) DPOKE address, data DPOKE address, data, segment PURPOSE: DPEEK returns a 16–bit value from memory. DPOKE writes a 16–bit value to memory. REMARKS: A 16–bit word is formed with the lower 8 bits as the value located at memory address “address” and the upper 8 bits as the value located at memory location “address + 1”. The first syntax applies to the first 64K of memory (segment 0).
EDIT Command SYNTAX: EDIT line “.” PURPOSE: To display a line for editing. REMARKS: The EDIT statement simply displays the line specified, and positions the cursor under the first character of the line. The line may then be modified, as described under the Editing Programs Chapter. Typing a period “.” will edit the current line. EXAMPLE: EDIT 10 10 A =15 10 _ The syntax below displays the current line for editing.
END Statement SYNTAX: END PURPOSE: To halt execution of a program at a given point. REMARKS: END causes execution to cease without any message. RELATED: STOP EXAMPLE: 10 20 30 50 60 GOSUB 50 PRINT "STATEMENT" END PRINT "END"; RETURN Without the END statement at line 30, execution would continue through lines 50 and 60 with a second “end” printed. A “GOSUB” error would also occur.
ERL System Variable SYNTAX: n = ERL PURPOSE: To return the line number associated with an error. REMARKS: The function returns the line number of the last error encountered by CAMBASIC. RELATED: ERR, ON ERR, RESUME EXAMPLE: 10 20 30 40 50 60 70 ERROR: none ON ERR GOTO 50 : 'enable error trapping INPUT"Enter a number to divide by.
ERR System Variable SYNTAX: n = ERR PURPOSE: To return the error code associated with an error. REMARKS: The function returns the error code for the last error. It is usually used in conjunction with the ERL function. Error trapping is essential in control applications, where a halt in execution is not tolerable. See the Error Messages Chapter for a list of error codes and messages.
ERROR System Statement SYNTAX: ERR n ERROR n PURPOSE: To simulate the occurrence of a run time error. REMARKS: This statement is usually used to test error trapping systems using the ERR and/or ERL functions. If n is not an assigned error number, an unknown error message will result. See the Error Messages Chapter for a list of error codes and messages.
EXIT and EXIT CLEAR Statement SYNTAX: EXIT [line/label] EXIT CLEAR PURPOSE: To allow legal branching out of a loop structure. REMARKS: Within FOR/NEXT, GOSUB/RETURN and DO/UNTIL structures, it is sometimes necessary to exit the loop before the loop conditions are met. EXIT CLEAR resets all stacks. It can be used in emergency stop (etc.) situations where the nesting of loop structures cannot be known. EXIT is always used with a line/label unless two or more levels are to be exited.
EXP Numeric Function SYNTAX: n = EXP(m) PURPOSE: To return the exponential function of “e.” REMARKS: This function returns the result of the number “e” (2.718282) raised to the power given by m. EXAMPLE: 10 PRINT EXP(1),EXP(2) RUN 2.71828 7.38906 ERROR: – if m> 88.
FIND Command SYNTAX: FIND argument PURPOSE: Used to locate variables, keywords, and labels. REMARKS: This is a useful tool especially in long programs. The variations described below: FIND keyword - This will list all the lines that contain the specified keyword. For example, FIND POKE EXAMPLE: FIND . . This will list all lines that start with labels. It will not list lines where the labels is part of a GOSUB, etc. FIND . .
20 GOSUB . . confirm 50 GOSUB . . current_test >FIND . . 200 . . confirm 300 . . current_test >FIND . . confirm 200 . . confirm 210 CUR = INP(12) 220 IF CUR < 2 THEN F = 0 ELSE F = 1 >FIND CUR 80 COR = INP(35) 90 IF COR <= 176 THEN PRINT “Status OK” 210 CUR = INP(12) 220 IF CUR < 2 THEN F = 0 ELSE F = 1 In this case you would be able to detect the conflict between the COR and CUR variables.
FOR / NEXT / STEP Statements SYNTAX: FOR variable = n TO m [STEP z] . . . NEXT PURPOSE: To perform a loop operation a given number of times. REMARKS: n and m are positive (including zero ) numbers and the optional z may be negative or positive, but not 0. n is the initial value of the counter. m is the final value of the counter. The program lines following the FOR statement are executed until the NEXT statement is encountered.
FPEEK and FPOKE Memory Function and Statement SYNTAX: a = FPEEK(address) a = FPEEK(address,segment) FPOKE address, data FPOKE address, data, segment PURPOSE: FPEEK returns a floating point number previously stored in memory. FPOKE writes a floating point number to memory. REMARKS: This function can be used to write and retrieve data stored in memory. This is very useful in data logging and process data storage and retrieval. The first syntax applies to the first 64K of memory (segment 0).
FRE Function SYNTAX: a = FRE(0) a = FRE(c$) PURPOSE: Returns the number of bytes of unused but allocated string space, or the number of bytes left for program and variables. REMARKS: The argument 0 returns the number of bytes which are currently unused and available for program and variables. When the argument is any string variable (variable name unimportant), the number of bytes of unused string space is returned.
GOSUB Statement SYNTAX: GOSUB line/label . . . RETURN PURPOSE: To branch to and return from a subroutine. REMARKS: line/label is the beginning of the subroutine. A subroutine may be called any number of times in a program, and a subroutine may be called from within another subroutine. The RETURN statement causes CAMBASIC to branch back to the statement following the most recent GOSUB statement.
GOTO Statement SYNTAX: GOTO line/label PURPOSE: To branch unconditionally out of the normal program sequence to a specified line number or label. REMARKS: If line is the line number of an executable statement, that statement and those following are executed. If it is a nonexecutable statement (such as a remark), execution continues at the first executable statement encountered after line. The GOTO statement can be used in Immediate Mode to reenter a program at a desired point.
HEX$ String Function SYNTAX: n$ = HEX$(m) PURPOSE: To return a hex representation of a number. REMARKS: The value of m may range from 0 to 65,535. If the number is 255 or less, HEX$ returns a two hex digit result. Larger numbers result in four hex digits being returned.
IF / THEN / ELSE Statement SYNTAX: IF m THEN statement(s) [ELSE statement(s)] IF m GOTO line/label IF m THEN line/label PURPOSE: To make decisions regarding program flow based on the results returned by an expression. REMARKS: If the expression m is true (not zero), the THEN clause is executed. THEN may be followed by either a line number for branching or one or more statements to be executed. If the result of m is false (zero), the THEN line is ignored and the ELSE line, if present, is executed.
INC and INCF Statements SYNTAX: INC variable INCF variable PURPOSE: To increment a variable by one (INC) or four (INCF). REMARKS: This is a fast increment of a simple or array variable. A=A+1 INC A A=A+4 INCF A fast slow fast slow INC executes more than double the speed of the statement it replaces. Valid for simple and array variables. RELATED: DEC, DECF EXAMPLE: 10 PRINT H 20 INC H 30 PRINT H 40 INCF H 50 PRINT H RUN 0 1 5 Line 10 increments element 8 of the array A.
INKEY$ Function SYNTAX: a$ = INKEY$(n) PURPOSE: To return a single character from a serial input buffer. REMARKS: The returned value is a null or one–character–length string. n = legal serial port number. As long as there are characters in the input serial buffer, you may bring them out one at a time. Each time INKEY$ is executed, a character is erased from the buffer.
INP and OUT I/O Function and Statement SYNTAX: n = INP(I/O address) OUT I/O Address, Data PURPOSE: INP returns a byte from an I/O address. OUT writes a byte to an I/O address. REMARKS: INP is the complementary function to the OUT statement. WARNING: Some I/O address are used internally and should not be written to with the OUT statement. See your hardware manual for these reserved addresses.
INPUT Statement SYNTAX: INPUT [,#n][;] var [,var] ..... INPUT [,#n][;] "prompt message"; var [,var] ..... INPUT [,#n][;] "prompt message", var [,var] .... PURPOSE: The INPUT statement causes the program to pause and prompt an operator for input data. REMARKS: The prompt message is a question mark in the first syntax. The other two syntaxes specify a message string to be printed before the question mark.
INPUT KEYPAD$ Statement SYNTAX: INPUT KEYPAD$ echo port,variable INPUT KEYPAD$ echo port,"text",variable INPUT KEYPAD$ echo port,"text";variable PURPOSE: To input data from a keypad. Optionally print text to echo port REMARKS: The INPUT KEYPAD$ statement is similar to the INPUT statement in that the program pauses to accept data from a matrix keypad. The echo port parameter tells the system where to echo the keys pressed on the keypad. The display must be previously initialized for an echo.
EXAMPLE: 10 ON KEYPAD$ 24 GOSUB 500 20 DISPLAY (1,0); 30 INPUT KEYPAD$ 10,"Enter weight",WEIGHT 40 PRINT WEIGHT 50 INPUT KEYPAD$ 10,"Enter name ";NAME$ . . . 500 C$ = KEYPAD$(1) 510 RETURN The ON KEYPAD$ syntax above may be different for your card.
INSTR Function SYNTAX: a = INSTR(n,string,substring) PURPOSE: Returns the position of the first occurrence on a substring within a string. REMARKS: The parameter n specifies where the search is to start in the string. A “1” signifies the leftmost position in the string. This parameter is not optional. string is a string constant or string variable that is to be searched. substring is the string variable or constant to be searched for.
INT Numeric Function SYNTAX: a = INT(b) PURPOSE: To return the largest integer that is equal to, or less than the argument. REMARKS: The integer portion is stored in variable “a” as a floating point number. RELATED: MOD, "\" integer divide EXAMPLE: PRINT INT(45.67) 45 PRINT INT(–15.02) –16 To produce true rounding to the closest whole number, use the following syntax: A=INT(B+0.5) Adding 0.5 provides the true rounding and emulates the CINT function found in other BASICs.
KEYPAD$ Process Function SYNTAX: a$=KEYPAD$(0) a=KEYPAD$(1) PURPOSE: To return a one–character string in response to a keypad input or return the position of the key. REMARKS: KEYPAD$(0) returns a single–character string that has been assigned to a key. It is most useful on 16–key devices. If no key was pressed ,or if you read the keypad again before another key is pressed, a null string is returned. KEYPAD$(1) returns the key position. Keypads often have legends that are not single letters.
LEFT$ String Function SYNTAX: n$ = LEFT$(m$,p) PURPOSE: To return the leftmost p characters of m$. REMARKS: If p is greater than the length of m$, the entire string (m$) will be returned. If p = 0, a null string is returned.
LEN Numeric Function SYNTAX: n = LEN(m$) PURPOSE: To return the number of characters in m$. REMARKS: Unprintable and blank characters are counted.
LINE Process Function SYNTAX: a = LINE(terminal #) PURPOSE: To return the status of an input on a STB-26 terminal board. REMARKS: The terminal # has a one-to-one correspondence with the terminals on the STB-26 terminal board. This feature eases documentation and troubleshooting. Refer to Card Manual for terminal number range. The LINE function is similar to the BIT function in that individual I/O bits or channels can be read.
LINE Process Statement SYNTAX: LINE terminal #, value PURPOSE: To write directly to the STB-26 terminal board. REMARKS: The terminal # has a one-to-one correspondence with the terminals on the STB-26. This feature eases documentation and troubleshooting. Refer to card manual for terminal number range. The LINE statement is similar to the BIT statement in that individual I/O bits or channels can be controlled.
LIST Command SYNTAX: LIST [line [–[line]]] LIST #n, [line [–[line]]] LIST! PURPOSE: To list a part or all of the program currently in memory. REMARKS: You can stop the listing by pressing . The program is listed through the COM1 serial port unless you specify otherwise. The basic variations are: LIST list the entire program to COM1 / quick version of above LIST #1 list the entire program to COM1 LIST #2 list the entire program to COM2 LIST.
LOAD Command SYNTAX: LOAD LOAD segment LOAD DATA to RAM segment, RAM address, from Flash segment, Flash address, length PURPOSE: LOAD with no parameters reads a program from Flash and puts it into RAM. LOAD segment retrieves a program from 0 or 1 in a 128K Flash EPROM and puts it into RAM. LOAD DATA transfers data from Flash to RAM. REMARKS: The program and serial EEPROMs are two different devices. Saving to a serial EEPROM requires about 200 mS. Loading takes about 20 mS.
LOCK and UNLOCK Tasking Statements SYNTAX: LOCK UNLOCK [RETURN] PURPOSE: To lock out interrupts from time critical portions of a program. REMARKS: When an interrupt occurs from a ON TICK, ON COM$, etc., the current program is interrupted and the interrupt subroutine is called. In some cases, especially where time is critical, it is desirable that the current program not be interrupted until it is completed.
LOG Numeric Function SYNTAX: n = LOG(m) PURPOSE: To return the natural logarithm of m. REMARKS: The natural logarithm is the logarithm to the base e (2.718282). EXAMPLE: PRINT LOG(45/7) 1.86075 ERROR: – if m is zero or negative.
MID$ String Function SYNTAX: n$ = MID$(m$,p[,q]) PURPOSE: To return the requested part of a given string. REMARKS: The function returns a string of length q characters from m$ beginning with the pth character. If q is equal to zero, or p is greater than the length of m$, then MID$ returns a null string. If q is omitted, then a string from position p to the end of m$ is returned.
MID$ String Statement SYNTAX: MID$(a$,s [,n]) = b$ PURPOSE: To replace a portion of one string with another. REMARKS: A common usage for the MID$ statement is in networking protocols. The network commands are standard strings defined by string variables. Using the MID$ statement to modify these strings is much faster than other string methods. The string a$ is the target string, while b$ is the replacement string. The parameter s is the starting point within a$ where b$ will be inserted.
MOD Operator SYNTAX: n = a MOD b PURPOSE: To return the remainder of an integer division. REMARKS: a is divided by b and the remainder is placed in n. The arguments a and b are first rounded to integers. These must be in the range from –32,768 to 32,767 (no error messages are given). The division is then done and the quotient is truncated to an integer. The sign of the result is always the sign of a. RELATED: “\” for integer division.
MON Command SYNTAX: MON PURPOSE: To invoke the Mini–Monitor REMARKS: The Mini–Monitor is used primarily for debugging object code programs. Its use assumes that the programmer is familiar with assembly code and debugging techniques. Unlike CAMBASIC all data is entered in hexadecimal. The Mini–Monitor subcommands are: D – Display memory E – Edit memory F – Fill a block of memory M – Math, add, subtract, multiply in Hex Q – Quit Mini–Monitor See the Mini–Monitor Chapter for more information.
NEW and UNNEW Commands SYNTAX: NEW UNNEW PURPOSE: NEW initializes CAMBASIC for a new program. UNNEW restores a program erased by NEW or a hardware reset. REMARKS: NEW is used to free memory before entering a new program. NEW does not change the memory reserved by the last CLEAR statement. EXAMPLE: The following erases the program pointers for entry of a new program.
ON Statement SYNTAX: ON expression GOSUB line [,line] ... ON expression GOTO line [,line] ... PURPOSE: In the ON...GOTO statement, the value of the expression determines which line number in the list will be used for branching. For example, if the value is 3, the third line number in the list will be the destination of the branch. NOTE: You may not use labels with this statement. REMARKS: In the ON...GOSUB statement, each line number in the list must be the first number of a subroutine.
ON BIT Tasking Statement SYNTAX: ON BIT task number,address,bit GOSUB line/label PURPOSE: To declare an I/O line to be monitored for changes in logic level. REMARKS: Any eight I/O lines may be monitored so that a change in state causes a program branch to the specified subroutine. The I/O lines may be located on any parallel port. A change of state is either a low to high or a high to low transition. The specified line is sampled at each tick of the system clock.
ON COM$ Tasking Statement SYNTAX: ON COM$ n GOSUB line/label ON COM$ n GOSUB PURPOSE: To define a program branch when a task defined by the CONFIG COM$ statement becomes valid. REMARKS: After defining all the parameters with CONFIG COM$ the ON COM$ activates the task. You can deactivate the task by executing the same statement but without a line number after GOSUB. n = legal serial port number. See the Multitasking Chapter for more information.
ON COUNT Tasking Statement SYNTAX: ON COUNT n GOSUB line/label ON COUNT n GOSUB PURPOSE: To execute a subroutine when a preset count is reached. REMARKS: To use this statement you must first set up a counter with CONFIG COUNT and specify a preset count. Every time the preset count is reached, the counter is reset to zero and program flow branches to the routine specified by line. When the subroutine is finished, the program will resume execution.
ON ERR GOTO Statement SYNTAX: ON ERR GOTO line/label PURPOSE: To enable error trapping and specify the first line of the error handling subroutine. REMARKS: Once error trapping has been enabled, all errors detected by CAMBASIC during run time cause CAMBASIC to branch to the specified line. To disable error trapping, execute an ON ERR without the line number. If the routine beginning at line has an error, an infinite loop will be set up. In this case, do a hardware reset and execute the UNNEW! command.
ON INP Tasking Statement SYNTAX: ON INP n, address, mask, compare GOSUB line/label PURPOSE: To cause an interrupt when a preset input bit pattern is detected in an input port. REMARKS: The task is similar to ON BIT. However, you can look at any or all of the 8 bits on a port. An interrupt occurs when the bit pattern is recognized. The interrupt will occur on the first instance of the pattern match. It will not interrupt again until the inputs change and then change back to match the pattern.
ON ITR Tasking Statement SYNTAX: ON ITR n GOSUB line/label ON ITR n GOSUB PURPOSE: To enable or disable a program branch due to an hardware interrupt. REMARKS: Check your hardware manual to determine if this statement is active for your card. It is not active for the RPC-2300 or RPC-150. n = 0 or 1. These correspond to ITR 0 and ITR 1 as described in the hardware manual. The ON ITR statement traps a hardware interrupt so software can service it.
ON KEYPAD$ Tasking Statement SYNTAX: ON KEYPAD$ GOSUB line/label ON KEYPAD$ GOSUB PURPOSE: To cause a program branch when any key is pressed on the keypad. Using this command without a line/label disables keypad tasking. REMARKS: The program branch will respond to any key being pressed. The interrupt service routine can then filter the characters. See the Multitasking Chapter for more information. RELATED: KEYPAD$, SYS(8) EXAMPLE: 10 20 30 . .
ON TICK Tasking Statement SYNTAX: ON TICK n,t GOSUB line/label ON TICK n,t GOSUB PURPOSE: To cause periodic program branching. REMARKS: This statement is used when periodic tasks must be executed. The GOSUB is executed every t seconds. There are three TICK timers in CAMBASIC. The parameter n ranges from 0-2. The TICK timers are independent of each other. The range of t is 0.005 to 327.68 seconds. The GOSUB branch occurs every t seconds unless the second syntax is executed.
OPTO Process Function SYNTAX: a = OPTO (channel) PURPOSE: To return the status of an input on an on board opto isolator rack. REMARKS: Inputs and outputs are active low when interfacing with opto-isolator racks. Thus, writing a “1” to an opto output module will turn it off. This confusion is eliminated with the OPTO function. It automatically inverts the logic so that a “1” represents on and a “0” represents off.
OPTO Process Statement SYNTAX: OPTO channel, value PURPOSE: To turn output modules on and off on 24 position opto-isolator racks that are external to the card. REMARKS: Inputs and outputs are active low when interfacing with opto-isolator racks. Thus, writing a “1” to an opto output module will turn it off. This confusion is eliminated with the OPTO statement. It automatically inverts the logic so that a “1” represents on and a “0” represents off.
PEEK and POKE Memory Function and Statement SYNTAX: n = PEEK(address) n = PEEK(address,segment) POKE address, data POKE address, data, segment PURPOSE: PEEK returns a byte from memory. POKE writes a byte to memory. REMARKS: The returned value from PEEK will be an integer in the range 0 to 255. address is the address in memory. PEEK is the complement to the POKE statement. The first syntax applies to the first 64K of memory (segment 0). For addresses above segment 0, use the second syntax.
PEEK$ and POKE$ Memory Function and Statement SYNTAX: x$ = PEEK$(address) x$ = PEEK$(address, segment) POKE $ address, X$ POKE$ address, X$, segment PURPOSE: PEEK$ returns a string from successive memory addresses. POKE$ writes a string to memory. REMARKS: The first syntax applies to the first 64K of memory (segment 0). For addresses above segment 0, use the second syntax. Not all products support segmented memory.
PRINT Statement PR [#n,] [expression] [; or ,] [expression].. PRINT [#n,] [expression] [; or ,] [expression].. PURPOSE: To output data through the specified serial or display port. REMARKS: If all of the expressions are omitted, a carriage return is performed. If the list of expressions is included, the values of the expressions are displayed on the screen. The expressions in the list may be numeric and/or string expressions. String constants must be enclosed in quotation marks.
In the example below, the semicolon at the end of line 20 causes both PRINT statements to be printed on the same line. 10 INPUT X 20 PRINT X; "Squared is";Xˆ2;" and;" 30 PRINT X; "Cubed is";Xˆ3 RUN ? 9. 9 Squared is 81 and 9 Cubed is 729.OO1 RUN ? 21 21 Squared is 441 and 21 Cubed is 9260.99 This example prints a message to the COM2 port. 100 PRINT #2,"Pressure:";A In this example, the comma in the PRINT statement causes each value to be printed in successive print zones.
PRINT USING Statement SYNTAX: PRINT USING[#n,]!"format string"; expression PURPOSE: To print strings or numbers using a specified format. REMARKS: n = valid port number. Port numbers are 1 and 2 for serial; 9 for VF display; 10 for LCD display. LCD and VF displays must be configured using the CONFIG DISPLAY command before use. The format declaration(s) is one or two strings that specify the print format.
A = 1234.67 PRINT USING "#.##ˆˆˆˆ";A 0.12E+4 In this case the first # specifies the leading zero to the left of the decimal point. PRINT USING "##.##ˆˆˆˆ;A 1.23E+3 Leading zeros to the left of the first digit to the left of the decimal point are suppressed. A = 25.5555 PRINT USING #2, "##.##";A 25.56 Note that true rounding to the second decimal place took place. Output is to the COM2 port.
PRINT$ Statement SYNTAX: PRINT [#n,] $ character [,character]... PR [#n,] $ character [,character]... PURPOSE: Used to send any character from 0 to 255 out a serial port. REMARKS: The statement is often used to send escape sequences to printers, displays, etc. It is the same as PRINT CHR$(n);CHR$(n);CHR$(n);... n = valid port number. Port numbers are 1 and 2 for serial; 9 for VF display; 10 for LCD display. LCD and VF displays must be configured using the CONFIG DISPLAY command before use.
PULSE Process Function SYNTAX: n=PULSE(m) PURPOSE: To return the remaining time of a pulsed output. REMARKS: The resolution of the software pulse timers is 0.005 seconds (0.01 sec in 9 Mhz systems). The remaining time is returned in seconds. If the timer is still in the wait period, the number returned will be negative. The argument range for m is 0 to 7, which is the timer number. See the Multitasking Chapter for more information.
PULSE Tasking Statement SYNTAX: PULSE n,address,bit,time,polarity PURPOSE: To configure a digital output line as a timed or pulsed output. REMARKS: You may configure up to eight digital I/O lines as independent pulse output. The lines may be on any I/O port. The parameter n is the pulse number and has a range from 0 to 7. The address is the I/O address of an 8–bit port. The range is 0 to 255. The bit parameter is the particular bit of the port. The value ranges from 0 to 7.
READ Statement SYNTAX: READ variable [,variable] . . . PURPOSE: To read values from a DATA statement and assign them to variables. See the DATA statement. REMARKS: A READ statement must always be used in conjunction with a DATA statement. READ statements assign DATA statement values to variables in the READ statement on a one–to–one basis. READ statement variables may be numeric or string.
REMARK Statement SYNTAX: 'any characters PURPOSE: To allow explanatory remarks to be inserted in a program or designate a line/label. REMARKS: This syntax is different from the REM used in other Basics. The ' format provides a more readable remark. The old REMARK syntax, 10 REM test comments 10 'test comments is not allowed. is required. Remark statements are not executed but are output exactly as entered when the program is listed. Remarks are skipped over during execution.
RENUM Command SYNTAX: RENUM [newline] [,increment] [,oldline] PURPOSE: To renumber program lines. REMARKS: newline is the first line number to be used in the new sequence. The default is 10. increment is the increment to be used in the new sequence. The default is 10. oldline is the line in the current program where renumbering is to begin. The default is the first line of the program. RENUM also changes all line number references to reflect the new line numbers.
RESTORE Statement SYNTAX: RESTORE [line] PURPOSE: To reset the READ pointer to the beginning of the DATA list. REMARKS: After a RESTORE statement is executed, the next READ statement accesses the first item in the first data statement in the program. If the optional line number is specified, the next READ statement accesses the first item beginning at the line number specified. NOTE: Labels may not be used with RESTORE.
RESUME Statement SYNTAX: RESUME RESUME NEXT RESUME line PURPOSE: To continue program execution after an error recovery procedure has been performed. REMARKS: If NEXT is not declared, the main program will resume operation by reexecuting the statement that originally caused the error. Every error–handling routine must eventually end either by executing a RESUME statement or by terminating the program.
RESUME COUNT Tasking Statement SYNTAX: RESUME COUNT m [,m1] [,m2] . . . [,mn] PURPOSE: To reenable a software event counter. REMARKS: The statement reenables a counter after a STOP COUNT statement has been executed. The counter contents remain unchanged. The m parameter is the count number which ranges from 0 to 7. See the Multitasking Chapter for more information.
RETURN Statement SYNTAX: RETURN [line/label] RETURN ITR number PURPOSE: To resume execution after a GOSUB, interrupt, multitasking or communications call. The RETURN ITR reenables the interrupt. REMARKS: RETURN is used as a return from a GOSUB call. Program execution continues at the statement following the GOSUB. number is 0 or 1, or as limited by your hardware. It is the interrupt number that the subroutine declared by ON ITR n declared.
RIGHT$ String Function SYNTAX: n$ = RIGHT$(m$,p) PURPOSE: To return the right–most p characters of m$ as a string. REMARKS: If p is greater than or equal to LEN(m$), then m$ is returned. If p is zero, a null string is returned.
RND Numeric Function SYNTAX: n = RND(m) PURPOSE: To return a pseudo–random number between 0 and 1. REMARKS: The RND function returns a pseudo–random number between 0 and 1. An m of less than zero will initialize the pseudo–random number sequence. Each time the pseudo–random number generator is initialized with the same m number, it will produce the same sequence of pseudo–random numbers. An m of zero will cause RND to return the previous random number.
RUN Command SYNTAX: RUN [line] PURPOSE: To begin the execution of a program. REMARKS: RUN resets the numeric variables to zero, string variables to null, resets the interrupt pending flag and runs the current program. RUN changes the memory reserved by the last CLEAR statement. RUN causes parts of the program to be compiled at speed execution. A typical program will compile at about 800 lines per second. RUN may also be used at run time with the optional line number.
SAVE Commands SYNTAX: SAVE SAVE segment SAVE DATA,to Flash segment, to Flash address, from RAM segment, from RAM address, length PURPOSE: SAVE saves programs and data to flash EPROM. REMARKS: Some cards, such as the RPC-150 and RPC-2300, only allow the first syntax, SAVE. Cards with 128K or more of flash EPROM allow saving more than 1 program. These same cards also allow saving binary data. Refer to your hardware manual to see if it supports 128K of flash. The RPC-150 and RPC-2300 do not.
SIN Numeric Function SYNTAX: n = SIN(m) PURPOSE: To calculate the trigonometric sine function. REMARKS: m is an angle in radians. To convert degrees to radians, multiply by PI/180 where PI = 3.141593. RELATED: ATN, COS, TAN EXAMPLE: PRINT SIN(1.5) .
START BIT Tasking Statement SYNTAX: START BIT task number [,task number]. . . PURPOSE: To enable a BIT task that has previously been defined with an ON BIT statement. REMARKS: You can disable the task using the STOP BIT statement. The START BIT statement will start the last task that was declared by the ON BIT statement. If you use START BIT without first defining the task with the ON BIT statement, CAMBASIC cannot know whether a valid task exists.
START COUNT Tasking Statement SYNTAX: START COUNT n [,n1] [,nm] PURPOSE: To activate a software counter task that was previously defined. REMARKS: Once one or more counters have been defined by the CONFIG COUNT statement, the counter is activated by the START COUNT statement. Until that time no counts will be accumulated. The range of n is 0 to 7, which is the counter number. See the Multitasking Chapter for more information.
START INP Tasking Statement SYNTAX: START INP n [,n1] [,n2] PURPOSE: To enable one or more INP tasks declared by the ON INP statement. REMARKS: The task parameters are defined by the ON INP statement. START INP activates the task. NOTE: You must execute an ON INP statement first for each corresponding START INP. You may start more than one task at a time. RELATED: STOP INP, ON INP See the Multitasking Chapter for more information.
STOP Statement SYNTAX: STOP PURPOSE: To terminate program execution and return to command level. REMARKS: STOP statements may be used anywhere in a program to terminate execution. When a STOP is encountered, the following message is displayed: where nnn is the line number where the STOP occurred. CAMBASIC always returns to command level after a STOP is executed. Execution is resumed by issuing a CONT command (see “CONT Command”).
STOP BIT Tasking Statement SYNTAX: STOP BIT task [,task] . . . PURPOSE: To disable a bit that has previously been defined with an ON BIT statement and enabled with a START BIT statement. REMARKS: You can reenable the task by using the START BIT statement. You do not need to reexecute the ON BIT statement. See the Multitasking Chapter for more information.
STOP COUNT Tasking Statement SYNTAX: STOP COUNT n [,n1] [,nn] PURPOSE: To deactivate a software counter task that was previously active. REMARKS: This statement is used to suspend a counter that has previously been started. The accumulated count is not changed. You can restart the counter at the same point by executing START COUNT. The range of n is 0 to 7. See the Multitasking Chapter for more information.
STOP INP Tasking Statement SYNTAX: STOP INP n [,n1] [,n2] PURPOSE: To disable one or more INP tasks declared by the ON INP statement. REMARKS: The task parameters are defined by the ON INP statement. STOP INP deactivates the task. You may specify more than one task parameter so that several tasks may be stopped simultaneously. NOTE: STOP INP is only executed after a START INP has been executed. RELATED: START INP, ON INP See the Multitasking Chapter for more information.
STR$ String Function SYNTAX: n$ = STR$(m) PURPOSE: To convert a number to a string. REMARKS: For positive numbers, the string generated by STR$ has a leading blank. See the VAL function for its complement. RELATED: ASC, CHR$, VAL EXAMPLE: 10 A$=STR$(3.14159) 20 PRINT "PI=";A$ RUN PI=3.14159 10 A=8 20 IF STR$(A) <> " 8" THEN END 30 PRINT "OK" NOTE: In this case a space is required in " 8" since all positive numbers are printed with a leading space.
SYS System Function SYNTAX: a = SYS(n) PURPOSE: To access system data and addresses. REMARKS: n is the system number.
The SYS(6) and SYS(7) will return 0 if no error has occurred. Any nonzero value means an error has occurred and you can request the host to retransmit the data. The advanced user may want to know which of the three errors has occurred. The SYS function will return 64 for an overrun error, 32 for a parity error, and 16 for a framing error. Keep in mind that an incorrect baud rate could cause any one of these errors, since the incoming bits would be out of time synchronization with the UART clock.
TAB Print Function SYNTAX: PRINT TAB(m) PURPOSE: To tab to position m. REMARKS: m ranges from 0 to 255 If the current print position is at or beyond space m, TAB is ignored.
TAN Numeric Function SYNTAX: n = TAN(m) PURPOSE: To return the trigonometric tangent of m. REMARKS: The angle m must be in radians. To convert degrees to radians, multiply by PI/180 where PI = 3.141593. RELATED: ATN, COS, SIN EXAMPLE: 10 PRINT TAN(1.5) 14.
TICK Process Function SYNTAX: a=TICK(n) PURPOSE: To return the time from the TICK timers. REMARKS: There are three TICK timers in CAMBASIC that accumulate on a 12 hour basis. These are separate from the calendar/clock and are not battery-backed. n is from 0 to 2, corresponding to the tick timer. The functions return the time in 0.005 (0.010 in 9 Mhz systems) second increments up to 12 hours.
TIME$ Function SYNTAX: a$ = TIME$(n) PURPOSE: The TIME$ function is used to read the system calendar/clock. The system clock keeps time on a 24 hour basis with a resolution of one second. REMARKS: The time is returned in two forms, depending upon the value of the argument n. When n=0, the hours, minutes and seconds are returned. When n=1, the minutes and seconds are returned. The clock is set by the TIME$ statement.
TIME$ Statement SYNTAX: TIME$ = time string PURPOSE: TIME$ is used to set the time on the system calendar/clock. The clock keeps time on a 24 hour basis with a resolution of one second. REMARKS: The time string may be a variable or a constant. In either case the format is the same. The string must be in the form: hh:mm:ss where hh is the hour and ranges from 01 to 23, mm is the minute (00 to 59) and ss the second (00 to 59). NOTE: No error checking is done on the entries.
TRON/TROFF Statement SYNTAX: TRON TROFF PURPOSE: To trace program execution and/or display variable values. REMARKS: You execute TRON to turn on the trace and TROFF to turn the trace off. It may be executed in the immediate mode to trace a whole program or be placed within a program to trace only a section. WARNING: RELATED: none EXAMPLE: 10 20 30 40 50 TRON and TROFF must be the only command or last command on a line. TRON FOR X = 0 TO 3 A = X NEXT TROFF RUN .20..30..40..30..40..30..40..30..
VAL Numeric Function SYNTAX: n = VAL(m$) PURPOSE: To convert a string to a number. REMARKS: The VAL function strips leading spaces from m$ before calculating the result. A leading alphanumeric character will always cause zero to be returned, regardless of the characters that follow the alphanumeric character. Trailing alphanumeric characters are ignored.
VARPTR Numeric Function SYNTAX: VARPTR(variable) PURPOSE: To return the address in RAM of the variable. This command is similar to VARPTR found in other BASICs. Unlike VARPTR, the address of a string variable is returned directly. REMARKS: variable is any CAMBASIC variable. This function may be used to pass data other than single bytes to external machine or assembly language routines. It is also used to find uncommitted RAM for temporary data storage.
On power–up, you have 100 bytes of string space. You can change this with the CLEAR statement. (Beneath the string area is the stack). Thus, unused RAM extends from the top of the array space to the bottom of the stack. EXAMPLE 1: 10 A = 1.1 20 B = VARPTR(A) 30 PRINT B ; 40 FOR X = 0 TO 3 50 PRINT PEEK(B+X) ; 60 NEXT : PRINT RUN 17487 205 204 12 129 This example is for a simple numeric variable.
CONFIG BAUD Statement SYNTAX: CONFIG BAUD n,baud rate, mode, parity [,com] PURPOSE: To change the serial port parameters. REMARKS: The power–up default for COM1 is: 19,200 baud 8 data bits and 2 stop bits no parity The power–up default for COM2 is: 19,200 baud 8 data bits and 1 stop bit no parity RS-232 All these parameters are programmable. Once programmed, the serial parameters will remain in place even when the program stops.
0 = RS-232 (default) 1 = RS-422 (transmitter always on) 2 = RS-485 RELATED: none EXAMPLE: 10 CONFIG BAUD 1,6,5,0 This sets COM1 for the default values. ERROR: – all parameters – if illegal baud, mode or parity parameter.
CONFIG BREAK Statement SYNTAX: CONFIG BREAK com port,mode PURPOSE: To enable or disable response to a break character on a communications port. REMARKS: In normal operation an to COM1 while the program is running will stop program execution. The same is true for ˆC in an INPUT statement. This response is disabled with CONFIG BREAK. The com port parameter is 1 or 2. The mode parameter tells the system whether or not to suppress break. A “0” will allow normal break operation.
CONFIG CLOCK Statement SYNTAX: CONFIG CLOCK mode,run CONFIG CLOCK run (RPC-2350 series only) PURPOSE: Configures real time clock for 12 or 24 hour modes and starts or stops the clock. REMARKS: The TIME$ function returns the time in 12 or 24 hour formats. Set mode = 0 for 12 hour time and 1 for 24 hour time format. run turns the clock on and off. 0 = off or stopped, 1 = on or run. RELATED: TIME$, DATE$ EXAMPLE: CONFIG CLOCK 1,1 Sets to clock to 24 hour mode and starts it running.
CONFIG COM$ Tasking Statement SYNTAX: CONFIG COM$ n,terminator,length,XON,echo PURPOSE: To configure a communication port to interrupt when the programmed conditions are met. REMARKS: The CONFIG COM$ statement is used in conjunction with the ON COM$ statement so that the foreground program is interrupted when either a specific message length has been received or a specified termination character has been received. n = legal serial port number.
CONFIG COUNT Tasking Statement SYNTAX: CONFIG COUNT number,address,bit [,preset] [,AUTO] PURPOSE: To define the characteristics of a software counter. REMARKS: The CONFIG COUNT statement is the initial step in setting up a software counter. Up to eight counters can be defined. A counter input may be any digital input. The counter number has a range of 0 to 7. The address is the address of a parallel I/O port. The bit parameter specifies bit 0 through 7 of that port.
CONFIG DISPLAY Statement SYNTAX: CONFIG DISPLAY address,type,cursor PURPOSE: To install a driver for a display REMARKS: CAMBASIC supports eight vacuum fluorescent (DP series) and liquid crystal (LCD) displays. When the CONFIG DISPLAY statement is executed, a driver is installed that tells CAMBASIC the I/O address, type and cursor. The address is the address of the output port at which the display is located. See your hardware manual for more information.
510 520 530 540 550 560 570 580 590 600 610 620 ERROR: CONFIG DISPLAY & 40,3,0 DISPLAY “REMOTE PROCESSING”; DISPLAY (3,1) “Tick = “; DISPLAY (3,8); PRINT#9,!”###.
CONFIG PIO Statement SYNTAX: CONFIG PIO init,port A,port B, port LC, port UC [,address] PURPOSE: To initialize an 82C55 parallel I/O IC. REMARKS: The 82C55 parallel I/O IC has four I/O ports. Each port can be programmed as input or output. They are defined as follows: Port A Port B Port LC 4 bits Port UC 8 bits 8 bits 4 bits 0 to 3 0 to 7 0 to 7 4 to 7 The init parameter is the value you want output ports to be after the command is executed. The 82C55 initializes itself to all inputs on power–up.
PROGRAM DEBUGGING CAMBASIC has several constructs which can be used to debug a program. This section will outline the methods and give examples. Using the STOP statement When a STOP statement is encountered, program execution halts and the line number containing the stop statement is displayed. By inserting the STOP statement in different sections of the program, you can determine whether these sections are being executed.
90 INC H 100 RETURN RUN .30..40..90..100..50..40..90..100..50..40..90..100..50..60. USING MON TO EXAMINE MEMORY When storing data into memory, it is sometimes necessary to verify that a block is correct. You can display 128 bytes at a time with the MON "D" command. The syntax is: MON>D address [segment] where address is the starting address in hexadecimal. The command will display 8 lines of 16 bytes. The optional segment parameter can be used to view memory segments above segment 0.
The following list of error messages are returned by CAMBASIC. These indicate clearly, what is wrong, within the context of a program, and should be of great use in program debugging. NUM MESSAGE EXPLANATION 0 Error is undefined 1 A NEXT statement is encountered without a matching FOR. 2 A line is encountered that includes an incorrect sequence of characters (misspelled keyword, incorrect punctuation, etc.).
NUM MESSAGE EXPLANATION 12 A statement that is illegal in Immediate Mode is entered as an Immediate Mode command. 13 A string variable name is assigned a numeric value or vice–versa; a function that expects a numeric argument is given a string argument or vice versa. 14 String variables have caused CAMBASIC to exceed the amount of free memory remaining. CAMBASIC will allocate string space dynamically, until it runs out of memory.
NUM MESSAGE EXPLANATION 27 255> The argument or parameter may not exceed 255. 28 65,535> The argument or parameter may not exceed 65,535. 29 Program does not exist in EEPROM. 30 CAMBASIC is expecting a left parenthesis or an expression. 31 CAMBASIC is expecting a right parenthesis. 32 CAMBASIC is expecting a right bracket. 33 Another parameter or argument is expected.
Event Multitasking Event Multitasking was developed to give faster response to real time events. It is different than the multitasking that was originally designed for business applications and later used in some industrial control languages. Time Slice Multitasking – The Old Way This older form of multitasking usually takes two forms. The most popular is called “time slice.” Each task is written as if it were a separate program.
There are a few exceptions. The INPUT and INPUT KEYPAD$ statements will ignore interrupts until the input is received. The DELAY statement will prevent a response to an interrupt until the delay period. If the serial output buffer becomes full, and there are still more characters to put in the buffer, interrupts will not be serviced until all the characters are in the buffer. Interrupt Priorities CAMBASIC does not have an interrupt priority scheme.
Each counter may be assigned through software to any digital I/O line on any Control or expansion card. Once configured, counting is done independently in the background. The counters have the following features: 1. The count rate may range from 0 to 80 Hz. 2. The counters may be read at any time with the COUNT function. This function is synchronized with the counter so that valid data is always read. 3.
CONFIG COUNT counter, address, bit [,preset] [,AUTO] Where: counter is the counter number which may be 0 through 7. address is the I/O address of the port (of 8 bits) that you want to use for the input. This will typically be an 82C55 port. bit is the particular bit or line of the port addressed. The range is 0 through 7. preset is an optional parameter that tells the counter to notify the system when a preset count has been reached. The program will branch if an ON COUNT statement has been executed.
Line 10 configures counter 5 to read bit 1 of address 0 as an input. When the count reaches 2000, the counter will automatically reset. Line 20 directs CAMBASIC to branch to a subroutine when the preset count is reached. Line 30 starts counter operation. These three lines do not need to be adjacent in the program. However, they must be executed in this order. Line 200 increments variable A. Thus, the value of A is the number of times the counter has counted to 2000.
NOTE: It is theoretically possible for the subroutine to take so long to execute that another 2000 counts is reached. In this unlikely case, the subroutine will interrupt itself. CAMBASIC is not recursive. The effect of this is that the second interrupt may change variables that the first interrupt has yet to use. This situation can be avoided by careful programming and by detailing the system timing. It is always a good idea to keep interrupt routines as short as possible.
You can try this by holding down the on your terminal so that it auto–repeats and enters count faster. INP TASKING INP tasking lets you react to a combination of on/off conditions at a digital I/O port. That is, you may want to detect when inputs 0, 1 and 7 are high, and inputs 2 and 3 are low, while ignoring the other input lines (4, 5, 6). There are a total of 8 tasks that can be configured. The ON INP statement sets the interrupt conditions. The START INP is used to activate the task.
parameters and are bits 0, 1 and 2. When the data at the port is ANDed with 7, and the value is 5 (bits 0 and 2 are high and bit 1 is low), the program branches to line 50. Line 20 prints the binary representation of the port of interest so that you can see the bits pattern while you experiment. Line 30 actually starts the tasking process. Line 40 creates a small delay so that the binary string printing is easily readable. Line 50 repeats the printing. Line 60 lets you know that an interrupt has occurred.
A=KEYPAD$(1) returns the key position number to a numeric variable. A zero is returned if no key was pressed. For large keypads, the legends often contain some words and symbols in addition to letters. The variation is most suited for these cases. Assigning Character String to Keys A table in RAM can be programmed to return any ASCII value. The table is set up so that the first character is the upper–left–hand corner and the last character is the lower–right–hand corner.
55 60 65 70 75 80 85 90 95 B$=KEYPAD$(0) IF B$=CHR$(13) THEN ..Get_value IF B$="*" THEN B$="." A$=A$+B$ RETURN ..Get_value R=VAL(A$) A$="" RETURN Line 30 tells CAMBASIC to call a subroutine by the name of “Keypad_interrupt” every time a key is pressed. Line 35 prints the number that the input string will be converted to. Initially, it will be zero. Line 40 is a 0.25 second delay for demonstration purposes. Line 45 is used only as part of this demo program so that the system will wait.
250 RETURN and so forth. Line 40 tells CAMBASIC to call a subroutine by the name of “Keypad_interrupt” every time a key is pressed. Line 50 is used only as part of this demo program so that the system will wait. You could insert the rest of your control program. Line 70 assigns the input position to variable K. Line 90 returns program execution to the place that was executing before the key was pressed. However, the program should never get to this point if 16 line numbers are specified.
MULTITASKING ON A CLOCK TICK The three 200 Hz (100 Hz in 9 Mhz systems) tick timers are used for a number of multitasking functions in CAMBASIC. In multitasking, it is used as a periodic interrupt. The ON TICK statement can call a subroutine as often as 200 (100 in 9 Mhz systems) times per second, or once every 327.67 seconds. The syntax is: ON TICK number, time GOSUB line/label On every multiple of the specified time, program execution branches to the subroutine at the line/label.
PULSE MULTITASKING Introduction CAMBASIC supports eight timed (or pulsed) outputs. These are generated in software and have a resolution of 10 mS. Each timer may be assigned through software to any digital I/O line on any CPU or expansion card. Once configured, timing is done independently in the background. The timers have the following features: 1. The time resolution is 5 mS (10 ms in 9 Mhz systems) 2. The timers may be read at any time with the PULSE function. 3.
Timer 0 is configured at address 0 and bit 1. The wait time is 0.05 seconds. The output will go high for 0.06 seconds at the end of the wait period, and then go low. The PULSE function returns the remaining time of each stage. If the return is negative, the number is the time left in the wait stage. If the return is positive, the number is the remaining part of the active time. The example below demonstrates this. 10 30 40 50 PULSE 0,0,1,.05,1 A = PULSE(0):IF A=0 THEN STOP PRINT A GOTO 30 RUN –.05 –.05 –.
DIFFERENCES—CAMBASIC vs QBASIC 1. CAMBASIC is a multitasking language while the others are not. This adds features to the language and also some limitations. 2. CAMBASIC does not support disk or direct video commands on 64180 systems. 3. CAMBASIC has an automatic floating point math system. which automatically converts from floating point to integer and back as needed. Values are always stored in floating point.
THE CAMBASIC MINI–MONITOR The Mini–Monitor is included in CAMBASIC primarily for those who will be combining object code (either from assembly or “C”) programs with CAMBASIC. The command set will let you examine and edit memory, and single step using the breakpoint feature. You enter the Mini–Monitor by typing: >MON While in the monitor, the prompt will change from the normal “>” to: MON> You can exit the monitor by typing at the monitor prompt.
Edit Memory This routine lets you poke hex values into memory. For example, to edit at A000, you enter the command below. The “*” prompt is for the data. Enter the data and type . The data and addresses will then be displayed for easy verification. MON>E A000 *01 22 4D C3 20 00 7A 23 C9 A000 A001 A002 A003 A004 A005 A006 A007 A008 01 22 4D C3 20 00 7A 23 C9 This command can only be used in segment 0, since this is the only segment where code may be executed.