Glossary of Keywords
REM
Variable Declaration
KERNEL
GLOBAL
LOCAL
STATIC
CONSTANT
DIM
DECLARE
Variable Assignment
LET
DATA, READ, RESTORE
Procedures
INCLUDE
SUBROUTINE
FUNCTION
CALL
CRITICAL
VITAL
END
Control Loops
IF, [ELSE], ENDIF
SELECT, CASE, [ELSE], ENDSELECT
DO WHILE, [EXIT], LOOP
DO, [EXIT], LOOP UNTIL
FOR, STEP, EXIT, NEXT
EXIT
Interrupt Control
ON TIMERx, SET TIMERx TO
ON INTx
ON ERROR
ON COMx
Task Control
START
STOP
RUN
SUSPEND
SET TIMESLICES TO n
REBOOT
Memory Commands
PEEK
POKE
DPEEK
DPOKE
I/O Space
IOPEEK
IOPOKE
Off-Board Memory
MEM_PEEK
MEM_POKE
MEM_DPEEK
MEM_DPOKE
EEPROM
EEPROM_SIZE
EEPROM_POKE
EEPROM_PEEK
Flash Memory
FLASH_DPEEK
FLASH_DPOKE
FLASH_ERASE
FLASH_AVL
RAM Memory
RAM_AVL
Real-Time Clock
TIMEDATE_PEEK
TIMEDATE_POKE
RTC_PEEK
RTC_POKE
Power Management
NAP
SLEEP
HIBERNATE
Data Manipulation
SIZE_OF
ADDR
ROWS_OF
COLS_OF
String Manipulation
HEX
DEC
REM
ASC
CHR
VAL
FVAL
STR
FSTR
LEN
Math Operators
MIN
MAX
SIN
COS
ARCTAN
ABS
LOG
Onboard Peripherals
KEYPAD
BEEP
PWM
COUNT
Output
PRINT
PIPE
INPUT
LCD Functions
LCD_COMMAND
Serial Communications Port Control
COMM
Using The DEV Port as a Serial Port
MODE
PTT
KEY_PENDING
INKEY
GET_TIMEOUT
IIC and SPI Commands
VAST_OPEN( )
VAST_CLOCK( )
VAST_CLOSE( )
VAST_SPI_XFER( )
SPI transfer Example
VAST_IIC_START( )
VAST_IIC_STOP( )
VAST_IIC_SEND( )
VAST_IIC_READ( )
IIC Transfer Example:
Digital and Analog I/O
Digital I/O
VDIO_CONFIG ()
VSET()
VRESET(
VOUT()
VTEST()
Analog Input
AIN_CONFIG()
AIN()
Analog Output
AOUT_CONFIG()
AOUT()
Configuring Off-board Serial Ports
COMM_BUFFER()
LED Matrix Control
VLED_COMMAND()
VLED_MATRIX()
VLED _7SEGMENT()
REM
Use the REM statement to add comments or remarks to your program that make your
code easier to read and easier to debug.
Where:REM text
- "text"
- is any comment you choose.
Example:* The compiler ignores all text following the REM keyword. Remarks do not affect the size of your compiled code.
* We recommend that you use REM statements to fully comment your code, describing what it does and how it works.
* REM cannot be used as the last line of your Vesta Basic programs.
* When remarks are placed at the end of a statement, a colon is required to denote the end of the previous statement.
REM Set up the timeout counter timeout = 100 :REM 100 ticks of REM system clock
Variable
Declaration
Declaration statements define the storage class of a variable.
All variables must be declared in advance of use. More than one variable may
be declared in a storage class statement. Variables in a list may be any of
the four data types. A variable name can contain up to 30 characters. Names
reserved for Vesta Basic commands and functions cannot be used as variable names.
A. Storage class statements that are appropriate the main procedure.
1. KERNEL
2. GLOBAL
B. Storage class statements that are appropriate inside subroutines and functions.
1. LOCAL
2. STATIC
KERNEL
The Kernel statement declares a variable, defines it's type, and identifies
it as shared among multiple tasks.
Where:KERNEL var1 AS TYPE <, var2 AS TYPE>
- "var1"&"var2"
- are the names of the kernel variables.
- "TYPE"
- is the data type of the variable and can be string, float, long or integer. See Data Types for more information.
* Each task that will access a particular kernel variable must declare the variable using the same name and type.
* Kernel variables may be referenced in any task that declares them. Kernel variables follow the same declaration rules as global variables. The only difference is that they can be shared among tasks. A kernel variable exists and maintains its contents until the board is reset. The kernel variable is created and initialized upon first use by any task.
Example:
Declares a floating-point variable named fvar1, and a string variable named svar2.KERNEL fvar1 AS FLOAT, svar2 AS STRING
GLOBAL
The Global statement declares a variable, defines its type, and identifies it
as accessible from within the current task, but not outside of it.
Where:GLOBAL var1 AS TYPE <, var2 AS TYPE>
- "var1"&"var2"
- are the names of the global variables.
- "TYPE"
- is the data type of the variable and can be string, long, integer, or float. See Data Types for more information.
* Global variables are usually declared just before the main procedure (the first executable statement.) They cannot be declared after the first executable statement in the main procedure. A procedure will not have access to a global variable unless it is defined after the global variable.
* If you require access to a global variable within certain procedures, the global variable must be declared before the first procedure that references it. A good practice is to declare, at the beginning of your code, a small set of global variables that must be shared. Declare all others just before the main procedure. The simplest solution is not to use global variables in procedures if possible. Instead, pass values to procedures as needed.
* At application startup, global variables are initialized to zero.
Example:
GLOBAL ivar1 AS INTEGER, svar1 AS STRING
Declares an integer variable by the name ivar1, and a string variable named svar1.
This declaration cannot be inside a function or subroutine definition, and it
cannot occur after any executable code in the main procedure.
LOCAL
The Local statement declares a variable, defines it's type, and identifies it
as accessible from within the current function or subroutine, but not outside
of it.
Where:LOCAL var1 AS TYPE <, var2 AS TYPE>
- "var1" & "var2"
- are the names you give your LOCAL variables.
- "TYPE"
- is the data type of the variable and can be string, long, integer, or float. See Data Types for more information.
* The value of a variable declared with LOCAL is set to zero each time the function or subroutine is entered.
* This declaration must be inside a function or subroutine definition, and it cannot occur after any executable code in the function or subroutine.
* Local variables (declared with the LOCAL keyword) are only accessible within the subroutine or function that declared them. No other procedures can reference that particular variable.
Example:
LOCAL ivar2 AS INTEGER
Declares an integer variable named ivar2.
STATIC
The STATIC keyword declares a variable that can only be accessed from within
a subroutine or function, and also retains its contents from one execution of
the procedure to the next.
Where:STATIC var1 AS TYPE <, var2 AS TYPE>
- "var1" & "var2"
- are the names you give your STATIC variables.
- "TYPE"
- is the data type of the variable and can be string, long, integer, or float. SeeData Types for more information.
* This declaration must be inside a function or subroutine definition, and it cannot occur after any executable code in the function or subroutine.Example:
* The value of a variable declared with STATIC will be preserved until the next time function or subroutine is entered. Static variables are local variables that retain their contents between calls to the procedure.
* At startup, STATIC variables are initialized to 0.
* STATIC variables must be declared inside the function or subroutine definition and before any executable code in the function or subroutine.
* STATIC variables are allocated from global RAM space. STATIC integer variables require 2 bytes of RAM, STATIC float variables require 4 bytes of RAM. Static variables may also be of the BIT type.
* The value of a variable declared with STATIC will be preserved until the next time function or subroutine is entered. At task startup, static variables are initialized to 0 or the empty string.
Declares a long variable by the name lvar1.STATIC lvar1 AS LONG
CONSTANT
The CONSTANT keyword identifies a value that will not change. The compiler has
ways to optimize code when data is identified as CONSTANT.
Where:CONSTANT name AS TYPE=value
- "name"
- is the name you assign to the constant.
- "TYPE"
- is the data type of the constant and may be string, float, long or integer. SeeData Types for more information.
- "value"
- is the content you assign to the constant.
Example:
CONSTANT pi AS FLOAT = 3.14159 CONSTANT crlf AS STRING = "\013\010"
DIM
DIM creates and allocates memory for arrays.
DIM name[index<,index>] AS TYPE <IN RAM / IN FLASH / IN EEPROM /
Where:IN EEPROM = address / = address / CONSTANT = [list] >
- "name"
- is the name of the array.
- "index"
- a variable or literal indicating the maximum number of elements associated with each dimension of the array.
- "TYPE"
- is the data type of the array elements and can be bit, byte, integer, or float. See Data Types for more information.
- "address"
- a variable or literal the address location where the array begins.
- "list"
- is a list of constant values for each position in the array.
* The "IN RAM", "IN FLASH", "IN EEPROM", "IN EEPROM = address", "= address ", and "CONSTANT = [list]" constructs are mutually exclusive, you may not use more than one of these constructs in the same DIM statement.
* Use the "IN RAM" construct to allow the compiler to assign a location in RAM.
* Use the "IN FLASH" construct to allow the compiler to assign a location in Flash.
* Use the "= address" construct to specify a particular memory location.
This memory location may be in RAM, Flash or RTC memory depending on the address you specify. See the Vesta Multi-tasking Hardware Manual for information on the memory maps of the various Multitasking engines.
Although the "=address" construct allows you to specify a location RAM, Flash or RTC memory, the "IN FLASH", "IN RAM" and "=address" constructs are mutually exclusive. You may use "IN FLASH", "IN RAM" or the "=address" construct but not two or more on the same line.
To specify a location in EEPROM you must use the "IN EEPROM = address" construct rather than the "= address" construct alone with an address specified that happens to be in EEPROM.
* Use the "IN EEPROM" construct to allow the compiler to assign a location in EEPROM.
* Use the "IN EEPROM = address" construct to assign an array to a specific location in EEPROM.
* Arrays may be located at any address in EEPROM by specifying the address after the equal sign. The SBC2000-332 and SBC2000-188 will increase the address specified to the next 16 byte boundary. Do not use IN FLASH or IN RAM if specifying the address in memory. You must use IN EEPROM whether or not you specify a starting address for arrays stored in EEPROM.
* Use the "CONSTANT = [list]" construct to set up an array where the data will not change. The values provided in the list must be of a type compatible with the type specified for the array, delimited by commas, and enclosed in quotes if the array type is string.
The Constant statement may be split onto multiple lines beginning with the first value following the "[".
* Arrays accessed by procedures must be DECLAREd in the source before the procedure.
DECLARE x AS INTEGER ARRAY
* String arrays use 256 bytes per element.
* ADDR_OF() will return the base address of an array suitable for passing to another task in order to dimension a shared array.
* If you restart a task that allocates an array but does not prescribe an address for the array, the system will allocate memory for a new copy of the array (provided memory is available). The memory used by the first copy of the array will not be freed until the board is reset.
Example:
The DECLARE keyword allows arrays and procedures to be used before they are defined.DIM x[16] AS INTEGER DIM xy[16,16] AS INTEGER DIM sa[8] AS STRING DIM sa2[2,3] AS STRING CONSTANT = [ "Yes,"No","why","1","2","3"] DIM dat1[10] AS INTEGER IN EEPROM DIM dat2[10] AS INTEGER IN EEPROM=64 DIM dat3[1000] AS LONG = 0x200000+0x40000 :rem(4th sector of flash REM on a -332) DIM dat4[1000] AS LONG = 0x80000+0x40000 :rem(4th sector of flash REM on a -188)
Where:DECLARE FUNCTION name AS TYPE
DECLARE SUBROUTINE name
DECLARE name AS TYPE ARRAY
- "name"
- is the name you assign to the function subroutine or array.
- "TYPE"
- is the data type the function returns, which can string, float, long or integer, or the data type of the elements of the array. STOP
* Normally, a procedure cannot be invoked or an array value accessed unless it has been defined previously in the source code. The DECLARE statement allows the programmer to invoke procedures and refer to arrays that have not yet been defined.
Subroutine Example:
REM Call each other into oblivion DECLARE SUBROUTINE subroutine_2 SUBROUTINE subroutine_1() CALL subroutine_2() END SUBROUTINE subroutine_2() CALL subroutine_1() END
Array Example:
DECLARE x_array AS INTEGER ARRAY SUBROUTINE initialize_x_array() LOCAL index AS INTEGER FOR index = 0 TO 99 x[index]=0 NEXT DIM x_array [100] AS INTGER END
LET
The LET keyword is used to assign the result of an expression to a variable.
Where:<LET> variable = expression
- "variable"
- is the name of a variable.
- "expression"
- is the value that you want to assign to the variable.
* LET is an optional keyword provided for compatibility with previous implementations of BASIC.
* Cross-type assignment rules (as described in the section on Data Types) apply when using the LET statement.
Example:
LET color1 = "red" LET color2 = color1 LET intvar = floatvar / longvar color1="blue" color2=color1
DATA, READ, RESTORE
The DATA, READ and RESTORE statements work together to fill variables with specified
data values.
Where:DATA cnst1<, cnst2, >
READ var1<, var2, >
RESTORE
- "cnst1" & "cnst2"
- are the data values that will fill the variables. This list may be several lines long.
- "var1" & "var2"
- are the names of the variables being filled by corresponding data values.
* The DATA statement is used to initialize variables of various data types. The DATA constants are available as if they were GLOBAL. DATA statements can only occur in the main procedure, but their data can be READ by other procedures.
* The first READ statement accesses the first value in the first DATA statement and assign it to the first variable in the READ list. Subsequent READ statements assign the next sequential data value to the next read variable.
* RESTORE will reset the READ pointer to the first item in the first DATA statement.
* Each value should be the same type as the variable into which it is read. If it is not, the cross-type assignment rules will apply. A run-time error will result if an attempt is made to assign string data to non-string variable, or vice versa.
* DATA constants may occupy more than one line. All separate DATA statements are treated as a single, long DATA statement.
* See Arrays, for a more efficient method of initializing constant data.
Example:
DATA 10, 20, 1.25 READ intvar, intvar2 :REM intvar=10, intvar2=20 DATA 2, 5, 15, "hello" READ floatvar :REM floatvar=1.25 READ intvar, intvar2 :REM intvar=2, intvar2=5 RESTORE READ intvar :REM intvar=10
INCLUDE
The INCLUDE "file" directive serves as a pointer to files written
in Vesta Basic that reside outside your main program, for compilation as part
of your application.
Where:INCLUDE "path"
- "path"
- is the name and path, in quotes, of the file to be compiled as part of your program.
* The current project directory as established by the "Look in" box of the File|Open window in the IDE will be searched unless an alternative path is specified.
* INCLUDEd files will not be stepped or animated by the IDE. In effect this provides a "step over" feature. If you do not want subroutines or functions animated, INCLUDE them in a separate file and animation will step over these procedures instead of stepping through them.
* Errors caused by the code within external procedures (INCLUDEd files) make error reporting difficult to follow. Be sure your INCLUDE files are fully debugged and that you have not duplicated any variable, constant or procedure names in your source.
Example:
INCLUDE "Myfile.TXT" INCLUDE "C:\DATA\VBSOURCE\Myfile.TXT" INCLUDE "..\COMMON\Myfile.TXT"
SUBROUTINE
The SUBROUTINE definition identifies a separate, self-contained procedure that
may receive arguments but does not return a value, and it declares the names
and types of any arguments the subroutine receives. It also tells the compiler
that the subroutine is defined by the statements that follow, up to the END
statement.
Where:< CRITICAL / VITAL> SUBROUTINE Name (<arg1 AS TYPE><,argn AS TYPE>)
statements
<RETURN>
END
- "CRITICAL"
- is a keyword that protects the procedure against interruption from other tasks.
- "VITAL"
- is a keyword that protects the procedure against interruption from the Event-handler.
- "Name"
- is the name of the subroutine.
- "arg1" - "argn"
- are the input arguments for the subroutine.
- "TYPE"
- is the data type of each variable, and can be string, float, long or integer. See Data Types for more information.
- "statements"
- are Vesta Basic statements that make up the subroutine.
* Subroutines do not return any data, therefore they do not have an associated data type.
* Neither the keyword SUBROUTINE nor the name you assign to the subroutine are case sensitive.
* A subroutine may invoke other subroutines, functions or itself.
* Subroutines are invoked using the name of the subroutine and any arguments it receives, optionally preceded by the CALL keyword. Any other procedures that a subroutine invokes must either be already defined or prototyped using the DECLARE statement, prior to the subroutine definition.
CALL tone(333, 400)
* Subroutines must end with END statement.
* The RETURN statement transfers control back to the calling procedure.
* The VITAL keyword disables the event-handler until the specified function or subroutine has completed. Event-driven procedures (all ON functions e.g. ON TIMER, ON COM, ON INT and ON ERROR.) will be suspended until the current VITAL function or subroutine has completed. ON events must specify a VITAL subroutine. VITAL procedures may call only other VITAL procedures. See VITAL.
* The CRITICAL keyword prevents other tasks from executing until the CRITICAL task is exited. See CRITICAL.
* Because subroutines do not return a value, they are best suited for output routines such as PRINT, BEEP, or POKE.
* The arguments used to pass values to the subroutine behave like local variables that have been initialized by the calling routine. These arguments are copies of the data being passed by the calling procedure.
* If you want to give a subroutine access to a global variable, the global variable declaration must precede the subroutine definition.
* A maximum of 62 bytes of formal parameters may be passed into a procedure. A string parameter occupies 4 bytes.
For example:
o 15 LONG values is ok, 16 LONG data is not.
o 31 INTEGER values is ok, 32 INTEGER data is not.
* A maximum of 32 bytes of LOCAL variable storage may be declared. String variables count as 4 bytes.
For example:
o 8 LOCAL variables AS LONG is ok, 9 is not.
o 16 LOCAL variables AS INTEGER is ok, 17 is not.
* There is no limit to the number of STATIC variables that may be declared within a procedure.
Example:
SUBROUTINE delay (arguement AS INTEGER) LOCAL index AS INTEGER FOR index = to arguement RETURN NEXT END DO PRINT "." DELAY(100) LOOP UNTIL 0
Example:
DECLARE Tone(freq AS INTEGER, duration AS INTEGER) GLOBAL fholder AS INTEGER=100, dholder AS INTEGER=200 SUBROUTINE Tune fholder=100 dholder=100 FOR foo = 1 TO 20 fholder=fholder+foo dholder=dholder-foo Tone (fholder,dholder) NEXT foo BEEP (0) END SUBROUTINE Tone (freq AS INTEGER, duration AS INTEGER) LOCAL interval AS INTEGER BEEP(freq) FOR interval = 1 TO duration REM because you can't have empty loops NEXT interval END CALL Tune
FUNCTION
FUNCTION declares a procedure to be one that returns a value, declares the data
type of the value that the function returns, and the names and data types of
any variables that the function expects to receive. It also tells the compiler
that the function is defined by the statements that follow, up to the END statement.
Where:< CRITICAL / VITAL> FUNCTION Name (<arg1 AS TYPE><,argn AS TYPE>) AS TYPE
statements
<RETURN>
END
- "CRITICAL"
- is a keyword that protects the procedure against interruption from other tasks.
- "VITAL"
- is a keyword that protects the procedure against interruption from the Event-handler.
- "Name"
- is the name of the function.
- "arg1" - "argn"
- are the input arguments for the function.
- "TYPE"
- is the data type of the argument variables which can be string, integer, long or float; and the final TYPE is the type of the value returned by the function, which may also be string, long, integer, or float.
* All functions return a value. This value is initialized to zero when the function is invoked. The value that the function returns is set within the function by assigning the value to the function's name.
* Neither the keyword FUNCTION nor the name that you assign to it is case sensitive.
* Functions may invoke other functions, subroutines, or themselves. In order for another procedure to invoke a function, the function must either be placed before the invoking procedure in the program code or the function must be prototyped with a DECLARE statement previous to any procedure that uses the function.
* Functions are called by using the function's name as a variable in an expression. The functions name represents the value that the function returns.
* Functions must end with an END statement.
* The RETURN statement transfers control back to the calling procedure.
* For procedures that must complete execution without interruption, the VITAL keyword disables the event-handler until the specified function or subroutine has completed. Event-driven procedures (all ON functions) will be suspended until the current VITAL function or subroutine has completed. ON events must specify a VITAL procedure. VITAL procedures may call only other VITAL procedures. See "VITAL" below.
* The CRITICAL keyword prevents other tasks from executing until the CRITICAL task is exited. See "CRITICAL" below.
* The list of arguments used to pass values to the function is similar to local variables that have been initialized by the calling routine. These arguments are copies of the data being passed to the procedure by the calling procedure.
* If you want to give a function access to a global variable, the global variable declaration must precede the function definition.
* A maximum of 62 bytes of argument data may be passed into a function. Each string parameter occupies 4 bytes.
* A maximum of 32 bytes of LOCAL variable storage may be declared for each Function. String variables count as 4 bytes.
* There is no limit to the number of STATIC variables declared within a procedure.
Example 1:
FUNCTION Factorial(num AS INTEGER) AS INTEGER LOCAL index AS INTEGER Factorial = 1 IF num <= 1 RETURN ENDIF FOR index = num TO 1 STEP -1 Factorial = Factorial * index NEXT index END PRINT Factorial(5)
Example 2:
FUNCTION Square_root (num AS FLOAT) AS FLOAT Square_root = num ^ 0.5 END result = Square_root (x) result = 7+Square_root (9)
Example 3:
FUNCTION peekword(addr AS LONG) AS INTEGER peekword=peek(addr)+peek(addr+1)*256 END FUNCTION get_key() AS INTEGER DO get_key = INKEY() :REM Call to REM function LOOP UNTIL get_key <> -1 PRINT CHR(get_key) END FUNCTION accumulate(integral_data AS INTEGER) AS INTEGER STATIC accumulator AS INTEGER accumulate = accumulator + integral_data accumulator = accumulate END
CALL
The CALL statement executes a subroutine.
Where:CALL Subname <(arg1 <,argn >)>
- "Subname"
- is the name of the subroutine.
- "arg1" - "argn"
- are the input arguments for the subroutine.
* The actual keyword CALL is optional. Subroutines may also be executed with just the subroutine name followed by any required input arguments.
Example:
DECLARE Tone(freq AS INTEGER, duration AS INTEGER) GLOBAL fholder AS INTEGER, dholder AS INTEGER SUBROUTINE Tune fholder=100 dholder=100 FOR foo = 1 TO 20 fholder=fholder+foo dholder=dholder-foo Tone (fholder,dholder) NEXT foo BEEP (0) END SUBROUTINE Tone (freq AS INTEGER, duration AS INTEGER) LOCAL interval AS INTEGER BEEP(freq) FOR interval = 1 TO duration REM because you can't have empty loops NEXT interval END CALL Tune CALL Tone (25,250)
CRITICAL
The CRITICAL keyword may be placed in a procedure definition to disable the
Task Switcher during the procedure's execution.
CRITICAL Subroutine print_string(str AS STRING)
* Some procedures must complete before task switching is allowed. The CRITICAL statement disables the Task Switcher until the specified function or subroutine has completed.
* Multitasking is resumed as soon as the current CRITICAL procedure completes.
* CRITICAL does not prevent event-driven code (i.e., procedures specified by ON statements) from being executed.
* CRITICAL procedures may only call other CRITICAL or VITAL procedures.
* CRITICAL is part of a function or subroutine declaration.
Example:
REM Print entire string before switching tasks. REM Prevents mixing of strings from different tasks CRITICAL Subroutine print_string(str AS STRING) PRINT str END
VITAL
The VITAL keyword disables the Task Switcher and Event Handler during procedure
execution.
VITAL Subroutine print_string(str AS STRING)
* Some procedures must complete before task switching or execution of any event-driven procedure is allowed. The VITAL statement disables the Task Switcher and the event handler until the specified function or subroutine has completed.
* Event-driven procedures (all ON functions) will not execute until the current VITAL function or subroutine has completed.
* VITAL is part of a function or subroutine declaration.
* VITAL procedures may call only other VITAL procedures.
Example:
REM Changes global variables used by event REM handlers REM Don't want event handler called after REM one variable changed but not the other VITAL SUBROUTINE update_globals(num1 AS INTEGER, num2 AS INTEGER) globalvar1 = num1 globalvar2 = num2
END
The END statement is used as the last statement of a procedure to indicate the
end of the procedure definition, and at the end of the main procedure to tell
the compiler that although there is no more code to execute, interrupt handling
routines are still in effect.
END
* The effect of END as the last statement of the main procedure is to allow ON events to be processed by the task after the main procedure has completed execution.
* Use STOP to cause all event processing to cease. STOP is the implied last statement of a program on the SBC2000-188 and SBC2000-332. See STOP.
* If the Multi-tasker reaches the end of executable code in a task without encountering an END statement, it will effectively STOP the task. This is especially important in that the Event-handler cannot execute a procedure in a STOPped task, but it can execute a procedure in a task that has ENDded.
Example:
VITAL SUBROUTINE dualtone(x AS INTEGER) STATIC on_off AS INTEGER STATIC tone AS INTEGER on_off = NOT on_off IF on_off tone = NOT tone SET TIMER0 TO 1 IF tone BEEP(1000) ELSE BEEP(2000) ENDIF ELSE SET TIMER0 TO 50 BEEP(0) ENDIF END REM main procedure ON TIMER0 dualtone SET TIMER0 TO 10 END
IF, [ELSE], ENDIF
These statements provide conditional execution based on the results of a true
or false evaluation of an expression.
Where:IF expression
statements1
<ELSE
statements2>
ENDIF
- "expression"
- is an expression or variable that will be evaluated as true or false.
- "statements1"
- are the statements executed if the expression is true.
- "statements2"
- are the statements executed if the expression is false.
* For the IF expression, a zero value is considered false and nonzero values are considered true for integer, float, and long expressions. An empty string expression is considered false, and a string that is not empty is considered true.
* The IF and its conditional expression must be the only statement on a line. ELSE and ENDIF must also occupy separate lines.
Example:
INPUT test IF test > 10 PRINT "greater than 10\013\010" ELSE PRINT "less than or equal to 10\013\010" ENDIF IF key = 'A' OR key = 'a' PRINT "A" ENDIF
SELECT, CASE, [ELSE], ENDSELECT
The SELECT statement evaluates an expression and searches a list of possible
cases for a match.
Where:SELECT test_expression
CASE case_value1
statements1
<CASE case_valuen
statementsn>
<CASE ELSE
statements3>
ENDSELECT
- " test_expression"
- is the expression that determines which if any case statements will be executed.
- "case_value1"
- the value that the results of test_expression must evaluate to if statements1 are to be executed.
- "statements1"
- are the statements executed if the expression evaluates to case_value1.
- "statementsn"
- are the statements executed if the expression evaluates to case_valuen and may be repeated for as many values as needed.
- "statements3"
- are the statements that will be executed if none of the case_values are equal to the test expression.
* The group of statements associated with the first matching CASE are executed. Execution then continues after the ENDSELECT keyword.
* "test_expression" can evaluate to integer, long, float or string types. It is then compared to each of the CASE "match_ statement" to determine equality. These statements may be either a constant or a variable.
* "Statements" is a group of statements that are executed for the matching case.
* "Default statements" are associated with the CASE ELSE if the latter is included and are executed when no matching CASE expressions are found. Only one CASE ELSE is allowed within a SELECT statement. CASE ELSE is optional.
* After the statements within the first matching case have completed execution, the program continues to the first statement following the ENDSELECT statement.
* SELECT and ENDSELECT must be the only statements on a line. CASE (and its associated "match_expression") and CASE ELSE must also be on lines by themselves.
* REM statements can not appear between the SELECT statement and the first CASE statement.
Example:
GLOBAL var AS INTEGER var=0 INPUT I SELECT I CASE var PRINT "I=zero" CASE 1 PRINT "I=one" CASE 2 PRINT "I=two" CASE ELSE PRINT "I is", I ENDSELECT
DO WHILE, [EXIT], LOOP These expressions repeat a group of instructions while a condition is true.
Where:DO WHILE cond_exp
statement(s)
<EXIT>
LOOP
- "cond_exp"
- is a valid conditional expression that will terminate the loop when the expression evaluates to True.
- "statement(s)"
- are the VSTB statements that will be executed within the loop.
* A DO WHILE loop evaluates the conditional expression first, before executing any code inside the loop. This means that the loop contents might not execute at all.
* At least one statement is mandatory. Empty DO WHILE/LOOP structures are not permitted. A REM statement can be used to satisfy this condition.
* DO WHILE and LOOP must be the only statements on a line.
* You may exit a loop at any time, using EXIT.
Example:
DO WHILE 1 REM - frequently used to execute main REM program forever LOOP index=0 DO WHILE index < 100 index = index + 3 IF someflag = 1 EXIT :REM exit early on some event ENDIF LOOP
DO,
[EXIT], LOOP UNTIL
This structure repeats a group of instructions until a condition is true.
DO
Where:statement(s)
<EXIT>
LOOP UNTIL cond_exp
- "cond_exp"
- is a valid conditional expression that will terminate the loop when the expression evaluates to True.
* The conditional expression is evaluated after the first execution of the loop contents. This means that the contents of a DO/LOOP UNTIL loop will always be executed at least once.
* At least one statement is mandatory. Empty DO/LOOP UNTIL structures are not permitted. A REM statement can be used to satisfy this condition.
* DO and LOOP UNTIL must be the only statements on a line.
* You may exit a loop at any time by executing EXIT.
Example:
index = 0 DO index = index + 2 PRINT index,"\013\010" LOOP UNTIL index > 9 index = 0 DO index = index + 2 IF (index \ 2) <> 0 EXIT ENDIF LOOP UNTIL index > 9
FOR, STEP, EXIT, NEXT
This structure increments a counter while repeatedly executing a group of instructions
until the counter reaches a specified value.
Where:FOR loop_counter = initial_value TO final_value <STEP n>
statements
<EXIT>
NEXT loop_counter
- "loop_counter"
- is the variable that will track progress through the loop.
- "initial_value"
- is the starting value assigned to the loop_counter variable.
- "final_value"
- is the value of loop_counter that will terminate the loop.
- "n"
- is a literal integer or integer variable by which the loop counter will be incremented at the end of each iteration loop.You may exit a loop at any time, using EXIT.
* Testing to determine whether the final value is reached is done at the start of the loop. If, upon execution of the FOR statement "loop_counter" has reached or passed the "final_value," then statements in the loop will not be executed.
* The name of the "loop_counter" variable following NEXT is optional. If present it must be identical to the matching FOR statement. This is usually used for clarity, in nested FOR/NEXT loops.
* At least one statement is mandatory. Empty FOR/NEXT structures are not permitted. A REM statement can be used to satisfy this condition.
* Multiple statements on a line with FOR or NEXT are forbidden. A compiler error message will result.
* STRING data type may not be used for the loop counter.
* STEP defaults to (1) when not specified.
Example:
FOR index = 1 TO 9 PRINT index,"\013\010" NEXT index FOR index = 0 TO 10000 STEP 100 REM do something IF key='X' EXIT ENDIF NEXT REM "EXIT" exits to here
EXIT
EXIT allows early termination of control structures.
EXIT
* An EXIT statement is always associated with the innermost enclosing DO, FOR or SELECT structure.
* An unassociated EXIT will generate a compiler error message.
* Use RETURN to leave a subroutine or function.
Example:
FUNCTION get_key() AS INTEGER DO WHILE 1 get_key = inkey() IF get_key <> -1 EXIT :REM Only way to exit loop ENDIF LOOP END FOR index = 0 TO 10000 REM do something IF key='X' EXIT ENDIF NEXT index REM "EXIT" exits to here
Interrupt Control
The following keywords, ON TIMER, ON ERROR, ON INT, and ON COM, assign the interrupt
handling routines for each of the various types of interrupt events (timeouts,
runtime errors, interrupts, and characters received to either of the two on-board
serial ports).
The Interrupt Handler will transfer control to the last routine assigned to
the interrupt when that interrupt condition occurs.
For example:
1. Task 1 assigns COM0 events to handler1.
2. Task 2 subsequently assigns COM0 events to handler2.
3. A character is received by the COM0 serial port.
4. Subroutine handler2 is invoked regardless of which task is executing.
The procedure that handles the event may be in a different task than the one
that sets the event trigger. Also, any other task may be executing when the
event occurs and unless the current procedure is protected with VITAL, processing
will immediately switch to the event handling procedure regardless of which
task it is in. However, if the task that contains the handler procedure has
been STOPped when the event occurs or it will not be able to respond, and the
event will be ignored (using the END statement instead of the STOP statement
will avoid this problem).
ON
TIMERx, SET TIMERx TO
These expressions are used to execute a subroutine after a specified amount
of time.
Where:VITAL SUBROUTINE Subname (timer AS INTEGER)
Statements
END
ON TIMERx Subname
SET TIMERx TO period
- "TIMERx"
- specifies one of the two available timers; "TIMER0" for Timer 0, or "TIMER1" for Timer 1.
- "Subname"
- is the name of the subroutine that will be executed when the event is triggered.
- "period"
- is the number of "clock ticks" to wait before triggering the timer event.
- "timer"
- is the name of the variable that will indicate which timer triggered the ON TIMERx event. The variable will be set to "0" if Timer0 triggered the event, and "1" if Timer1 triggered the event.
* There are eight timers, ON TIMER0 through ON TIMER7. Any timer used by a task is unavailable to all other tasks.
* ON may only be used in main procedures.
* Only VITAL subroutines (which disable event processing) may be used as an argument by the ON TIMERx statement.
* SET TIMERx TO will set the selected timer to the number of system clock ticks. The system clock tick rate is 10 milliseconds. SET TIMERx TO 0 will turn off the timer.
* ON TIMERx will turn off the specified timer if no handler subroutine is specified.
* When the timer expires, the specified subroutine is executed immediately unless the timer expires during the execution of a VITAL procedure. In this case the specified subroutine will execute as soon as the VITAL subroutine completes.
* In order for a timer to be periodic (that is, to repeat), the handler subroutine must execute the SET TIMERx TO statement again.
* If two timers time out simultaneously, the higher numbered timer has priority.
* Multiple timers may use the same handler subroutine. The subroutine that handles the ON TIMERx event will receive the timer number as a parameter.
Example 1:
VITAL SUBROUTINE dualtone(x AS INTEGER) STATIC flipflop AS INTEGER flipflop=NOT flipflop IF flipflop CALL BEEP(2000) SET TIMER0 TO 30 ELSE CALL BEEP(500) SET TIMER0 TO 60 ENDIF END REM the main procedure uses only timer 0. SET TIMER0 TO 10 ON TIMER0 dualtone DO WHILE 1 REM LOOP
Example 2:
REM One handler subroutine can handle all timers: GLOBAL timeout AS INTEGER VITAL SUBROUTINE handle_all (timer AS INTEGER) SELECT timer CASE 0 timeout = 0 REM timer0 is periodic SET TIMER0 TO 100 EXIT CASE 1 timeout = 1 REM timer1 is periodic SET TIMER1 TO 250 EXIT CASE ELSE :REM all other timers are one-shots timeout = 2 ENDSELECT END REM In Main-- ON TIMER0 handle_all ON TIMER1 handle_all ON TIMER2 handle_all REM etc. SET TIMER0 TO 100 SET TIMER1 TO 250 SET TIMER2 TO 1000 :REM etc. DO WHILE 1 REM watch for timers to time out, print REM when it has happened IF timeout <> -1 print timeout,"\013\010" timeout = -1 ENDIF LOOP
ON INTx
ON INTx executes an interrupt service subroutine when a hardware interrupt event
occurs.
Where:VITAL SUBROUTINE Subname (irq_number AS INTEGER)
Statements
END
ON INTx [subroutine_name]
SET INTx TO 1
- "Subname"
- is the name of the subroutine that will be executed when the event is triggered.
- "INTx"
- is INT0 or INT1.
* ON may only be used in main procedures.
* The following table contains the hardware source corresponding to each ON INT event (and a connector pin, if it is externally available) for each model of SBC2000.
Interrupt Table* Only VITAL subroutines (which disable event processing) may be used as arguments to this statement.
ON INTx SBC2000-332 MC2000-332 SBC2000-188 0 N/A N/A BUS int (J1B 6) 1 VAST int (VAST 9) (J3 13) INT 1 (J1B 24) 2 RTC (J3 12) INT 2 (J1B 25) 3 (J2D 8) (J3 11) N/A 4 (J2D 7) (J3 10) VAST int (VAST 9) 5 (J2D 6) (J3 9) N/A 6 BUS int (J1A1) (J3 8) N/A
* SET INTx TO 1 will enable the interrupt handler for one assertion of the interrupt only. If you want the hardware interrupt to be handled again, you must use SET INTx TO 1 in the handler routine to re-enable it. SET INTx TO 0 will disable the hardware interrupt.
* ON INTx will execute the specified subroutine for the next assertion of the associated interrupt. Once the interrupt is asserted, the interrupt is disabled. ON INTx enables an interrupt for the next single event. Therefore, your handler should re-enable the interrupt with a new call to ON INTx.
* SBC2000 interrupts are level sensitive. Your handler should acknowledge the interrupt if possible, so that it is not immediately reentered at the completion of the interrupt service subroutine.
* An interrupt signal should remain asserted for at least 50 microseconds in order for it to be handled in all situations.
* The hardware interrupt will be disabled if ON INTx is used without a subroutine designated as an argument.
Example:
GLOBAL int_count AS INTEGER VITAL SUBROUTINE int_handler(irq AS INTEGER) int_count = int_count + 1 SET int1 TO 1 END REM Main procedure ON INT1 int_handler SET int1 TO 1 REM initially # of enable hardware interrupt DO WHILE INKEY() <> 'q' PRINT int_count,"\013\010" REM prints times INT1 is asserted LOOP ON INT1 REM disable interrupt before end of code
ON
ERROR
The ON ERROR statement executes an error-recovery subroutine when a recoverable
run-time error occurs in a task. The default error handler stops the task containing
the error.
Where:VITAL SUBROUTINE Subname (task AS INTEGER, line AS INTEGER, statement AS INTEGER, err AS INTEGER)
Statements
END
ON ERROR Subname
- "Subname"
- is the name of the subroutine that will be executed when the event is triggered.
- "task"
- is the Task where the error occurred.
- "line"
- is the line of code number where the error occurred.
- "statement"
- is the statement where the error occurred.
- "err"
- is the error code.
* The task, line, statement and error code are automatically passed to the error handling procedure by Vesta Basic when an error occurs.The following error numbers are ordered according to the type of error. An error status of zero means no errors occurred.The IDE Monitor (task 0) executes a SUSPEND statement before it installs its own ON ERROR handler routine. If your application installs an ON ERROR handler, you must do one of two things before you execute the ON ERROR statement:
Error Code Table
Error Number Error Condition Error Number Error Condition 4 COM 0 buffer overflow 19 COM 7 framing error 5 COM 0 framing error 20 Divide by 0 6 COM 1 buffer overflow 21 Domain error e.g. ( -1) ^0.5 7 COM 1framing error 22 Math overflow 8 COM 2 buffer overflow 23 Array bounds exceeded 9 COM 2 framing error 24 Wrong data type 10 COM 3 buffer overflow 30 to 39 Unassigned 11 COM 3 framing error 40 to 49 Development time errors 12 COM 4 buffer overflow 50 error in argument 0 13 COM 4 framing error 51 error in argument 1 14 COM 5 buffer overflow 52 error in argument 2 15 COM 5 framing error 53 error in argument 3 16 COM 6 buffer overflow 54 error in argument 4 17 COM 6 framing error 55 error in argument 5 18 COM 7 buffer overflow 56 error in argument 6 57 error in argument 7 88 generic hardware timeout 60 to 69 unassigned 89 generic hardware failure 70 array memory error 90 Call to an unimplemented extension 71 flash error - fail to write 94 startup could not locate critical elements needed to run Basic 72 flash timeout - fail to write / erase 95 User aborted download in process or stops VRED in DOS 80 bad hardware configuration, inappropriate product code during use 96 Task memory violation during execution 81 no acknowledge on IIC transfer 97 Version mismatch between compiler (PC) and P-code engine (ROM) 82 VAST transfer failure 98 Unimplemented Interrupt service subroutine 83 VAST timeout - 332 specific 99 Vesta Basic has found an error within itself during execution. * The first statement on a line is statement 0. Any others on the same line (separated by colons) are numbered sequentially, starting at 1.
* Only one error recovery function is used for all tasks.
* ON ERROR without a specified handler subroutine turns off error recovery. In this situation, the error messages will not be sent out the DEV port by the IDE Monitor (Task 0).
* ON ERROR may only be used in main procedures. It is usually used in the main procedure of the primary task, to set up error handling for all tasks. ON ERROR can be used more than once in a program if different program states require different error handling. Only the last ON ERROR statement executed will be in effect.
1. You must execute two SUSPEND statements in the task where you assign the error handling routine. Since Vesta does not guarantee a startup order for tasks, you need two SUSPEND statements to guarantee that the monitor installs its ON ERROR handler before your task does. This will allow the IDE Monitor to continue running and communicating with the IDE. Most debug capabilities will remain active in this case, but the monitor will not be able to detect or report errors.
2. You must execute a STOP 0 statement to shut down the debug monitor. This will halt communication between your application and the IDE, including debug information.
Example:
GLOBAL err_status AS INTEGER GLOBAL intvar AS INTEGER VITAL SUBROUTINE Recover (task AS INTEGER, line AS INTEGER, statement AS INTEGER, err AS INTEGER) IF task = 1 err_status = err ENDIF END SUBROUTINE printerr() SELECT err_status CASE 22 PRINT "Exponentiation overflow\013\010" EXIT CASE 21 PRINT "Imaginary Exponentiation\013\010" EXIT CASE 20 PRINT "Divide by zero\013\010" EXIT CASE ELSE PRINT "No error handling\013\010" ENDSELECT err_status = 0 END REM in the main procedure ON ERROR recover REM Now we cause some errors... intvar = 10/0 IF err_status CALL printerr() ENDIF intvar = 100 ^ 1000 IF err_status CALL printer() ENDIF
ON
COMx
ON COMx names a subroutine to be executed when a character is received on a
serial port.
Where:VITAL SUBROUTINE Subname (port_number AS INTEGER)
Statements
END
ON COMx Subname
SET COMx TO
- "COMx"
- indicates the serial device that triggers the event; on the SBC, COM0 specifies the port labeled COM and COM1 specifies the DEV port.
- "Subname"
- is the name of the subroutine that will be executed when the event is triggered.
- "port_number"
- is a variable that will identify the serial port that triggered the event: 0=the COM port, 1= the DEV port.
* If an external b4serial board is installed as card 0, its ports can be referenced as COM4-7. ON COMx cannot be used with COMM8 - COMM19 on BUS4SERIAL cards 1-3, use ON INT6 instead.
* The subroutine assigned to handle the COM event must be protected with the VITAL keyword.
* ON COMx may only be used in main procedures.
* You have the option of assigning your COM handler to intercept the incoming character, using COMM() mode 0. If you do not intercept the character, it will be sent on to the default character handler [for reception by INPUT or INKEY()].
* Using ON COMx with no subroutine as argument prevents incoming character events from calling user-defined subroutines.
* The IDE Monitor (task 0) installs an ON COM1 handler routine. If your application installs an ON COM1 handler, you must execute a STOP 0 statement to shut down the IDE Monitor before you install your handler.
Example 1:
GLOBAL message AS STRING, message_flag AS INTEGER VITAL SUBROUTINE assemble_message(x AS INTEGER) LOCAL temp AS INTEGER temp=COMM(0,0,0):REM get the character IF temp<>13 message{$}=CHR(temp) ELSE message_flag=1 ENDIF END REM the main procedure waits for a completed packet ON COM0 assemble_message DO WHILE message_flag<>1 REM LOOP PRINT message This example can receive a packet of any type of data without the delimiter limitations of INPUT.
Example 2:
GLOBAL port0 AS INTEGER GLOBAL port1 AS INTEGER VITAL SUBROUTINE com_handler(port AS INTEGER) SELECT port CASE 0 port0 = port0 + 1 CASE 1 port1 = port1 + 1 ENDSELECT END REM Main ON COM0 com_handler ON COM1 com_handler DO WHILE 1 PRINT port0," ",port1,"\r" :REM prints REM count of chars RX LOOP
START
This statement restarts any task while running another task.
Where:START <task>
- "task"
- is the task number (1-7) of the task you want to start.
* The task you specify may not start immediately. START queues up the specified task to restart the next time the task-scheduler switches to it.
* Each active task is executed for up to 50 milliseconds before the task scheduler switches to another task.
* If no new task is specified, the current task will restart from the beginning.
Example:
START :REM current task restarts itself START 0 :REM restart the IDE Monitor task
STOP
This statement stops the execution of any task or application.
Where:STOP <task>
- "task"
- is the task number (1-7) of the task you want to stop.
* Do not execute STOP within a VITAL or CRITICAL procedure.
* If no task is specified STOP terminates the current task.
Example:
STOP 0 :REM Stop the IDE Monitor task STOP :REM Current task stops
Task
0 - The IDE Monitor
Task 0 is the IDE monitor. The IDE Monitor is used to communicate between the
Vesta Basic IDE on the PC and the Vesta Basic Runtime engine on the SBC2000.
The IDE Monitor is written to SUSPEND itself if there is no IDE traffic. Therefore,
it consumes little microprocessor overhead, however, it can be shut down in
order to optimize execution of other tasks.
You may stop the IDE Monitor task from any task in RAM, because the IDE Monitor
will restart normally as soon as you cycle power to the SBC2000. However, once
a task in flash stops the debug monitor, communication between the SBC2000 and
the PC is severed. If this happens, you can select Flash|Erase Flash or Erase
Runaway Task to erase all tasks in flash.
RUN
RUN resumes any stopped task from the point at which it was terminated.
Where:RUN [task]
- "task"
- is the task number (1-7) of the task you want to run.
* The task specified will not resume execution immediately; RUN only adds the task back to the task scheduler list.
* Running a task that is already in progress will have no effect.
Example:
RUN 0 :REM resume execution of task 0
SUSPEND
SUSPEND exits the current task.
SUSPEND
* SUSPEND causes the task switcher to transfer to the next task without waiting for the end of the current 50-millisecond time slice.
* The current task will execute normally the next time the task switcher returns.
Example:
IF keypad(0) = -1 SUSPEND :REM no keys are being REM pressed, don't hang around ELSE REM handle the keypress ENDIF
SET
TIMESLICES TO n
Allots n number of 10 millisecond time-slices to the current task.
Where:SET TIMESLICESTO n
- "n"
- is the number of clock ticks you would like to allocate to the current task.
* SET TIMESLICES allows the user to allocate multitasker resources amongst the tasks.
* "n" is the number of 10 millisecond time intervals that the task will be allotted until switched.
* SET TIMESLICES TO 0 will effectively stop the current task with no opportunity for recovery without reboot.
* All tasks are started with 5 ten millisecond time-slices.
Example:
SET TIMESLICES TO 10
REBOOT
This statement reboots the board.
REBOOT
* REBOOT causes execution to begin at the power on reset vector of the microprocessor.
Memory
Commands
There are two classes of memory-access procedures: conventional and special
purpose. The conventional PEEK, POKE, DPEEK, and DPOKE are all-purpose functions
that can be used to access any part of an SBC2000's memory space. Your SBC2000
hardware manual specifies where each memory type is mapped in the board's absolute
address space.
Additional conventional memory devices include the off-board memory and I/O
space of various peripherals. Vesta Basic provides bus access that masks the
differences among SBC2000 models when addressing off-board devices.
Conventional statements cannot be used for special-purpose devices such as Flash,
serial EEPROM, or the real-time clock. For these devices Vesta Basic provides
specialized, built-in procedures.
Applying 8-bit procedures (PEEK, MEM_PEEK, etc.) to 16-bit-wide devices gives
the results you might expect: Only the relevant 8-bits are returned. Conversely,
using 16-bit procedures (DPEEK, MEM_DPEEK, etc.) on 8-bit-wide devices also
will return the relevant 16 bits.
When expressed in hexadecimal, a number must be preceded by the symbol 0x ("zero,
x"), followed by up to four hexadecimal digits. These digits may be 0 thru
9 or A thru F. The A thru F are not case sensitive.
PEEK
The PEEK function returns the byte of data from the specified, absolute memory
address.
Where:PEEK(address)
- "address"
- is the RAM address of memory location that you want to access, expressed as a long in the range of 0-255.
* PEEK is a function that expects a long argument and returns integer data.
* Even though PEEK will work on many types of memory devices, it is better to use special-purpose PEEK procedures (IOPEEK, MEM_PEEK . . .) whenever possible.
Example:
FUNCTION peekword(address AS LONG) AS INTEGER REM Returns a 16 bit integer stored in Motorola order peekword = (peek(address)*256) + peek(address+1) END
POKE
The POKE subroutine writes a byte of data to memory at the specified absolute
address.
Where:POKE(address, value)
- "address"
- is the address of the destination.
- "value"
- is the data value that you want to assign to the destination.
* POKE is a subroutine that expects a long address and returns integer data.
* PEEK with alacrity, POKE with caution.
* Even though POKE will work on many types of memory devices, it is better to use special-purpose POKE procedures (IOPOKE, MEM_POKE . . .) whenever possible.
The statement, POKE(someaddr,0x1234) will poke the least significant byte of data (34 hex) into the location specified.
Example:
SUBROUTINE pokeword(address AS LONG, value AS INTEGER) REM store a 16 bit integer in Intel order CALL POKE(address, value) CALL POKE(address+1,value \ 256) END
DPEEK
This function will read a 16-bit integer from the specified absolute memory
address.
Where:DPEEK(address)
- "address"
- is the location that you want to access.
* Odd addresses are read at the even address starting with the previous byte. Addresses start at zero (0) on the hardware memory map.
Example:
Will read the contents of the first two bytes of memory.intvar = DPEEK(0x00)
DPOKE
This subroutine will write a 16-bit integer to the specified absolute memory
address.
Where:DPOKE(address, value)
- "address"
- is the address of the destination.
- "value"
- is the data value that you want to assign to the destination.
* Odd addresses are written at the even address starting with the previous byte.
Example:
Will write the value 0x1234 to the first two bytes of RAM on an SBC2000-332CALL DPOKE(0x100000, 0x1234)
IOPEEK
The IOPEEK function returns the byte that was read from the specified address
in IO space.
Where:IOPEEK(address)
- "address"
- is the location that you want to access.
* Address zero (0) is the first address in off-board (bus) IO space.
Example:
Will read 1st byte of IO memory.intvar=IOPEEK(0)
IOPOKE
The IOPOKE subroutine will write a byte to the specified address in IO space.
Where:IOPOKE(address, value)
- "address"
- is the address of the destination.
- "value"
- is the data value that you want to assign to the destination.
* Address zero (0) is the first address in off-board (bus) IO space.
Example:
Will set 1st byte of IO memory to 14.IOPOKE(0,14)
MEM_PEEK
This function returns a byte of data from the specified address in off-board
memory.
Where:MEM_PEEK(address)
- "address"
- is the memory location that you want to access.
* Address zero (0) is the first address in off-board (bus) memory space.
Example:
Will read the 17th byte of offboard memory. If no memory device is installed at this location the result is undefined.intvar = MEM_PEEK(0x0010)
MEM_POKE
This function writes a byte of data to the specified address in off-board memory.
Where:MEM_POKE(address, value)
- "address"
- is the address of the destination.
- "value"
- is the data value that you want to assign to the destination.
* Address zero (0) is the first address in off-board (bus) memory space.
Example:
Will write 0x5a to the 17th byte of offboard memory space.CALL MEM_POKE(0x0010, 0x5a)
MEM_DPEEK
This function returns a 16-bit integer from the specified address in off-board
memory.
Where:MEM_PEEK(address)
- "address"
- is the location that you want to access.
* Address zero (0) is the first address in off-board (bus) memory space.
Example:
Will read the 17th and 18th bytes of offboard memory. If no memory device is installed at this location, the result is undefined.intvar = MEM_DPEEK(0x0010)
MEM_DPOKE
MEM_DPOKE writes a 16-bit integer to the specified address in off-board memory.
Where:MEM_DPOKE (address, value)
- "address"
- is the address of the destination.
- "value"
- is the data value that you want to assign to the destination.
* Address zero (0) is the first address in off-board memory space.
Example:
Will write 0x4321 to the 17th & 18th bytes of offboard memory space.MEM_DPOKE(0x0010, 0x4321)
EEPROM_SIZE
This subroutine tells the Vesta Basic run-time engine what size EEPROM is installed
on your SBC2000.
Where:EEPROM_SIZE(code)
- "code"
- is a 1 or 0 indicating the type of EEPROM device installed on your SBC2000. The default EEPROM size is size=1.
* Use this subroutine before calling any code that accesses the onboard EEPROM device.
Code Size EEPROM device 0 128 to 2k bytes 24C01 to 24C16 1 4k to 8k bytes 24C32 to 24C64
* Undefined behavior will result if you attempt to read from or write to an EEPROM device of a different size than the one set by this subroutine.
Example:
CALL EEPROM_SIZE(0)
EEPROM_PEEK
This function returns an 8-bit byte from the EEPROM.
Where:EEPROM_PEEK(register)
- "register"
- is the EEPROM register you want to access.
* For details on the capacity of EEPROM, check your SBC2000 manual.
Example:
Will read the 17th byte of the EEPROM device.intvar = EEPROM_PEEK(0x0010)
EEPROM_POKE
This subroutine writes an 8-bit byte to the EEPROM.
Where:EEPROM_POKE(register, value)
- "register"
- is the EEPROM register of the destination.
- "value"
- is the data value that you want to assign to the destination.
* Each byte of the EEPROM may be individually written and re-written.
Example:
Will write an 0x11 to the fourth byte of EEPROM.CALL EEPROM_POKE(0x0003, 0x11)
FLASH_DPEEK
This function returns a 16-bit integer from the specified address in Flash memory.
Where:FLASH_PEEK(address)
- "address"
- is the flash address that you want to access.
* Address zero as the first byte of Flash.
Example:
Will return the values in the 9th and 10th bytes of Flash memory.intvar = FLASH_DPEEK(0x0008)
FLASH_DPOKE
FLASH_DPOKE writes a 16-bit integer to the specified address in Flash memory.
Where:FLASH_DPOKE(address, value)
- " address "
- is the flash address of the destination.
- "value"
- is the data value that you want to assign to the destination.
* Address zero is the first byte of Flash.
* Each data element of Flash can only be written once before the entire sector must be erased.
Example:
Will write 0x5a5a to the 9th and 10th bytes of Flash memory.FLASH_DPOKE(0x0008, 0x5a5a)
FLASH_ERASE
This subroutine erases the specified sector of Flash memory.
Where:FLASH_ERASE (sector)
- " sector "
- is the flash sector you want to erase.
* In Vesta Basic, Flash is organized in from 2 to 16 sectors of 64k bytes each. If sector is -1, all sectors of Flash (except the sectors containing Vesta Basic) are erased.
Example:
Erases the second 64Kb of Flash memory.FLASH_ERASE(2-4)
FLASH_AVL
Returns the size of remaining flash.
FLASH_AVL()
* Size is expressed in bytes.
* In the Vesta Basic IDE, Tools|SBC Memory will display the amount of Flash memory installed and remaining.
Example:
var=FLASH_AVL()
RAM_AVL
Returns the size of the largest block of contiguous RAM.
RAM_AVL()
* Block size is expressed in bytes
* In the Vesta Basic IDE, Tools|SBC Memory will display the amount of RAM memory installed and remaining.
Example:
var=RAM_AVL()
Real-Time
Clock
The onboard Real-time Clock (RTC) can be set and read using strings or by accessing
individual RTC registers.
Use TIMEDATE_PEEK and TIMEDATE_POKE to communicate using strings. Use RTC_PEEK
and RTC_POKE to access individual registers and RAM on the RTC chip.
The Real-time clock is Millennium compliant.
TIMEDATE_PEEK
This function will return the time and date from the real-time clock in string
form.
TIMEDATE_PEEK()
* The format of the string is the same as that described below for TIMEDATE_POKE.
* In the event of a failure an empty string will be returned.
* TIMEDATE_PEEK reads all RTC registers simultaneously to avert roll-over problems.
* When TIMEDATE_PEEK() is executed, an array in RAM is updated with the latest RTC information. The address of this array is 0x100430 for the SBC2000-332 and 0x3730 for the SBC2000-188. Accessing the data in this array has a couple of advantages:· You don't have to worry about rollover.
DIM rtc_array[8] AS INTEGER = 0x100430 GLOBAL year AS INTEGER, month ...
· It's faster than parsing the ASCII text string that TIMEDATE_PEEK returns.
year = rtc_array[0]
month = rtc_array[1]
date = rtc_array[2]
day = rtc_array[3]
hour = rtc_array[4]
minute = rtc_array[5]
second = rtc_array[6]
hundredth = rtc_array[7]
Example:
Will place the current time in string form into stringvar.stringvar = TIMEDATE_PEEK()
TIMEDATE_POKE
This subroutine allows the RTC to be set.
Where:TIMEDATE_POKE(time)
- "time"
- is the time setting in the following format:
"HH:mm:ss.hh MMM DD,yyyy ddd",
HH = hours (0-23)
mm = minutes (0-59)
ss = seconds (0-59)
hh = hundredths of seconds (0-99)
MMM = month (JAN, FEB, etc.)
DD = date (1-31)
yyyy = year
ddd = day (SUN, MON, TUE, WED, THU, FRI. SAT)
Example:
Will set the current time and date to 10:15 am on Wednesday, August 6th, 1997.CALL TIMEDATE_POKE("10:15:00.00 AUG 06,1997 WED")
RTC_PEEK
This function will return the 8-bit value of any register in the real-time clock.
Where:RTC_PEEK(address)
- "address"
- is the location that you want to access.
* Information is stored in packed BCD format.
* The first 16 registers contain time/date values, and each has its own format. (See table below, under RTC_POKE). The remaining 240 registers act as regular, 8-bit memory locations.
Example:
Will place the value from the RTC seconds register into secondreg. This value is stored in packed BCD (Binary Coded Data) format. To convert from packed BCD to decimal, use the following algorithm:secondreg = RTC_PEEK(2)
RTC_POKE
This subroutine will write any 8-bit register to the real-time clock. Each timer
register in the RTC has its own format.
Where:RTC_POKE(reg, value)
- "reg"
- is the destination register.
- "value"
- is the destination value.
The following chart shows the register layout of the real-time clock.
Reg Function Reg Function 0 Control/Status 8 Alarm control 1 Hundredths of seconds 9 Alarm, hundredths of Seconds 2 Seconds 10 Alarm, seconds 3 Minutes 11 Alarm, Minutes 4 Hours 12 Alarm, Hours 5 Year/Date, packed 13 Alarm, Year/Date, packed 6 Day/Month, packed 14 Alarm,Day/Month, packed Example:
RTC_POKE(3, 0x12)Will change the RTC time to 12 minutes past the hour.
All clock data registers (1 thru 7 and 9 thru 15) are in packed, BCD format. The Hours, Year/Date and Day/Month registers also have some extra bits not included in the time value.
Hours Registers 7 6 5 4 3 2 1 0 0=24hr format 1=12hr format 0=AM,1=PM tens of hours ones of hours
Year/Date Registers 7 6 5 4 3 2 1 0 Year (0-4) tens of days ones of days in month
Day/Month Registers 7 6 5 4 3 2 1 0 Bit weekday (0-6) tens of months ones of months To convert from a decimal time value to packed BCD, use the following algorithm:
secondreg = (seconds/10) * 16 + seconds\10
Registers from 24 to 255 are unused and available to use as battery backed RAM if an external battery is attached. This form of battery-backed RAM consumes less power than most other information-storage system featuring a power-off cycle.
Note: Certain functions of the real-time clock are used by Vesta Basic. Do not change the Control/Status register or the Alarm Control Register. These registers are 0, and 8. Vesta Basic also reserves clock RAM registers 16-23.
Power Management
Three procedures are provided for reducing power consumption during idle periods.
NAP
Enter the NAP power-down mode.* In this mode all peripherals continue to run. (On the SBC2000-332, BEEP(), and PWM() outputs will run at one-eighth their normal frequency during NAP mode). The UART will continue running normally during NAP mode.NAP()
* Any serial input or on any enabled external interrupt assertion will exit NAP mode. Execution continues with the next statement after NAP mode is exited.
Example:
ON COM0 Com_handler REM do nothing until awakened by a COM0 event. NAP()
SLEEP
Enters the SLEEP power-down mode.
SLEEP()
* When an enabled external interrupt is asserted sleep mode will terminate. (See your SBC2000 hardware manual for details on available interrupts.)
* Execution continues with the next statement after SLEEP mode is exited.
Example:
On INT0 Int_handler REM do nothing until awakened by an interrupt event SLEEP()
HIBERNATE
Enters the hibernate power-off mode.
HIBERNATE()
* In this mode, main power for the entire single-board computer is automatically switched off, provided your single-board computer is equipped with a switchable power supply.
* Power will be restored when the time (in seconds) specified in the interval has elapsed.
* If you do not have a switched power supply, power management is controlled by the HIB jumper on the SBC2000.
* With the jumper installed, HIBERNATE() behaves like SLEEP(), but execution resumes after the hibernate interval.
* If the jumper is not installed, HIBERNATE() behaves just like SLEEP().
Example:
Will power down the SBC2000 for an hour if the system is equipped with a switchable power supply.CALL Set_up HIBERNATE(3600) :REM wait for a while CALL Wake_up_and_look_around
SIZE_OF
This operator returns the size of the referenced array in EEPROM.
Where:SIZE_OF (name)
- "name"
- is the name of the array whose size will be returned.
* Size is expressed in bytes.
Example:
var=SIZE_OF(x)
ADDR_OF
This operator returns the starting address of the referenced array in EEPROM.
Where:ADDR_OF (name)
- "name"
- is the name of the array whose address will be returned.
* Arrays may have been manually or automatically allocated.
Example 1:
DIM xarray<100> AS INTEGER PRINT ADDR_OF(xarray)
Example 2:
var=ADDR_OF(x)
ROWS_OF
This operator returns the number of rows in the referenced array.
Where:ROWS_OF (array name)
- "array name"
- is the name of the array whose rows are to be counted.
* Rows are specified by the first or single argument of a DIM statement.
Example:
This example illustrates how ROWS_OF can be used to allow the programmer to change the size of an array without having to change every reference to the array in the program.DIM matrix [123,16] as integer FOR counter = 1 TO ROWS_OF(matrix) Print martrix[counter,5] NEXT
COLS_OF
This operator returns the number of columns in the referenced array.
Where:COLS_OF (array name)
- "array name"
- is the name of the array whose columns are to be counted.
* Columns are specified by the second argument of a DIM statement.
Example:
var=COLS_OF(x)
String
Manipulation
These procedures are useful for managing strings and converting between integers
and characters.
HEX
The HEX keyword changes the conversion base for binary- to-string and string-to-binary
conversions to hexadecimal.
HEX
* HEX affects the operation of STR, VAL, PRINT and INPUT.
Example:
longvar=255 DEC PRINT longvar :REM will print "255" HEX PRINT longvar :REM will print "FF"
DEC
The DEC keyword changes the conversion base for binary-to-string and string-to-binary
conversions to decimal.
DEC
* DEC affects the operation of STR, VAL, PRINT and INPUT.
* DEC is the default mode.
Example:
longvar=255 DEC PRINT longvar :REM will print "255" HEX PRINT longvar :REM will print "FF"
ASC
The ASC function returns the ASCII value of the first character of the string
passed to it.
Where:ASC(string)
- "string"
- is the you want to test.
* ASC is useful for individual character manipulation (e.g. upper to lower case conversion).
Example:
ASC("A") :REM will return 65 or hexadecimal 41 ASC("BC") :REM will return 66
CHR
The CHR function converts the numeric argument to a string containing one character.
Where:CHR(value)
- "value"
- is the ASCII value of the string you want to use.
* CHR is the inverse of ASC.
Example:
CHR(92) :REM will return the ASCII string "\".
VAL
The VAL function returns the long numeric value of the string argument.
Where:VAL(value)
- " value"
- is a numeric string.
* VAL operates on string data and returns a long integer result.
* The DEC and HEX commands effect how VAL() interprets the argument. By default numbers are assumed to be in decimal format. See Data Types for more information.
Example:
longvariable=VAL("1234567890") integervariable=VAL("12345") negativeinteger=VAL("-12345") HEX hexnum=VAL("0x0400") hexnum2=VAL("03f8")
FVAL
The FVAL function returns the floating point numeric value of the string argument.
Where:FVAL(value)
- " value"
- is the a string representing a float value.
* FVAL operates on string data and returns a float result.
* The rules for formatting the string value to represent a floating point number correctly are the same as the rules for INPUT (see INPUT), except that:
a) If an integer value with too many significant digits is entered a runtime error (24) will be generated.
b) If the value is outside the representable range a runtime error (24) will be generated.
c) If the magnitude is too large a runtime error (24) will be generated.
d) If the magnitude is too small a zero will be returned.
Example:
Floatvar1 = FVAL("1.23456789") Floatvar2 = FVAL("-1.23456789") Floatvar3 = FVAL(floatstring) Floatvar3 = FVAL("1.2345 E24")
STR
The STR function returns the ASCII string representing the integer or long argument.
Where:STR(value)
- " value"
- is an integer or long value that you want to treat like a string.
* STR() takes a long argument, so Floats are converted to Longs before STR() converts to a string. Therefore, any fraction is lost and any value too large for a Long representation is converted to the largest value represented by a Long. For better results when working with Floats, use the FSTR() command instead of STR().
* One leading space is inserted for positive numbers.
* The DEC and HEX commands effect how STR() interprets the argument. By default numbers are assumed to be in decimal format. See Data Types for more information.
Example:
stringvariable = STR(1234567890) stringvariable = STR(longvariable) amounttext = STR(checkamount) FOR index = 1 TO LEN(amounttext) :REM skip first char (0) SELECT amounttext{index} CASE 1 PRINT "one " CASE 2 PRINT "two " CASE 3 PRINT "three " CASE 4 PRINT "four " ENDSELECT
FSTR
The FSTR function returns the ASCII string representing the floating point argument.
Where:FSTR(value)
- " value"
- is a float that you want converted to text.
* One leading space is inserted for positive numbers.
Example:
stringvariable = FSTR(1.234567890) stringvariable = FSTR(floatvariable) stringvariable = FSTR(-1.234 E32)
LEN
The LEN function returns the length of a string.
Where:LEN(str)
- " str"
- is string you want to know the length of.
* Empty strings are length zero.
Example:
LEN("ABC") :REM returns 3
MIN
The MIN operators will return the smaller of two arguments.
Where:MIN(arg1,arg2)
- "arg1" & "arg2"
- are two numbers that you want to compare.
* The two arguments may be long, integer or float data types. Arguments need not be of the same data type.
Example:
INPUT a, b IF MIN(a,b)=a difference = b - a ELSE difference = a - b ENDIF
MAX
The MAX operator will return the larger of two arguments.
Where:MAX(arg1,arg2)
- "arg1" & "arg2"
- are two numbers that you want to compare.
* The two arguments may be long, integer or float data types. Arguments need not be of the same data type.
Example:
INPUT a, b PRINT MIN(a,b), " is less than ", MAX(a,b)
SIN
The SIN function returns the sine of the argument.
Where:SIN( angle)
- "angle"
- is expressed in radians as a float data type.
* The argument to SIN cannot exceed 100 radians.
360 degrees = 2 pi radians.
1 degree = .01745329 radians
Example:
PRINT SIN(45*.01745329)
COS
The COS function returns the cosine of the argument.
Where:COS(angle)
- "angle"
- is expressed in radians as a float data type.
* The argument to COS cannot exceed 100 radians.
360 degrees = 2 pi radians.
1 degree = .01745329 radians
Example:
PRINT COS(45*.01745329)
ARCTAN
The ARCTAN function returns the arctangent in radians of the argument.
Where:ARCTAN(value)
- "value"
- is expressed in radians as a float data type.
* The argument is dimensionless.
360 degrees = 2 pi radians.
1 degree = .01745329 radians
* ARCTAN returns a result that is expressed in radians as a float data type.
Example:
PRINT ARCTAN(1)
ABS
ABS will return the absolute value of the argument.
Where:ABS(arg)
- "arg"
- is the element to be evaluated, and may be a bit, byte, integer or float variable or a literal value.
* ABS returns same data type as the argument.
Example:
x = -99 PRINT ABS(x)
LOG
The LOG function returns the logarithm of the argument.
Where:LOG (arg)
- "arg"
- is any number.
* Log is base 10.
* Attempting to assign the LOG of zero or a negative number will result in an ON ERROR event.
* LOG returns a float data type.
Example:
PRINT LOG(10)
Onboard
Peripherals
There are several peripheral connections built into Vesta SBC2000s. The procedures
that follow are used to control them directly.
KEYPAD
The KEYPAD function provides an interface to the 16 key keypad port on the SBC2000
engines.
Where:KEYPAD(mode)
- "mode"
- is either 0 or 1. When mode is 0 KEYPAD() returns the value of the key currently being pressed, and when mode is 1 KEYPAD() returns the position of the key or keys being pressed.
Keypad(0) returns -1 if no key is pressed.
Keypad(0) returns values of 0 to 15 if a key is pressed.
Keypad(1) returns a 16 bit code that can be used for decoding multiple keys according to the following table:
A 1 in any bit position indicates that the corresponding button is depressed. If no button is depressed a 0 is returned.
16 bit value COL 0 COL 1 COL 2 COL 3 R3 R2 R1 R0 R3 R2 R1 R0 R3 R2 R1 R0 R3 R2 R1 R0
Example:
If button 2 (column 0, row 2) is pressed down: KEYPAD(0) will return a 2 KEYPAD(1) will return an 0x4000 To check the key presses using KEYPAD(1) you might use a routine like the following: all_keys = KEYPAD(1) DO IF all_keys > 16 Call Col4Row0Subr all_keys =all_keys-16 IF all_keys > 16 Call Col4Row1Subr all_keys =all_keys-15 IF all_keys > 16 Call Col4Row2Subr all_keys =all_keys-14 . . . LOOP UNTIL all_keys = 0
BEEP
BEEP initiates a periodic 50% square waveform on the timer dedicated to the
beeper at the specified frequency.
Where:BEEP(freq)
- "freq"
- is the output frequency in Hz.
If the frequency specified is zero the output is reset low. An argument less than the minimum will produce no output; an argument more than the maximum will produce maximum output.
SBC2000 BEEP -332 -188 MIN 81Hz @ 20 MHz95 Hz @ 25 MHz 38Hz MAX ~32 kHz @ 20 MHz32 kHz @ 25 MHz 32 kHz
Example:
REM example of BEEP
CALL BEEP(2000) :REM will produce a 2000 Hz output BEEP(3000):REM 3 kHz BEEP(0):REM off
PWM
PWM sets up a pulse-width modulated output signal of the specified frequency
and high-time percentage, via the specified timer channel.
Where:PWM(channel, percent, frequency)
- " channel "
- is a number indicating the pwm channel.
- "percent"
- indicates the proportion of time that the square wave that is high.
- "frequency"
- is the output frequency in Hz.
Although the percent argument is an integer, it represents tenths of a percent. Therefore, valid values for this argument are from 0 to 1000 (i.e., 907 produces a periodic signal which is high 90.7% of the time).
There are 14 PWM channels available on the SBC2000-332. Two channels (0-1) are available on the SBC2000-188.
Channel and Corresponding pin:
channel SBC2000-332 MC2000-332 SBC2000-188 0 Keypad -5 J1-1 Beep-3 or J1B-20 1 Keypad -6 J1-2 J1B-19 2 Keypad -7 J1-3 Not available 3 Keypad -8 J1-4 Not available 6 Beep -3 or J1B-20 J1-5 Not available 7 J1B-16 J1-6 Not available 8 J1B-18 J1-7 Not available 9 J1B-19 J1-8 Not available 10 J1B-21 J1-9 Not available 11 J1B-22 J1-10 Not available 12 J1B-23 J1-11 Not available 13 J1B-24 J1-12 Not available 14 J1B-25 J1-12 Not available 15 J1B-26 J1-12 Not available
PWM SBC2000 -332(20MHz) -332(25MHz) -188 MIN 160Hz 190Hz 76 Hz MAX 290kHz 340kHz 2.5MHz
Resolution SBC2000 -332(20MHz) -332(25MHz) -188 10 bits <5120 <6144 <4883 9 <9766 <10240 <12288 8 <19532 <20480 <24576 7 <39063 <24576 <49152 6 <78125 <81920 <98304 Example:
REM PWM using TP6 (BEEP connector) REM 50% duty cycle at 3kHz PWM(6,500,3000) REM 1% duty cycle at 7kHz PWM(6,1,7000) CALL PWM (1, 600, 2000) :REM will produce a 2 kHz signal with 60% REM active-duty cycle, on timer channel 1
COUNT
COUNT reads or initializes the current count value for the specified timer channel.
Where:COUNT(channel,op)
- "channel"
- is a number indicating the channel.
- "op"
- is an operation code that indicates weather to read the count or to reset it.
There are 14 channels available on the SBC2000-332. Two channels (0-1) are available on the SBC2000-188.
Channel and Corresponding pin:
channel SBC2000-332 MC2000-332 SBC2000-188 0 Keypad -5 J1-1 Beep-3 or J1B-20 1 Keypad -6 J1-2 J1B-19 2 Keypad -7 J1-3 Not available 3 Keypad -8 J1-4 Not available 6 Beep -3 or J1B-20 J1-5 Not available 7 J1B-16 J1-6 Not available 8 J1B-18 J1-7 Not available 9 J1B-19 J1-8 Not available 10 J1B-21 J1-9 Not available 11 J1B-22 J1-10 Not available 12 J1B-23 J1-11 Not available 13 J1B-24 J1-12 Not available 14 J1B-25 J1-12 Not available 15 J1B-26 J1-12 Not available
"Op" is expressed in two values:
0
reads the count value. 1 initializes the channel as a counter and reset the counter to 0.
The returned count value is in the range 0 to 65535.
Counter increments are determined by rising transitions at the timer input.
Example:
somevar = COUNT(4,1):REM sets up timer channel :REM 4 as a counter :REM ...10 pulses later... somevar= COUNT(4,0) :REM returns 10
Output
PRINT
The PRINT statement will write one or more expressions of any type to the default
output device in ASCII format.
Where:PRINT expression(s)
- "expression(s)"
- may be variables, ASCII character codes preceded by a slash, constant strings enclosed in quotes, or mathematical expressions. Each item in the PRINT expression should be separated from those that follow by a comma.
* The default PRINT destination is the communication port labeled "COM". The destination my be changed to LCD or another COMMx device using the PIPE statement.
* PRINT represents Floats beginning with a leading space or minus sign, followed by eight characters, seven of which will be digits, one of which will be a decimal point. Roughly: 0.001 < |x| < 1000000
Outside this range, the display changes. Far enough outside this range, exponential notation is used.
* Strings may contain escape sequences representing special non-printable characters. Escape sequences consist of a backslash character followed by three decimal digits representing a number in the range 0-255. Example sequences are:
Sequence Function
\010 line feed
\013 carriage return
\012 form feed
\009 tab
\007 bell
Example:
PRINT "\010\013 Hello World!" PRINT TIMEDATE_PEEK() PRINT "\010\013" REM moves cursor to REM beginning of next line PRINT " is the current index" FOR index = 0 TO 9 PRINT "\013",index REM Prints only on one line NEXT index
PIPE
The PIPE statement specifies the output device for PRINT and INPUT statements
in the current task.
Where:PIPE PRINT COMMx / PIPE INPUT COMMx / PIPE PRINT LCD
- "x"
- in COMMx is a numeric code that represents one of the communications port drivers.
PRINT and INPUT in other tasks are unaffected.
Port Description 0
"COM" on-board RS-232 connector 1
"DEV" on-board RS-232 connector 2
(run-time parameter error) 3
(run-time parameter error) 4
PORT 0 of BUS4 serial card 0 5
PORT 1 of BUS4 serial card 0 6 PORT 2 of BUS4 serial card 0 7 PORT 3 of BUS4 serial card 0 8
PORT 0 of BUS4 serial card 1 9
PORT 1 of BUS4 serial card 1 10 PORT 2 of BUS4 serial card 1 11 PORT 3 of BUS4 serial card 1 12
PORT 0 of BUS4 serial card 2 13
PORT 1 of BUS4 serial card 2 14 PORT 2 of BUS4 serial card 2 15 PORT 3 of BUS4 serial card 2 16 PORT 0 of BUS4 serial card 3 17 PORT 1 of BUS4 serial card 3 18 PORT 2 of BUS4 serial card 3 19 PORT 3 of BUS4 serial card 3
PIPE may only be used in the main procedure of a task.
PIPE can redirect PRINT and INPUT to a substitute character device driver written in Vesta Basic as an alternative to the standard COMM0 through COMM7 drivers that Vesta supplies. See the description of COMM for details of this function's arguments. The function must be declared as a vital function.
PIPE allows you to completely debug a program that will eventually use the DEV port. Write and debug your program using the COM port, then change the tested code to PIPE to the DEV port.
The DEV port is used during development as the communication port between the IDE and the SBC. For more information see Using The DEV Port as a Serial Port.
The IDE can hang if the SBC sends too many characters out the DEV port. If this happens, use CTRL-ALT-DEL to end the task.
Example:
PRINT "hi" :REM sends "h" & "i" to the COM port (default) PIPE PRINT COMM1 :REM directs PRINT to the DEV port PRINT "hi" :REM sends "h" & "i" to the DEV port PIPE INPUT COMM0 :REM directs INPUT from the COM port INPUT something :REM waits for data from the COM port PIPE PRINT LCD :REM directs PRINT to the LCD PRINT "hi" :REM appears on the LCD
INPUT
INPUT fills a variable with data from the default operator input device.
Where:INPUT var1 <, var2>
- "var1" & "var2"
- are the names of the variables that will be set to the data values from the input device.
* The default input device for INPUT is the communication port labeled COM, on the SBC2000 board.
* The PIPE statement can be used to redirect INPUT from the COM port or the DEV port. See PIPE.
* INPUT terminates when all of the variables in the list have been filled. Each variable requires a carriage return, space, or comma to terminate that particular entry.
* Integers and longs may be preceded by a minus sign, and are terminated by the first non-digit character entered. The value entered must be within the legal values for an integer.
If an integer or long value with too many significant digits is entered, it will be coerced to the largest allowable value (See Data Types for more information).
* A floating point number consists of an optional sign character, followed by a sequence containing a zero or more digits. A decimal point may be included anywhere in the sequence of digits. The sequence may be followed by the letter "E" (or "e") followed by an optional sign character ("+" or "-"), followed by an exponent value in the range of 0 to 38.
If the value entered is outside the range provided by the floating point representation, the value will be coerced to the largest or smallest representable value of the correct sign, as appropriate.
Floats are terminated by the first character entered that not fit the format above. The value entered must within the legal values for an float.
* Stings may contain any characters and are terminated by a carriage return.
* When expressed in hexadecimal, a number must be preceded by the symbol 0x ("zero, x"), followed by up to four hexadecimal digits. These digits may be 0 thru 9 or A thru F. The A thru F are not case sensitive.
* The data must match the variables in the list. Specifically, if alpha characters are sent to an integer variable, they will be discarded, and the input statement will terminate. Numeric characters include the digits 0 thru 9, a period (.), the plus symbol (+), and the minus symbol (-).
* If no unterminated input is waiting INPUT will wait forever(unless a timeout is set using the MODE statement). This does not stop other tasks from executing.
Warning: Be careful when executing INPUT within a VITAL or CRITICAL procedure. You are in a procedure that is protected from task switching while within the procedure - the task will wait for the correct data to satisfy the INPUT statement and potentially never task switch!
* The MODE statement can be used to set a timeout limit on the INPUT. See MODE, for more information.
Example:
GLOBAL k AS INTEGER GLOBAL s AS STRING DO WHILE 1 INPUT k,s :REM system will wait for an integer :REM and a string PRINT k,s LOOP
LCD Functions
More information on LCD commands is available in your LCD hardware manual.
LCD_COMMAND
This subroutine writes a command byte to the LCD control port.
Where:LCD_COMMAND(command)
- "command"
- is the one of the codes from the chart below.
LCD Commands (in hexadecimal)
LCD_DISPLAY
Function Cmd Function Cmd Initialize display
0x28 Move cursor left 0x10 Clear LCD, home cursor 0x01 Move cursor right 0x14 Home 0x02 Shift LCD left 0x18 Cursor off 0x0C Shift LCD right 0x1C Cursor on 0x0E Position cursor on 1st char 0x80 Blink Character 0x0D Position cursor on 2nd char 0x81 Advance cursor w/ data 0x06 and so on... ...
This subroutine writes a text string to the display port of the LCD.
LCD_DISPLAY (text)
The display will start at the current cursor location.
Example:
Will display 'Hello World!' on the LCD.CALL LCD_DISPLAY("Hello World!")
Serial
Communications Port Control
COMM
The COMM function provides character-level control of the serial ports.
Where:COMM (port, func, value)
- "port"
- is the serial port:
Port Description 0 "COM" on-board RS-232 connector 1 "DEV" on-board RS-232 connector 2 (run-time parameter error) 3 (run-time parameter error) 4 PORT 0 of BUS4 serial card 0 5 PORT 1 of BUS4 serial card 0 6 PORT 2 of BUS4 serial card 0 7 PORT 3 of BUS4 serial card 0 8 PORT 0 of BUS4 serial card 1 9 PORT 1 of BUS4 serial card 1 10 PORT 2 of BUS4 serial card 1 11 PORT 3 of BUS4 serial card 1 12 PORT 0 of BUS4 serial card 2 13 PORT 1 of BUS4 serial card 2 14 PORT 2 of BUS4 serial card 2 15 PORT 3 of BUS4 serial card 2 16 PORT 0 of BUS4 serial card 3 17 PORT 1 of BUS4 serial card 3 18 PORT 2 of BUS4 serial card 3 19 PORT 3 of BUS4 serial card 3
- "func"
- is the low-level control function:
Function Description 0 Serial Input: Returns -1 if no character is pending within port's current timeout (see GET_TIMEOUT). Otherwise, returns ASCII value of next pending character. 1
Serial Output: Places low 8 bits of value argument out of port (NOTE: result is irrelevant). 2
Character Pending: Returns non-zero when one or more characters are pending on the serial port, zero otherwise. (NOTE: value argument is ignored). 3 Push to Talk: Set serial port to Transmit when value is non-zero otherwise set serial port to Receive (NOTE: result is irrelevant).
- "value"
- is the character for output. The value must be included but it is ignored if func is 0 or 2.
Example 1:
REM echos characters coming into COM port GLOBAL LETTER AS INTEGER GLOBAL RESULT AS INTEGER DO WHILE 1 REM GET THE LETTER LETTER = COMM(0,0,0) IF LETTER <> -1 REM PUT OUT THE LETTER RESULT = COMM(0,1,LETTER) ENDIF LOOP
Example 2:
REM tell user when characters are pending on COM port GLOBAL RESULT AS INTEGER DO REM LOOP COMM(0,2,0) PRINT "CHARACTERS ARE PENDING!"
Example 3:
REM set COM port to first transmit then receive CONSTANT XMIT AS INTEGER = 1 CONSTANT RCVE AS INTEGER = 0 GLOBAL RESULT AS INTEGER RESULT = COMM(0,3,XMIT) RESULT = COMM(0,3,RCVE)
Using
The DEV Port as a Serial Port
After program development is completed, the DEV port is no longer needed for
debug monitoring. The problem is getting over that last blind hurdle of writing
code that cannot be executed in the debug environment.
You may "borrow" the DEV port during development by doing the following:
o set the IDE polling rate to zeroThe STOP 0 will prevent the IDE Monitor from intercepting characters coming in the DEV port and processing them. Assuming your task is in RAM, resetting the SBC2000 will restore the debug environment.
o write a task that will execute STOP 0
o download and run the task from RAM
o disconnect the RS-232 cable from PC
o connect the DEV port to something
o observe operation
o reset the SBC2000 and reconnect PC
MODE
The MODE subroutine allows serial port parameters to be changed.
MODE (port, baud_rate, bits_per_char, parity, stop_bits, timeout)
The serial port is selectable, where:
All other parameters can take -1 to indicate "no change". Otherwise, each parameter must be in the legal range for that setting.
Port Description 0 "COM" on-board RS-232 connector 1 "DEV" on-board RS-232 connector 2 (run-time parameter error) 3 (run-time parameter error) 4
PORT 0 of BUS4 serial card 5
PORT 1 of BUS4 serial card 6 PORT 2 of BUS4 serial card 7 PORT 3 of BUS4 serial card
On some SBC2000 boards, only certain combinations of bits_per_char, parity, and stop_bits are allowed for certain ports.
Any attempt to use an illegal setting or combination of settings will cause a run-time error.
The baud rate parameter adjusts the serial port transmit/receive rate.
SBC2000 -332 -188 Port COM DEV COM DEV MIN 150 150 150 150 MAX 38400 38400 76800 76800 Higher baud rates can be programmed, however, as the baud rate increases, resolution decreases.
The baud rate for the B4SERIAL min: 150 to max: 115200
Example:
REM Adjust the baud rate of port 0 MODE(0,9600,-1,-1,-1,-1)
Bits/char |
Description |
7 |
Allows characters in range 0-128 (ASCII) |
8 |
Allows characters in range 0-255 (extended ASCII) |
9 | 0-255 expressed in 9 bits |
Example:
REM Adjust the bits per char of port 0 for ASCII MODE(0,-1,7,-1,-1,-1)
Parity |
Description |
0 |
no parity |
1 | even parity |
Example:
REM Set parity transmitted with characters REM for port 0 to odd parity. MODE(0,-1,-1,2,-1,-1)
Stop bits | Description |
1 |
one stop bit (standard for most PC's) |
2 | two stop bits (standard for some old mainframes) |
The stop bits parameter sets the number of stop bits to be transmitted with the bits
of a character.
Example:
REM Each character for port 0 shall be REM transmitted with 1 stop bit MODE(0,-1,-1,-1,1,1)
Timeout | Description |
20 | default timeout of COMM. |
The timeout parameter determines how long the serial port should wait before concluding
that no characters are pending, in units of system ticks (10 [ms]).
The timeout parameter influences the behavior of the COMM function (mode 1, serial input),
and of the INPUT statement (which uses COMM as the low-level interface).
Example:
REM Adjust timeout of port 0 to 40 [ms] MODE(0,-1,-1,-1,-1,40)
PTT
Turns the transmitter of the associated serial port on or off.
PTT(arg)
The argument is either 0 or 1.
1 = on
0 = off
The LED on the SBC2000 is off when the COM transmitter is on.
Example:
After transmitting a character or group of characters with the PRINT statement, a delay will be required in order to ensure that the final character has completed shifting out of the UART shift register before turning the transmitter off.PTT(0) :REM affects the port that PRINT is PIPEd to.
KEY_PENDING
KEY_PENDING() returns the status of the serial port from which INPUT is currently
PIPEd.
KEY_PENDING()
Returns 0 if no key is available, returns -1 if a key is waiting.
KEY_PENDING() does not remove the character from the incoming data stream like INKEY() does. Therefore it can be used to test if a subsequent INPUT statement can be executed.
Example:
DO SUSPEND LOOP UNTIL KEY_PENDING() = -1
INKEY
INKEY() returns the character or status of the serial port from which INPUT
is currently PIPEd.
INKEY()
If there is no character return -1 after timeout; otherwise return the character.
INKEY() removes the next character from the input data stream.
Example 2:
REM example of INKEY REM wait for keypress DO KEY = inkey () LOOP UNTIL INKEY<>-1
Example 2:
REM example of KEY_PENDING REM wait for specific incoming character DO DO SUSPEND LOOP UNTIL KEY_PENDING()=-1 LOOP UNTIL INKEY()=arg
GET_TIMEOUT
GET_TIMEOUT() returns the timeout setting for the serial port from which INPUT
is currently PIPEd.
GET_TIMEOUT()
The timeout is set with the MODE command. See MODE.
Example:
TICKS = GET_TIMEOUT()
IIC
and SPI Commands
Many of the peripheral boards available for use with Vesta's SBC2000 controllers,
take advantage of our own VAST bus protocol. The Vesta Addressable Synchronous
Transfer (VAST) is well suited for adapting devices using the Phillips / Signetics
IIC or any other of the many synchronous serial protocols such as Motorola's
SPI Protocol.
The following 8 Vesta Basic commands allow easy connection to IIC type and SPI
type peripherals:
VAST_OPEN( ) selects the VAST device addressThese procedures should be called only from within a CRITICAL or VITAL procedure to prevent other tasks from taking over the VAST bus before the transfer is complete.
VAST_CLOCK( ) sets the clock polarity and phase of SPI-type transfers
VAST_CLOSE( ) ends the SPI transfer
VAST_SPI_XFER( ) performs an SPI transfer
VAST_IIC_START( ) begins an IIC transfer
VAST_IIC_STOP( ) ends an IIC transfer
VAST_IIC_SEND( ) sends a byte to an IIC peripheral
VAST_IIC_READ( ) reads a data byte from the IIC peripheral
VAST_OPEN(
)
VAST_OPEN() is used to select the VAST address of the device you wish to control.
Where:VAST_OPEN(address)
- "address"
- is an integer number representing the VAST address.
* Legal values for SPI addresses are 0 thru 14. Address 15 is reserved for IIC devices.
See the SPI Transfer example, below.
VAST_CLOCK( )
VAST_CLOCK() is used to set the clock polarity and phase used in SPI transfers.
Where:VAST_CLOCK(mode)
See the SPI Transfer example, below.
- "mode"
- is 0-3 representing one of the following modes:
0 Clock is active high. Data changes are on trailing edge of the active clock pulse.
1 Clock is active high. Data changes are on leading edge of the active clock pulse.
2 Clock is active low. Data changes are on trailing edge of the active clock pulse.
3 Clock is active low. Data changes are on leading edge of the active clock pulse.
VAST_CLOSE( )
Use VAST_CLOSE() to end an SPI transfer by deselecting the VAST address of the
SPI peripheral with which you have been communicating.
Where:VAST_CLOSE(address)
- "address"
- is an integer number representing the VAST address.
* The address argument should always be 15 (the IIC VAST address) in order to deselect all VAST SPI devices.See the SPI Transfer example, below..
VAST_SPI_XFER( )
VAST_SPI_XFER() performs the actual transfer of information to and from a VAST
SPI peripheral.
Where:VAST_SPI_XFER(bit_count, dataval, clock)
- "bit_count"
- is the number of bits being transferred.
- "dataval"
- is data being transferred in integer form.
- "clock"
- is a long value representing the clock rate expressed in Hertz.
* This procedure sends "bit_count" bits of the dataval argument to the peripheral at clock rate "clock" expressed in Hertz.
* Data received during the transfer is returned as a LONG value.
* A minimum of 8 bits and a maximum of 16 bits can be sent or received in one transfer.
* The clock rate of the transfer is variable. With the peripheral used in the example below, the clock rate must be a minimum of 100000.
REM A function to start a conversion on a REM VAIO12/VADC12 then get the result using REM low level VAST functions in VBasic. REM This function runs conversions only on REM channel 0 of the VAIO12/VADC12 at REM VAST address 0. REM Note that the data values and transfers REM are specific to the VAIO12 peripheral and REM will not work for other VAST peripherals. REM This example is provided strictly as an REM illustration of proper use of the SPI REM transfer procedures. REM A function to perform an analog to REM digital conversion on a VADC12/VAIO12 CRITICAL FUNCTION VADC12_CONVERT() AS INTEGER LOCAL retval AS LONG CALL VAST_CLOCK(3) :REM active low :REM clock, leading :REM edge data shift CALL VAST_OPEN(0) :REM select VAST address REM Send a command byte which starts a REM unipolar conversion on channel 0. retval = VAST_SPI_XFER(8, 0x8E, 100000) REM To receive the conversion result REM outgoing data is all don't cares. REM Conversion result data is clocked in as REM the dummy data is clocked out. retval = VAST_SPI_XFER(13, 0, 100000) REM Now "close" the VAST connection to this peripheral CALL VAST_CLOSE(15) :REM Always call with '15' VADC12_CONVERT = RETVAL END REM MAIN -- Get analog input and print PRINT VADC12_CONVERT(),"\013\010"
VAST_IIC_START( )
VAST_IIC_START() sends an IIC start condition, which begins an IIC transfer.
Where:VAST_IIC_START()
* No value is required or allowed within the parenthesis.
* VAST address must be set to 15 using the VAST_OPEN() command prior to starting any VAST IIC transaction, and must remain at 15 until the transaction is completed.
See the IIC Transfer example, below.
VAST_IIC_STOP( )
VAST_IIC_STOP() is called to end an IIC transfer by sending an IIC stop condition.
Where:VAST_IIC_STOP()
See the IIC Transfer example, below.* No value is required or allowed within the parenthesis.
VAST_IIC_SEND(
)
VAST_IIC_SEND() sends out the low byte of the integer argument to the VAST bus.
Where:VAST_IIC_SEND(byte)
See the IIC Transfer example, below.
- "byte"
- is the value being sent.
VAST_IIC_READ(
)
This function reads data bytes from a VAST IIC peripheral.
Where:VAST_IIC_READ (last)
- "last"
- is a 0 or 1 indicating to the peripheral whether another byte will be read as part of the same transaction. (Zero = another byte expected, nonzero = no more bytes expected.)
AIN() will also work with this peripheral when properly configured. REM Run a conversion on channel 0 of the REM VAIODIO8 peripheral and return the REM result. REM Note that the data and number/order of REM transfers is specific to the VAIODIO8 REM peripheral, and will not work with REM other IIC devices. This example is REM provided strictly as an example of REM proper usage of the IIC transfer REM procedures. REM A function to perform an analog to REM digital conversion on a VAIODIO8 CRITICAL FUNCTION VAIODIO8_CONVERT() AS INTEGER LOCAL retval AS INTEGER REM Make sure we are addressing the IIC REM VAST address CALL VAST_OPEN(15) REM Send command bytes to start the REM conversion CALL VAST_IIC_START() retval = VAST_IIC_SEND(0x90) :REM Wakeup chip, etc. retval = VAST_IIC_SEND(0x40) retval = VAST_IIC_SEND(0x00) CALL VAST_IIC_STOP() REM The conversion result is collected in REM two separate transactions. CALL VAST_IIC_START() retval = VAST_IIC_SEND(0x91) retval = VAST_IIC_READ(1) :REM no more :REM bytes this transaction CALL VAST_IIC_STOP() CALL VAST_IIC_START() retval = VAST_IIC_SEND(0x91) retval = VAST_IIC_READ(1) :REM no more :REM bytes this transaction CALL VAST_IIC_STOP() :REM return the conversion value VAIODIO8_CONVERT = retval END REM MAIN - run conversion on VAIODIO8 and print PRINT VAIODIO8_CONVERT(),"\013\010"
Digital and Analog I/O
Digital | ||
VDIO_CONFIG() | configures digital I/O | |
Input | VTEST() | return the state of the input |
VINP() | return an 8 bit byte from the specified port and reads 8 inputs at a time | |
Output | VSET() | energize a relay |
VRESET() | de-energize a relay | |
VOUT() | write a specified byte to the specified port and controls 8 relays at one time | |
Analog | ||
Input | AIN_CONFIG() | set the type of peripheral to use for analog to digital conversions |
AIN() | read the specified AIN channel | |
Output | AOUT_CONFIG() | set the type of peripheral to use for digital to analog conversions |
AOUT() | set the specified D/A output to the specified value |
Board | Digital | I | O | Analog | I | O |
V4RLYOPTO | Y | Y | Y | |||
V8RLYOPTO | Y | Y | Y | |||
V16OPTO | Y | Y | ||||
V8ZPRLY | Y | Y | ||||
V32TTL | Y | Y | Y | |||
VAIODIO8 | Y | Y | Y | Y | Y | Y |
VADC8 | Y | Y | ||||
VAIO8 | Y | Y | Y | |||
VADC12 | Y | Y | ||||
VAIO12 | Y | Y | Y | |||
VADC24 | Y | Y | ||||
BADC12 | Y | Y |
VDIO_CONFIG ()
VDIO_CONFIG() configures digital I/O.
Where:VDIO_CONFIG(func, value)
This statement is usually executed only once, unless there are digital peripherals of a different configuration in the system that use the same digital control external procedures.
- "func"
- is function you want to set. Refer to the documentation on the peripheral you are using to see what func options are available for that peripheral.
- "value"
- is value that you want to set the function to. Refer to the documentation on the peripheral you are using to see what values are available for that function.
VSET()
VSET() will energize a relay.
Where:VSET(relay)
- "relay"
- is a literal or variable integer indicating the address of the relay you want to energize as determined by the jumper settings on the board you are using. Refer to the documentation on the peripheral you are using to find out what jumper settings correspond to what relay addresses.
VRESET()
VRESET() will de-energize a relay.
Where:VRESET(relay)
- "relay"
- is a literal or variable integer indicating the address of the relay you want to de-energize as determined by the jumper settings on the board you are using. Refer to the documentation on the peripheral you are using to find out what jumper settings correspond to what relay addresses.
VOUT()
VOUT() will write the specified byte to the specified port and controls 8 relays
at one time.
Where:VOUT (port, byte)
- "port"
- is a literal or variable integer indicating the relay or TTL port that you want to control. Refer to the documentation on the peripheral you are using to find out what jumper settings correspond to what ports.
- "byte"
- is an eight bit value where each bit controls one of the eight relays or TTLs.
Example:
VTEST() will configure a line as input and return the state of the input.VSET(1) VRESET(1) VOUT(1,2)
Where:VTEST(opto)
VINP() will read 8 inputs at a time and return an 8 bit byte from the specified port.
- "opto"
- is a literal or variable integer indicating the opto you want to test. Valid opto inputs are 0 to 479. Refer to the documentation on the peripheral you are using to find out what jumper settings correspond to what optos.
Where:VINP(port)
- "port"
- is a literal or variable integer indicating the opto or TTL port you want to read. Valid port addresses are 0 to 59. Refer to the documentation on the peripheral you are using to find out what jumper settings correspond to what ports.
* Each bit in the byte returned indicates one of the eight input values.
Example:
VTEST(1) VINP(1)
AIN_CONFIG()
AIN_CONFIG() selescts the peripheral you're working with and configures analog
to digital conversions.
Where:AIN_CONFIG(func, value)
- "func"
- is an integer representing the function being set. Refer to the documentation on the peripheral you are using to find out what func options are available for that peripheral.
- "value"
- is value that you want to set the function to. Refer to the documentation on the peripheral you are using to find out what values are available for that function.
* Func = 0 selects the peripheral where,
Value Board selected 0
VAIODIO8 1
VAIO8 2
VAIO12 or VADC12 3
VADC24 10
BADC12 20 MC2000-332 on board ADC
AIN()
AIN() reads the specified AIN channel.
Where:AIN(channel)
- "channel"
- is AIN channel you want to test. Refer to the documentation on the peripheral you are using to find out what channel options are available for that peripheral.
AOUT_CONFIG()
AOUT_CONFIG() configures digital to analog conversions.
Where:AOUT_CONFIG(func, value)
- "func"
- func should always be zero.
- "value"
- is value that you want to set the function to. Refer to the documentation on the peripheral you are using to find out what values are available for that function.
There is no need to call AOUT_CONFIG() before every conversion. Once configured, settings will remain so until changed.
AOUT() sets the specified D/A output to the specified value.
Where:AOUT(channel, value)
- "channel"
- is the AIN channel you want to set. Refer to the documentation on the peripheral you are using to find out what channel options are available for that peripheral.
- "value"
- is value that you want to set the channel to.
Configuring Off-board Serial Ports
Establishes serial buffers for the off-board serial ports COM4 - COM19.
Where:COMM_BUFFER (port AS INTEGER, address AS LONG, size AS INTEGER)
- "port"
- is the port number of the off-board serial port.
- "address"
- is the starting address of the buffer.
- "size"
- is the size of the buffer.
Input buffers collect incoming characters so that an application does not have to get each character from the port before the next one arrives. Vesta Basic does not automatically provide buffers for the ports on the BUS4SERIAL cards; you must use this routine in your application to provide them.
Where:VLED_COMMAND(board, intensity)
- "board"
- is the VAST address as determined by the ADDR jumpers. Refer to the documentation on the peripheral you are using for more information.
- "intensity"
- is a byte of data encoded as follows:
D7 Test - all segments on at maximum intensity when this bit is set to zero
D6-D4 Set to 0 - not used
D3-D0 Intensity - 0=off, 15=maximum
D6-D4 must be set to zero for proper operation. Non-zero values will disable areas of the matrix. Non-zero values will cause a subset of the digits to be individually enabled, starting from the rightmost digit.
VLED_MATRIX()
VLED _MATRIX() writes the byte of data to the digit at the specified position.
Where:VLED _MATRIX(position, byte)
Each bit of the byte controls a segment.
- "position "
- is the position of the LED in the LED matrix. Refer to the documentation for the peripheral you are using for more information.
- "byte"
- is value that you want to write.
Where:VLED_7SEGMENT(position, char, decpt)
- "position"
- is the left-to-right character position to be written. Positions 0-7 are at VAST address 0, positions 8-15 are at VAST address 1, and so on.
- "char"
- is the ASCII value of the character to be written to the display. Legal values are '0' through '9', 'A' through 'Z', 'a' through 'z', and ' ', '-', '_', and '.'.
- "decpt"
- is a flag indicating whether or not the decimal point segment should be lit for this character position. A zero value indicates that the decimal point should not be lit; a non-zero value indicates that the decimal point should be lit.