|
Page 4 of 5 ZBasic Features and FunctionThe
ZBasic programming language consists of BASIC language constructs that
are compatible with Microsoft’s Visual Basic version 6 (VB6) together
with a comprehensive function library. The language supports
variables of the following data types; Byte, Integer, Unsigned Integer,
Long, Unsigned Long, Single, Nibble, Bit, Enum and String. Integers are
stored in 2 bytes, Longs in 4 bytes and Single precision floating point
numbers also in 4 bytes. Double precision floating point numbers are
not supported. A Nibble is a 4 bit quantity and a Bit is self-evident.
Enums are used for enumerations that are stored as 2 byte quantities.
ZBasic also supports arrays of the major data types including String.
The data itself can be stored in RAM as globals or on the stack,
on-chip persistent memory, or off-chip EEPROM. Control
structures are via the usual conditionals (if/then/else/elseif),
looping constructs (for/while/repeat..until), and select case
statements. The ZBasic language allows the VB6 facility that any kind
of condition can be placed in an individual select case statement.
Control flow can also be altered using goto statements, subroutines,
function calls and exception handling. A special language construct is
used to start new tasks as shown in the example program. The
ZBasic language really shines with its function library that is a
superset of the BasicX library with 60 new functions not found in
BasicX. The ZBasic function library, which consists of 176 functions
and subroutines, is completely implemented in the ATmega32 flash memory
for performance. Here is an overview of the eleven categories of
functions and subroutines provided by ZBasic: | 10 routines to perform various kinds of data manipulation such as shift left. | | 8 routines to get and set the time of day from the on-chip real time clock (RTC). | | 37
routines to support a range of I/O functions including 1-wire, 2-wire
serial (I2C), 3‑wire serial (SPI), ADC, DAC, pulse input or output,
pulse counting, pulse width input or output, synchronous serial input
or output, X10, and sine wave output. Most of these I/O functions can
be done on any I/O pin depending on restrictions imposed by the
ATmega32. | | 24 routines with a range of math functions such as Sin, Arc Tan, Log and Max. | | 19
routines to read, write and copy data between various types of memory
including RAM, on-chip EEPROM persistent memory and off-chip EEPROM. | | 10 routines to handle queuing and dequeuing of data on programmer defined queues. | | 10
routines to both read and write to serial ports on up to 5 serial
channels. One hardware-based serial channel (COM1) can support up to
460,800 baud and the other four software-based ports support up to
19,200 baud. | | 11 routines to perform string manipulation such as Len and Mid. | | 16
routines to perform various kinds of task management such as locking a
task, delays, interval timer and wait for an interrupt (supports up to
3 interrupt levels) | | 18
routines to convert between various data types including various
integral types such as Long, Single precision floats, enumerations and
Strings | | 13 other routines for random number generation, C type exception handling, and setting the watchdog timer. |
The
ZBasic platform is backwards compatible with BasicX in terms of the
programming language syntax and function library with a few exceptions
where it was impossible or impractical to exactly duplicate the BasicX
functionality or where a program relies on the content of system data
structures. The few existing compatibility issues mostly arise because
the ZBasic chip is running at twice the clock speed of the BasicX. The
ZBasic runtime implementation also fixes a number of bothersome
anomalies and function deficiencies in the BasicX function library that
have existed since BasicX chips were first shipped in 2002. One
nice feature of the ZBasic platform is the ability to field-upgrade the
virtual machine inside the flash memory of the chip by simply
downloading a new one. There is even a backup mechanism if the flash
download should fail in some way and make the ZBasic runtime
inoperable. The flash memory images are encrypted to prevent
unauthorized copying of the ZBasic runtime. I expect flash memory
upgrades of the ZBasic runtime as the platform gets more mature and
this download feature avoids the need to return or purchase “upgrade”
chips.
|