1) Start up the PICAXE Programming Editor
- Make sure that the following options are selected (in View / Options...)
- PICAXE-18x (Mode tab)
- Text-mode Colour syntax (Editor tab)
- Compiler-Enhanced (Editor tab)
(if these aren't set correctly you won't be able to simulate)
- You should see the BASIC page. (if not, Click the Basic button.. )
2) Count-Up Loop:
This loop uses Variable b0 to store the count value. (It doesn't do anything useful inside the loop yet)
Here is your main program:
'---2 Count Up Loop -------------
let b0=0 ' set count to 0
do until b0=10
inc b0 ' count up by 1
loop ' loop back
let pins=%00000110 ' LEDs ON
'----------end of main program---
This program starts by setting the count to zero
It then loops 10 times,
and finally lights the LEDs
"let b0=0" to start the loop with a count of zero.
It uses "until b0=10" to control when the loop finishes.
It uses "inc b0" to step the count up by 1 each time you go round the loop.
This loop does not go on forever. It stops when the count reaches 10.
3) Simulate the loop.
Click on Simulate/Step on the menu bar.
The Simulator is ready to run the program, but won't do anything
until you tell it to step to the next basic command.
Switch on the "Show variables" part of the simulate screen.
There should be a Simulate window on the PC screen like this:
Step round the program.
the step button
Each line will be highlighted as it briefly runs.
Step on till you get
to the first
What is the value of b0 the first time you get to the "do" command
Now watch the variable b0 increase each time it passes the line "inc b0" in the program
Finally check that it goes to line "let pins=%00000110" when the count is high enough.
What is the value of b0 when you get to line "let pins=%00000110"
In the simulator
there is a display of all 14 variables:
these are called b0 to b13.
In the loop above we only use b0.
We could have used any of the other 13.
numbers, the smallest is 0, the largest is 255.
You can do maths with variables -
add numbers to variables or subtract them
add 2 variables together
multiply and divide variables or numbers.
You can use a variable's value to control a decision
e.g. "if b0=99"
All variables are set to zero when the program starts.
5) Questions on
(You might like to use the let simulator to help you with some of these... )
Write a program to call
"fwd" 30 times using a count-up loop.
Use subroutine "swonoff" to wait for the right microswitch before you start.
You'll need to fetch "swonoff" and "fwd" from the subroutines page.
Put these subroutines at the very bottom of your program.
Here is a blank program to get you started:
Content Scl Version 23/04/07