nearly as often. NOT returns False if the statement is true (or 1) and True if the
statement is False (or 0) so:
CODE
If Not (A=1)
Then “TRUE”
End If
This will print true if A is any number but 1. In this case the Not statement is used
as an <> (not equal to) statement, but it has other uses. We will cover more on
this later.
Part 7: Input Basics
You might want to get information from the user. The simplest way to get input
from the user is to use the ? command.
Syntax: ?->(Variable)
Description: this command causes a ? to appear on the screen, execution pauses
until the user enters data and hits , then the data is put into the variable. This
is a good way to ask yes or no questions, with the user having to enter 1 for yes
and 0 for no.
Another way you can use the ? command is to put a prompt before it: “Continue
(1=YES 0=NO)”?->C
This causes the text to be displayed with a ? after it and waits for data.
Part 8: Key Input
Sometimes you will want to know what key the user is pressing, to do this you
must use the Getkey command.
Syntax: Getkey->(variable) or if Getkey=(key number)
Description: Getkey returns a different value for each key pressed, if no key is
pressed then it returns 0, here is a simple program used to display the value of a
key.
CODE
Lbl 1
Locate 1,1,Getkey
Goto 1
The only key which does not return a value is AC/On.
"THIS ISN'T SHOWN, IT ISN'T EVEN LOOKED AT BY THE PROGRAM"
"NEITHER IS THIS"
WhileEnd
"ESCAPE FROM THE LOOP" //Break goes to here
now we will look at how Break works in nested loops
CODE
While A<>B
Do
Break
LpWhile A=A
//Break goes to here
WhileEnd //loops like normal
As you can see, Break only exits the current loop, and when that loop comes
around again and if Break isn't executed (if it’s in an If statement) then the loop
does not terminate and continues like normal. Get it?
CASIO Basic examples
Example 1:
====SUMDICE===
Lbl 1
“First number”? -> A
If Int (A) A
Then Goto 1
IfEnd
“Second number”? -> B
AxB
Goto 1
How It Works
We have told the program to take the integer of A and test it against the actual
value of A. If these two don’t equal, then obviously A is not an integer. The next
part of the statement is the Then command, since we said, ‘if they don’t equal, then
go to label 1’. If A is an integer, the program will ignore the Then statement.
The ⇑ symbol is in the PRGM (SHIFT VARS) menu and it means ‘stop the program
and display this result’
The usefulness of the results in the simulation is limited because the outcomes are
not stored anywhere, since the variable S is always changing during each loop. This
is why it is a good idea to store data in lists (sometimes called arrays), where it can
then be analysed later. This is the purpose of this lesson.
In order to store the data in a list, we must first set the dimensions of the list. This
means telling the calculator how many elements there are to be stored.
Since we are using the variable C as the number of simulations, this will be used
as the dimensions of list 1.
Lets set C equal to 5….
C -> 5
Then add the line
The commands Dim and List are found in the LIST menu, which is in the OPTN
menu. Press OPTN, followed by LIST (F1). Just about any action that relates to lists
will be found in this menu.
C -> Dim List 1
A Bit of Extra Help
Enter RUN mode from the Main Menu. Enter this line and press EXE.
C -> Dim List 1
This line says that I want to have 5 ‘empty’ elements in List 1 (they are in fact filled
with the value of 0).
Press MENU and then enter STAT mode. You will see that there are 5 ‘empty’
elements in List 1.
You will notice that this command has created 5 ‘empty’ elements in list 1. As a
rule, whenever you want data to be stored in a list (during the execution of a
program), you must first create empty elements using the command described
above. This is, if you tried to enter data in position 6, you would receive an error
message.
CODE
For 1 -> Z to C
Int (6Ran#)+1 -> M
Int (6Ran#)+1 -> N
M + N -> S
S -> List 1[Z]
Next
When the program first comes to the For statement, it will set Z to 1 and go through
and execute everything on the way to the Next command. This means it will get to
-> List 1[Z]
and send the value of S (which has been set as M+N) to List 1, row Z, which at the
moment is 1. After this, the program will move on to the next line, which is the Next
command in this case.
Once it gets to the Next command, the program will go back to the For command
and do it again, except Z will now be set to 2. So then the new value of S will be
sent to List 1, row Z, which is now 2. This will continue over and over again until
Z=C.
Notice how having the
command within the For statement utilises the way Z increases by 1 each time.
The maximum number of elements that this particular calculator can
TTL-level (High=5V and Low=0V), asynchronous serial half-duplex communication,
connects to a PC´s RS-232 COM-port with a MAX232 or equivalent level-converter
circuit.
• Baud-rate: 9600 bps
• Parity: none
• Byte-size: 8 bits
• Stop-bits: FROM Casio: 2 bits TO Casio: 1 bit
The Casio-plug is a standard 2.5mm stereo jack with the following pindesignations:
• Sleeve Ground
• Ring Data to Casio
• Tip Data from Casio
2. Casio to Casio cross-over cable
2.5 mm stereo plug 2.5 mm stereo plug
3. Casio to PC RS232 interface
2.5 mm stereo plug from
Casio connected to a PC D9
female plug.
BC547C can substitute for
BC337 NPN transistors.
LED’s in series with Rx and TX can indicate communication to and from PC
6. Casio 9750G Plus Code: RECEIVE picaxe data into a List:
255 -> Dim List 1
255 -> Dim List 2
1 -> B
Lbl 1
"Get readings (1 = YES)"? -> A
A = 1 => Goto 2
Goto 1
Lbl 2
Receive (R)
// R x 0.123 -> A convert to degree celcius or whatever units
Getkey -> C
If C 1 47
Then Goto 3
IfEnd
If B < 256
Then B-1 -> List1[B]
A -> List2[B]
B+1 -> B
IfEnd
Lbl 3
ClrText
Locate 1,1, B-1
Locate 6,1, A
If B = 256
Then Locate 1,2, “LIST FULL!”
IfEnd
Goto 2
How It Works
• List 1 and List 2 is created with 255 spaces (rows) assigned to them
• Once the user inputs “1” the Casio displays data values from the PICAXE but
• From the MENU select STATs (2 on main menu)
• press F1 (GRPH) then F6 (SET) to set up the graphing options.
• Go down to graph type and press F6 to get to other graph types then choose
•
The data collected can be transformed to temperature, etc by adding line in
blue above (remove // remark symbol)
Students can try to fit a
only puts them into LIST 2 (y axis) if the EXIT button is pressed. List 1 is for
plotting the x axis 0 – 255 time intervals.
box (for a box and whisker).
Press EXIT back to the list (you should be able to see your data in the list),
press F1 to get a box and whisker graph, good for working out mean, upper
quartile and range.
Modified from article by Erik Grindheim, August ~ October 2001
There are four different types of data packets in use to transfer variables, in
addition to the single-byte packets. This section describes the structure of these
packets in detail:
Request packet:
Byte no (1-50) ASCII
1-4 :REQ $3A $52 $45 $51
5
6-7 VM (Variable)
8-11
12 A-Z / r / è (The name of the Variable:)
13-49
50
PC (Picture)
LT (List)
MT (Matrix)
$00
$56 $4D <-- This is the bytes we want...
$50 $43 ( Byte no 12-49 below is based )
$4C $54 ( on Variable transfers, VM. )
$4D $54 ( )
all $FF
10
11
12 A-Z / r / è
13-19
20-27 Variable
28 C or R $43 or $52
29
30-49
50
$00
$00
if the variable is reset/unused: $00 **
if variable is in use (normal): $01
$00
the same value as byte no 9: $00 or $01
all $FF
$56 $61 $72 $69 $61 $62 $6C $65
(If the variable has an imaginary
part: C-complex. Otherwise: R-real)
$0A
all $FF
Checksum
= $01 + not((sum bytes 1-49)- $3A)
**note: If bytes 9 and 11 has the HEXvalue 00 this
means that the variable has not been used
after last "Alpha Memory" reset. Then no
Value packet will be transmitted at all.
After this packet comes the End packet.
The smallest value the Casio accepts is ± 1.00000000000000 × 10
The greatest number the Casio accepts is ± 9.99999999999999 × 10
Zero is stored as + 0.00000000000000 × 10
Or, at a general form: ± I.decimals × 10
In the Value packet, byte no. 6 is containing the integer part I, always from $01 to
$09 (except if the variable value is exactly 0,0…).
Bytes no. 7 to 13 contain the 14 decimals represented as BCD data.
The exponent EE is represented in byte no. 15 and bit 0 of the SignInfoByte (byte
no. 14).
The sign indicating whether the value is negative or positive is held in bits 6 and 4
of the SignInfoByte.
ASCII
HEX ($)
$00 $01 $00 $01
$00-$09 (BCD 0 and BCD 0-9 (integer part))
$00-$99 (BCD for 14 digits (decimal part))
SignInfoByte. Bit set if...:
bit 7 - Variable has an imaginary part
bit 6 & 4 - Value (real part) is negative
bit 0 - Absolute value of (real part
of) value is 1,0... or more
bits 1, 2, 3 and 5 are always 0 / Low
Exponent, 00-99
Exp.: Byte:
+99 99 \
+01 01 -} byte 14 bit 0 = 1 (High) **
00 00 /
-01 99 \
-02 98 -} byte 14 bit 0 = 0 (Low)
-99 01 /
Checksum
= $01 + not((sum bytes 1-15)- $3A)
**note: If the variable is (exactly) 0,0
then the exponent is 00 (instead of minus
infinite) but this bit (bit 0 in byte
14) is still low because variable value
is less than 1.
As an example let’s show how the checksum of the End packet is calculated. This
value will always remain the same since nothing in this packet changes from time
to time. First we add all the previous 49 bytes. This gives us a sum of $E4 (the
excess carry digits are thrown away). Then we subtract $3A and the result is $AA.
We invert it (=$55) and add $01. The result is $56, which is the checksum-byte;
byte no. 50.
ASCII
ASCII
HEX ($)
Equal to bytes 1-15 in the 16 bytes
long Value packet for real numbers. These
bytes only describe the real part of the
variable, while the next 10 bytes describe
the imaginary part of the complex number:
$00-$09 (BCD 0 and BCD 0-9 (integer part))
$00-$99 (BCD for 14 digits (decimal part))
SignInfoByte. Bit set if...:
bit 7 - Always set to 1 (imaginary)
bit 6&4 - Value (img. part) is negative
bit 0 - Absolute value of (img. part
of) value is 1,0... or more
bits 1, 2, 3 and 5 are always 0 / Low
Exponent for the imaginary part; 00-99
Exp.: Byte:
+99 99 \
+01 01 -} byte 24 bit 0 = 1 (High)
00 00 /
•When the command is issued the Casio sends an “attention request” byte,
$15
•The external device must reply with a “device present” byte, $13 within 0.5
~ 1 second or a Com ERROR message is displayed
• The Casio sends a Request packet which consist of 50 bytes.
• The external device receives this and confirms with one byte, $06.
• The Casio confirms that it’s ready for a Variable-description packet with $06
• The external device sends a Variable-description packet consisting of 50
bytes. Byte 12 in this packet (variable name) seems to be totally ignored by
the Casio, as the variable is stored under the name indicated in the Request packet anyway. Still it’s recommended to send back the same name/byte as
received in the Request packet byte 12.
•The Casio confirms that it’s ready (for a Value packet or an End packet,
depending on byte 9 and 11 in the previous packet) with $06
•A Value packet is then sent from the external device. It is still consisting of
either 16 or 26 bytes, depending on whether the variable also contains an
imaginary part (complex number) or not. If the variable is empty this packet
is not sent at all (length: 0 bytes). This means that the actual “Alpha
Memory” variable in the Casio is deleted. This will free 10 (real) or 20
(complex) bytes of memory in the Casio. In calculations the deleted
variable’s value equals zero (0).
•If a Value packet was sent then the Casio confirms (as usual) with $06 (if
the variable is empty there is no Value packet, and this byte is not sent
either.)
•To close the communication cycle the external device sends an End packet
of 50 bytes. The end packet is always the same; none of the bytes change
their value.
•When the command is issued the Casio sends an “attention request” byte,
$15
•The external device must reply with a “device present” byte, $13 within 0.5
~ 1 second or a Com ERROR message is displayed
•The Casio starts to send the Variable-description packet, which consists of
50 bytes.
• The external device receives this and confirms with $06.
• The Casio sends its Value packet, consisting of either 16 or 26 bytes. Packet
length depends on whether the variable also contains an imaginary part
(complex number) or not. If the variable has never been assigned a value
since the last reset of “Alpha Memory” this packet will not be sent at all.
•The external device receives this packet and confirms with $06. (If an empty
variable is sent, then there is no Value packet, and this byte is not sent
either.)
•To close the communication cycle the Casio sends an End packet of 50
bytes. The end packet is always the same; none of the bytes change their
value.
Casio PICAXE
Variable
description packet
Value
packet
End
packet
20 of 20
Loading...
+ hidden pages
You need points to download manuals.
1 point = 1 manual.
You can buy points or you can get point for every manual you upload.