PBASIC is a
microcontroller
A microcontroller (MC, uC, or μC) or microcontroller unit (MCU) is a small computer on a single integrated circuit. A microcontroller contains one or more CPUs (processor cores) along with memory and programmable input/output peripherals. Pro ...
-based version of
BASIC
Basic or BASIC may refer to:
Science and technology
* BASIC, a computer programming language
* Basic (chemistry), having the properties of a base
* Basic access authentication, in HTTP
Entertainment
* Basic (film), ''Basic'' (film), a 2003 film
...
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 specialized 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 em ...
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 ...
microcontrollers. After the code is written, it is tokenized and loaded into an
EEPROM
EEPROM or E2PROM (electrically erasable programmable read-only memory) is a type of non-volatile memory. It is used in computers, usually integrated in microcontrollers such as smart cards and remote keyless systems, or as a separate chip d ...
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 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 ...
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
A piezoelectric speaker (also known as a piezo bender due to its mode of operation, and sometimes colloquially called a "piezo", buzzer, crystal loudspeaker or beep speaker) is a loudspeaker that uses the piezoelectric effect for generating sou ...
, for example).
Programming
In the Stamp Editor, the PBASIC
integrated development environment
An integrated development environment (IDE) is a Application software, software application that provides comprehensive facilities for software development. An IDE normally consists of at least a source-code editor, build automation tools, an ...
(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 (corresp ...
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 (, ) 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 o ...
('). 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 terminals ( SCP/ SFTP). Uploading can be used in th ...
ed to the Basic Stamp through an RS232 or USB cable and stored in the stamp's EEPROM as
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
PICAXE is a microcontroller system based on a range of Microchip Technology, Microchip PIC microcontroller, PIC microcontrollers. PICAXE devices are Microchip PIC devices with pre-programmed firmware that enables bootloading of code directly from a ...
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