PBASIC

From Wikipedia, the free encyclopedia

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.

[edit] 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).

[edit] Programming

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                                                                 

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
pause 1000
Low 1
End

[edit] External links