PBASIC is a
microcontroller
A microcontroller (MCU for ''microcontroller unit'', often also MC, UC, or μC) is a small computer on a single VLSI integrated circuit (IC) chip. A microcontroller contains one or more CPUs ( processor cores) along with memory and programma ...
-based version of
BASIC
BASIC (Beginners' All-purpose Symbolic Instruction Code) is a family of general-purpose, high-level programming languages designed for ease of use. The original version was created by John G. Kemeny and Thomas E. Kurtz at Dartmouth College ...
created by
Parallax, Inc. in 1992.
PBASIC was created to bring ease of use to the microcontroller and
embedded processor
An embedded system is a computer system—a combination of a computer processor, computer memory, and input/output peripheral devices—that has a dedicated function within a larger mechanical or electronic system. It is ''embedded'' ...
world. It is used for writing code for the
BASIC Stamp
The BASIC Stamp is a microcontroller with a small, specialized BASIC interpreter ( PBASIC) built into ROM. It is made by Parallax, Inc. and has been popular with electronics hobbyists since the early 1990s.
Technical specifications
Although t ...
microcontrollers. After the code is written, it is tokenized and loaded into an
EEPROM
EEPROM (also called E2PROM) stands for electrically erasable programmable read-only memory and is a type of non-volatile memory used in computers, usually integrated in microcontrollers such as smart cards and remote keyless systems, or as ...
on the microcontroller. These
token
Token may refer to:
Arts, entertainment, and media
* Token, a game piece or counter, used in some games
* The Tokens, a vocal music group
* Tolkien Black, a recurring character on the animated television series ''South Park,'' formerly known as ...
s are fetched by the microcontroller and used to generate
instructions
Instruction or instructions may refer to:
Computing
* Instruction, one operation of a processor within a computer architecture instruction set
* Computer program, a collection of instructions
Music
* Instruction (band), a 2002 rock band from New ...
for the processor.
Syntax
When starting a PBASIC file, the programmer defines the version of the
BASIC Stamp
The BASIC Stamp is a microcontroller with a small, specialized BASIC interpreter ( PBASIC) built into ROM. It is made by Parallax, Inc. and has been popular with electronics hobbyists since the early 1990s.
Technical specifications
Although t ...
and the version of PBASIC that will be used. Variables and constants are usually declared first thing in a program. The DO LOOP, FOR NEXT loop, IF and ENDIF, and some standard BASIC commands are part of the language, but many commands like PULSOUT, HIGH, LOW, DEBUG, and FREQOUT are native to PBASIC and are used for special purposes that are not available in traditional BASIC (such as having the Basic Stamp ring a
piezoelectric speaker, for example).
Programming
In the Stamp Editor, the PBASIC
integrated development environment
An integrated development environment (IDE) is a software application that provides comprehensive facilities to computer programmers for software development. An IDE normally consists of at least a source code editor, build automation tools a ...
(IDE) running on a (Windows) PC, the programmer has to select 1 of 7 different basic stamps, BS1, BS2, BS2E, BS2SX, BS2P, BS2PE, and BS2PX, which is done by using one of these commands:
'
'
'
'
'
'
'
The programmer must also select which PBASIC version to use, which he or she may express with commands such as these:
' ' use version 1.0 syntax (BS1 only)
' ' use version 2.0 syntax
' ' use version 2.5 syntax
An example of a program using HIGH and LOW to make an
LED
A light-emitting diode (LED) is a semiconductor device that emits light when current flows through it. Electrons in the semiconductor recombine with electron holes, releasing energy in the form of photons. The color of the light (cor ...
blink, along with a DO...LOOP would be:
DO
HIGH 1 'turn LED on
I/O pin 1 on
PAUSE 1000 'keep it on for 1 second
LOW 1 'turn it off
PAUSE 500 'keep it off for 500 msec
LOOP 'repeat forever
An example of a program using HIGH and LOW along with the FOR
NEXT loop would be:
counter VAR Byte 'sets variable "counter
FOR counter = 1 to 5
HIGH 1 'make pin 1
logic level
In digital circuits, a logic level is one of a finite number of states that a digital signal can inhabit. Logic levels are usually represented by the voltage difference between the signal and ground, although other standards exist. The range of ...
high (5 V)
PAUSE 1000 'keep it on for 1000 msec
LOW 1 'turn it off
PAUSE 500 'keep it off for 500 msec
NEXT 'redirects to beginning four more times
END 'end program
Comments in the code are preceded by an
apostrophe
The apostrophe ( or ) is a punctuation mark, and sometimes a diacritical mark, in languages that use the Latin alphabet and some other alphabets. In English, the apostrophe is used for two basic purposes:
* The marking of the omission of one ...
('). The microcontroller ignores the rest of the line and continues to the next each time it encounters a comment. PBASIC codes can be simply a list of statements:
HIGH 1 'turn on LED on pin 1
PAUSE 1000 'pause for one second
LOW 1 'turn off LED on pin 1
END 'end program
If the programmer selects 'Run' from the IDE's menu, the program is tokenized and
upload
Uploading refers to ''transmitting'' data from one computer system to another through means of a network. Common methods of uploading include: uploading via web browsers, FTP clients], and computer terminal, terminals (SCP/ SFTP). Uploadi ...
ed to the Basic Stamp through an RS232 or USB cable and stored in the stamp's EEPROM as
Threaded code#Huffman threading, Huffman compressed non-byte-aligned variable-length tokens, and immediately executed. For example, a GOSUB statement uses 20 bits, including 11 bit-oriented addressing bits for the subroutine address. Because statements are non-byte-aligned, a subroutine can start on any bit in any byte in the EEPROM.
[Chuck McManis]
"Decoding the BASIC Stamp"
, 1994.
Other Chips
The
PICAXE microcontroller uses a version of Basic similar to the version used to program the Basic Stamp I.
References
External links
"Comparing PBASIC 2.5 control structures to the old PBASIC"– By Tracy Allen, EME Systems, 2003
Parallax, Inc.– Corporate website
{{BASIC
Embedded systems
Parallax, Inc. products
BASIC programming language