Step 19Using It: Your first Propeller Program
Boot it up the Propeller Tool and let's start with the most simple program, an LED blinky;
I'll break down each line:
PUB main
Programs start execution at the first method it finds. In this case, there's only one method (main), and it's a PUBlic method, but we don't need to worry about that now
dira[0] := 1
dira[0] is the 'direction register' for pin 0. By writing a value of 1 to the register, we make pin 0 an output. := is the assignment operator.
REPEAT
do everything that's tabbed below. A REPEAT loop without an UNTIL will repeat forever. Tabs are important in spin - everything indented under this line is part of the REPEAT loop.
!OUTA[0]
the ! operator means 'flip' and OUTA is the output register for pin 0. So this line takes the current value of outa[0], flips it, and write it back. If the pin is high, it will flip low. If the pin is low, it will flip high.
A fancy way of describing the ! is a 'Bitwise NOT assignment operator'.
WAITCNT(CLKFREQ + cnt)
Translation: Hold up for 1 second. WAITCNT(Time) will pause execution until the system clock == Time.
CLKFREQ is a system value - it equals the number of ticks in each second. CNT is another system value, it's the current system time (how many ticks since the Propeller has started). By adding 1 second's worth of ticks to the system clock, we're figuring out what the system clock will be one second from now.
And that's your first program!
What would you change if you wanted the LED to blink twice per second?
| « Previous Step | Download PDFView All Steps | Next Step » |
![]() |
Add Comment
|
























































