© Michael Fenton 2008
Connecting the PICAXE 08M and PICAXE 18X
to the Casio 9750G Plus graphics calculator
Introduction to Casio BASIC
Compiled from various web resources
July 2008 © Michael Fenton
1 of 20
© Michael Fenton 2008
Casio BASIC
PART 1: Creating a Program
To create a new program press then locate the program icon, press ,
press to create a new program. You will then be asked to enter a name for
your program, also you may create a password at this time (WARNING: if you put a
password on your program you will not be able to use the debugger).
PART 2: Variable Basics
A variable is something which holds a value. The most commonly used are the
letters A~Z and r,_. There are others, but they are not covered in this section. To
store a value into a variable you must use the key, like this:
CODE
1->A // Assigns 1 to A
It should look like this:
CODE
1->A~D // Assigns 1 to A B C & D
Variables are the most important aspect of programming.
PART 3: Basic Loops
Loops are used to repeat blocks of code. There are several types of loops in Casio
BASIC: Goto/Lbl, Do/lpWhle, For/Next, and While/WhileEnd. Here is an example of
a Goto/Lbl loop:
CODE
1->A //Assigns 1 to A
Lbl 1
A+1->A //Adds 1 to the variable A and stores new value
Goto 1 //Returns to Lbl 1
This loop will execute infinitely, Adding 1 to A each time (actually it will stop when
the value of A is greater than 99*10^99 because you will get a mem error).
Here is an example of a For loop; note that it does not take as many lines:
CODE
For 1->A to 100 Step 1
//this loop assigns 1 to A then adds 1 to A until it equals 100
Next //Goes back to the start of the loop, adds the step to the
variable.
2 of 20
© Michael Fenton 2008
Anything between the For and next statement will be executed until the expression
evaluates true (A equals 100). By changing the value of Step you can change how
much A is incremented by.
The While loop checks to see if the expression is true then executes the code. After
the code has been executed it returns to the top, checks the expression, and if it is
false jumps out of the loop and continues with executing the program. This is an
example of a While loop.
CODE
1->A
While 1=1 //1 always equals 1 so the expression always evaluates to
True
A+1->A
WhileEnd
Since the while loop evaluates the expression before executing the code it is
possible that if the expression is false before loop begins (ex: 1=2) then the loop
will never occur, it will just skip right over the code and continue with the program.
Unlike a while loop a Do/LpWhle loop will always execute at least once since it
evaluates the expression after the code has been executed. A Do/LpWhle loop looks
like this.
CODE
1->A
Do //Start of the Do/LpWhle loop
A+1->A
LpWhle A<100 //Loops while A is less than 100
PART 4: Selection Statements
Selection Statements are used to make programs have differing outcomes, instead
to executing the same way every time they are run. A selection statement checks
an expression, sees if it is True or False, then if True executes the rest of the
statement otherwise it skips to below the statement and continues with execution.
There are two types of selection statements on the calculator. They are the If/Else
statement and the => arrow.
3 of 20
An If/Else statement works like this
CODE
1->A
If A=1 //expression to be evaluated
Then “HI” //result if expression is true
“HOW ARE YOU”
Else “BYE” //result if expression is false
“SEE YOU LATER”
If End //end of statement
Result:
Since A is 1 the statement evaluates to true, therefore
QUOTE (Program Output)
HI
HOW ARE YOU
© Michael Fenton 2008
is printed. If you replaced the first line with 0->A then the if statement would
evaluate to False, and
QUOTE (Program output)
BYE
SEE YOU LATER
would be printed.
An If statement can contain many different things, and can be many lines long,
they are the keystone to making a game, and before going on you should feel
comfortable using them.
The => arrow is also very useful, it is a single line selection statement that takes
up less space but can do less than a normal if/else.
This is the same code as above, except using the => arrow instead of the If
statement.
CODE
1->A
A=1=>”HI”
A=1=>“HOW ARE YOU”
4 of 20
© Michael Fenton 2008
A<>1=>”BYE” // <> means not equal to
A<>1=>”SEE YOU LATER”
In general, the best time to use a if statement is when you have at least two lines
of code to be put inside, otherwise use the => arrow.
PART 5: Advanced Loops
Nesting is when you take one loop and put it inside another. Here is an example:
CODE
0->C
For 1->A To 10 //Step can be omitted instead of using Step 1
For 1->B To 10
A+B+C->C
Next
Next
C // the represents the output sign, it displays whatever is
before it and Pauses until [EXE] is pressed.
By executing this code you will get this output:
QUOTE (Program Output)
1100 //caused by
Now we will go through the code and look at what each line does.
Line 1: 0->C
Assigns the value 0 to the variable C
Line 2: For 1->A To 10
Tells the program that you will be looping until A is equal to 10, adding 1 with each
loop.
Line 3: For 1->B To 10
Tells the program that you will be looping until B is equal to 10, adding 1 with each
loop.
Line 4: A+B+C->C
The current value in A will be added to the current value of B, that value is then
added to the current value of C and then assigned to C.
Line 5: Next
Goes to line 3.
Line 6: Next
Goes to line 2.
Line 7: C
5 of 20
© Michael Fenton 2008
Displays the final value of C.
As you can see, the second loop executes completely for each iteration (loop) of the
first loop.
Nesting also applies to selection statements, you can nest if or => inside each
other as needed.
Example:
CODE
A<1=>A>0=>”HI”
If A<1
Then if A>0
Then “HI”
End If
End If
Part 6: Logical Operators
As you have just seen, there are times when you will want more than one condition
in a selection or loop, you can nest the statements or you can use a logical
operator: AND OR, NOT.
AND and OR are operators which can be used in selection statements to specify
additional conditions, therefore the code above could be written:
CODE
A<1 and A>0=>”HI”
Instead of:
CODE
A<1=>A>0=>”HI”
The OR operator allows you to specify alternate conditions which are evaluated
independently and if any are true then the entire statement is considered true. This
means you can do this:
CODE
If A=1 Or B=1
Then “TRUE”
End If
When this executes it will print TRUE if A or B equals 1.
The NOT operator can also be used in selection statements, though it is not used
6 of 20