PBASIC

Microcontroller based version of BASIC


title: "PBASIC" type: doc version: 1 created: 2026-02-28 author: "Wikipedia contributors" status: active scope: public tags: ["embedded-systems", "parallax,-inc.-products", "basic-programming-language"] description: "Microcontroller based version of BASIC" topic_path: "technology/programming-languages" source: "https://en.wikipedia.org/wiki/PBASIC" license: "CC BY-SA 4.0" wikipedia_page_id: 0 wikipedia_revision_id: 0

::summary Microcontroller based version of BASIC ::

PBASIC is a microcontroller-based version of BASIC created by Parallax, Inc. in 1992.

PBASIC was created to bring ease of use to the microcontroller and embedded processor world. It is used for writing code for the BASIC Stamp microcontrollers. After the code is written, it is tokenized and loaded into an EEPROM on the microcontroller. These tokens 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 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 (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: ' {$STAMP BS1} ' {$STAMP BS2} ' {$STAMP BS2e} ' {$STAMP BS2sx} ' {$STAMP BS2p} ' {$STAMP BS2pe} ' {$STAMP BS2px} The programmer must also select which PBASIC version to use, which he or she may express with commands such as these: ' {$PBASIC 1.0} ' use version 1.0 syntax (BS1 only) ' {$PBASIC 2.0} ' use version 2.0 syntax ' {$PBASIC 2.5} ' use version 2.5 syntax

An example of a program using HIGH and LOW to make an LED 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 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 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: ::code[lang=basic] 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 uploaded 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.

Other chips

The PICAXE microcontroller uses a version of Basic similar to the version used to program the Basic Stamp I.

References

References

  1. [http://legacy.arts.ufl.edu/composition/downloads/MicroV1_9.pdf What's a Microcontroller, ver. 1.9 (for first "experiment")], Student Guide for Experiments #1 through #6, Parallax, Inc, Page 3(Preface) ''...The business grew slowly until 1992 when Parallax released the first BASIC Stamp...''
  2. Scott Edwards, [http://www.parallax.com/Portals/0/Downloads/docs/cols/nv/vol1/col/nv17.pdf "Exploring the BS1 EEPROM"]{{Dead link. (July 2025)
  3. Chuck McManis, [http://www.piclist.org/techref/microchip/language/basic/stamp-decode.htm "Decoding the BASIC Stamp"] {{webarchive. link. (2013-04-15 , 1994.)

::callout[type=info title="Wikipedia Source"] This article was imported from Wikipedia and is available under the Creative Commons Attribution-ShareAlike 4.0 License. Content has been adapted to SurfDoc format. Original contributors can be found on the article history page. ::

embedded-systemsparallax,-inc.-productsbasic-programming-language