ZBasic Language Reference
1
ZBasic Microcontrollers
The ZBasic Language
and ZX Series Microcontrollers
Chapter 1 - Introduction
The purpose of this manual is to describe the elements of the ZBasic language and the ZX series
microcontrollers for those who have, at a minimum, a rudimentary knowledge of programming concepts
and an understanding of basic electronics. It is not intended to teach programming skills nor electronics -
there are many texts available for that purpose.
The ZBasic programming language will be familiar to anyone who has used Microsofts Visual Basic
language or NetMedias BasicX language. ZBasic was designed to achieve a high level of compatibility
with these languages but it also incorporates some additional capabilities to improve its utility in the
microcontroller environment. Even if you arent familiar with either of these two particular dialects of the
Basic language, if you have used another fairly modern dialect of you will find many familiar elements. In
contrast, ZBasic is quite different from archaic dialects of Basic like the PBasic language developed by
Parallax for use on the Basic Stamp series of microcontrollers. Even so, moving from PBasic to ZBasic
should be a relatively easy and rewarding experience.
ZBasic incorporates the modern block structured programming elements that help make programs easier
to write, easier to maintain and more reliable. Moreover, it provides a good range of data types allowing
efficient representation of the data items you need in your application. Beyond that, it has facilities to
implement multi-tasking systems, allowing complex problems to be solved more easily.
All ZBasic programs comprise, at a minimum, one subroutine. That one required subroutine must be
named Main() and it must be defined as taking no parameters. Additionally, the Main() subroutine
must have public visibility as opposed to being private to a particular module. The minimal ZBasic
program is shown below, in its entirety.
' the minimal program
Sub Main()
End Sub
This do-nothing program illustrates several points. First is the structure of comments as illustrated on the
first line of the program. A comment consists of an apostrophe (sometimes called a single quote mark)
and all characters following it all the way to the end of the line. It is not necessary for a comment to be on
a line by itself. Characters occurring before the apostrophe are processed as if the comment portion of
the line werent present.
The second point illustrated by the program above is the manner in which subroutines are defined. A
subroutine definition begins with the keyword Sub. That is followed by at least one space or tab character
and then the name of the subroutine. Following the subroutine name is the parameter list, details of
which are discussed later in this document. The parameter list is always enclosed in a pair of
parentheses which must be present even if there are no parameters as is the case above. All of the
statements, if any, between the Sub line and the End Sub line constitute the body of the subroutine.
Here is another program, intended for a 24-pin ZX device, that is a bit more complicated.
Const redLED as Byte = 25
' define the pin for the red LED
Const grnLED as Byte = 26
' define the pin for the green LED
Sub Main()
' configure the pins to be outputs, LEDs off
Call PutPin(redLed, zxOutputHigh)
Call PutPin(grnLed, zxOutputHigh)
|