122-32000 Parallax Inc, 122-32000 Datasheet - Page 94

MANUAL PROPELLER

122-32000

Manufacturer Part Number
122-32000
Description
MANUAL PROPELLER
Manufacturer
Parallax Inc
Datasheets

Specifications of 122-32000

Accessory Type
Manual
Lead Free Status / RoHS Status
Lead free / RoHS Compliant
For Use With/related Products
Propeller Education (PE) Kit
Lead Free Status / Rohs Status
Lead free / RoHS Compliant
Exercise 1: Output.spin Explanation
Now for an explanation of the source code:
PUB Toggle
The first line,
method is the object-oriented term for “procedure” or “routine.” We chose the name
simply because it is descriptive of what the method does and we knew it is a unique symbol;
it must be a unique symbol and conform to the Symbol Rules on page 159. We’ll describe
the term
contain at least one public (
The rest of the code is logically part of the
spaces from the
good habit for clarity.
The first line of the
direction of I/O pin 16 to output. The
through P31; clearing or setting bits within it changes the corresponding I/O pin’s direction to
input or output. The
register’s bit 16; the one that corresponds to I/O pin 16. Finally, the
operator that causes direction register bit 16 to be set to high (1); which makes I/O pin 16’s
direction an output. The Post-Set operator is a shorthand way of saying something like
dira[16] := 1
The next line,
loop runs infinitely, toggling P16, waiting ¼ second, toggling P16, waiting ¼ second, etc.
The next line,
The
!
corresponds to I/O pin 16. The
toggles the state of all bits specified to its right (the bit corresponding to I/O pin 16 in this
case).
The last line,
means “Wait for System Counter.” The cnt symbol is the System Counter register;
Page 94 · Propeller Manual v1.0
outa[16]
dira[16]~~
repeat
OUTA
!outa[16]
waitcnt(3_000_000 + cnt)
PUB
symbol is the output state register for I/O pins P0 through P31. The
indicates we want to access only the output register’s bit 16; the one that
, “public,” in more detail later, but it’s important to note that every object must
PUB Toggle
waitcnt(3_000_000 + cnt)
!outa[16]
repeat
which may look familiar to you from other languages.
PUB
’s column to make that more clear; this indenting isn’t required but is a
, creates a loop consisting of the two lines of code below it. This
Toggle
[16]
, toggles the state of I/O pin 16 between high (VDD) and low (VSS).
, declares that we’re creating a “public” method called “
PUB
following
) method.
method (second line of our example),
!
at the start of this statement is the Bitwise Not operator; it
dira
DIRA
, causes a delay of 3 million clock cycles.
indicates we want to access only the direction
Toggle
symbol is the direction register for I/O pins P0
method. We indented each line by two
dira[16]~~
~~
is the Post-Set
Toggle
, sets the
WAITCNT
[16]
REPEAT
Toggle
.” A
CNT
in

Related parts for 122-32000