PBASIC: Difference between revisions
{{reflist}} |
Grammar edit: microcontroller based to microcontroller-based |
||
Line 1: | Line 1: | ||
{{Unreferenced|date=August 2007}} |
{{Unreferenced|date=August 2007}} |
||
'''PBASIC''' is a [[microcontroller]] |
'''PBASIC''' is a [[microcontroller]]-based version of [[BASIC programming language|BASIC]] created by [[Parallax, Inc. (company)|Parallax, Inc.]] The language was created to bring ease of use to the microcontroller and [[embedded processor]] world. PBASIC 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 [[token (parser)|token]]s are fetched by the microcontroller and used to generate [[instruction (computer science)|instructions]] for the processor. |
||
==Syntax== |
==Syntax== |
Revision as of 07:03, 1 November 2012
PBASIC is a microcontroller-based version of BASIC created by Parallax, Inc. The language was created to bring ease of use to the microcontroller and embedded processor world. PBASIC 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 used for special purposes that are not available in traditional BASIC (such as having the Basic Stamp ring a piezo-speaker, for example).
Programming
In PBASIC you have to select 1 of 7 different basic stamps, BS1, BS2, BS2E, BS2SX, BS2P, BS2PE, and BS2PX,
and to that you have to select one of these commands:
' {$STAMP BS1}
you also have to select a PBASIC version.
To do that you have to select one of these commands:
' {$STAMP BS2}
' {$STAMP BS2e}
' {$STAMP BS2sx}
' {$STAMP BS2p}
' {$STAMP BS2pe}
' {$STAMP BS2px}
' {$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 along with the DO...LOOP
Would Be:
DO
HIGH 1 'turn LED in pin 1 on
PAUSE 1000 'keep it on for 1 second
LOW 1 'turn it off
PAUSE 500 'keep it off for ½ second
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 'turn LED in pin 1 on
PAUSE 1000 'keep it on for 1 second
LOW 1 'turn it off
PAUSE 500 'keep it off for ½ second
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:
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
The PBASIC code is stored in the microcontroller EEPROM as Huffman compressed non-byte-aligned variable-length tokens.[1] 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.[2]
Other Chips
The PICAXE microcontroller uses a version of Basic similar to the version used to program the Basic Stamp I.
External links
![](http://upload.wikimedia.org/wikipedia/commons/thumb/d/df/Wikibooks-logo-en-noslogan.svg/40px-Wikibooks-logo-en-noslogan.svg.png)
- ^ Scott Edwards. "Exploring the BS1 EEPROM". The Nuts and Volts of BASIC Stamps (Volume 1). July 1996.
- ^ Chuck McManis. "Decoding the BASIC Stamp". 1994.
- "Comparing PBASIC 2.5 control structures to the old PBASIC" – By Tracy Allen, EME Systems, 2003
- Parallax, Inc. – Corporate website