Home Chapter 7 BS2 Programming the project

Site Search

GTranslate

Chinese (Simplified) French German Italian Portuguese Russian Spanish
BS2 Programming the project

Schematic showing orientation of the LED. Notice how the flat mark of the LED is located closest to the ground plane of the BS2 or the same as VSS. The 470 ohm resistor comes out of pin 0 of the BS2

 

Programming the project

The programming syntax of PBASIC is the order in which the commands and the controlling aspects of each command are organized. It is important to pay attention to accidental spaces and dingbats that may cause your program to malfunction, as well as the order of the commands in your program. As with any natural language, the syntax defines the proper way and order to say something, and so the computer also needs proper syntax in order to understand your commands.

In the examples below, the commas indicate that the command HIGH is separate from the word pin,and this is where the pin number goes, so in the basic code example “introductory example”, notice there is not a comma in the actual code.

HIGH, pin

The HIGH command allows you to set the pin high or to 5 volts. Pin can be a variable, a constant, or an expression between 0 and 15. When you use HIGH, the pin is automatically specified as an output. Pin is a variable or a constant expression for pins 0 to 15 that specifies which I/O pin to set to HIGH. So, HIGH 7 would designate pin 7 as an output.

LOW, pin

The LOW command makes the pin specified low or 0 volts dc. It also sets the pin to an output state.

Pin is a variable or a constant expression for pins 0 to 15 that specifies which I/O pin to set to low. When this command is used, the pin will be placed into output mode.

PAUSE, period

The PAUSE command allows you to set up a pause in the execution of the code for the time you specify in the area called period, after the pause. This length of time can be varied from 0 to 65535. Each number is one millisecond, so PAUSE 1000 will stop the execution of the code for one second.

GOTO, address

The GOTO command is part of the branching capability that is built into PBASIC and allows you to move to the place in the program that you want the code to branch to next. You are allowed an unlimited number of GOTOs, but too many can be difficult to manage.

For an example, at the top of the program is a label called “Top:” and at the bottom of the program is the branching code that says GOTO Top.

Notice that you must place the colon after the word you have selected, such as the label “Top:” in order for the PBASIC to know that you have designated the word as a label. You do not have to use the colon again when you say GOTO, just simply, GOTO Top. After the program executes the code, the command GOTO Top sends it back to the beginning to execute the code again, continually, ad infinitum.
You will note that in the code below that after each bit of code is the symbol ‘.

This is used to allow you to create comments in your code but not have these comments affect the code. The comments do not take up any space in the program but are there to assist you to remember the logic of your program.

HIGH 0 ‘Set pin 0 to high.