Chapter
Programming 8
8-1 Basic Programming Steps
8-2 Program Mode Function Keys
8-3 Editing Program Contents
8-4 File Management
8-5 Command Reference
8-6 Using Calculator Functions in Programs
8-7 Program Mode Command List
8-8 Program Library
This unit comes with approximately 144 kbytes of memory.
•You can check how much memory has been used and how much remains by entering the SYSTEM Mode from the Main Menu, and then pressing 1(Mem). See “9-2 Memory Operations” for details.
19990401
8-1-1
Basic Programming Steps
8-1 Basic Programming Steps
Description
Commands and calculations are executed sequentially, just like manual calculation multistatements.
Set Up
1.From the Main Menu, enter the PRGM Mode. When you do, a program list appears on the display.
Selected program area (use f and c to move)
Files are listed in the alphabetic sequence of their names.
Execution
2.Register a file name.
3.Input the program.
4.Run the program.
#If there are no programs stored in memory when you enter the PRGM Mode, the message “No Programs” appears on the display and only the NEW item (3) is shown in the function menu.
#The values to the right of the program list indicate the number of bytes used by each program.
#A file name can be up to eight characters long.
#The following are the characters you can use in
a file name:
A through Z, r, θ, spaces, [, ], {, }, ’, ”, ~, 0 through 9, ., +, –, ×, ÷
#Registering a file name uses 24 bytes of memory.
#The file name input screen remains on the display if you press wwithout inputting a file name.
#To exit the file name input screen and return to the program list without registering a file name, press i.
19990401
8-1-2
Basic Programming Steps
Example 1 To calculate the surface area (cm2) and volume (cm3) of three regular octahedrons when the length of one side is 7, 10, and 15 cm, respectively.
Store the calculation formula under the file name OCTA.
The following are the formulas used for calculating surface area S and volume V of a regular octahedron for which the length of one side A is known.
2
A S = 2 3 A2, V = –––– A3 3
Procedure
1mPRGM
23(NEW)OCTAw*1
3!J(PRGM)3(?)aav(A)6(g)6(g)3(:)*2 c*!x()d*av(A)x6(g)4(^)
!x( )c/d*av ii
41(EXE) or w hw(Value of A) w
w wbaw w
w wbfw w*3
(A)Md
S when A = 7 V when A = 7
S when A = 10 V when A = 10
S when A = 15 V when A = 15
*1 Press 3(NEW) and the cursor changes form to indicate alpha character input.
*2 The following shows how the calculation of the surface area and volume of a regular octahedron would be calculated using a manual calculation.
Surface Area S ... |
c*!x( )d* |
|
<value of A> xw |
Volume V ............ |
!x( )c/d* |
|
<value of A> Mdw |
*3 Pressing wwhile the final result of a program is on the display changes to the program list.
#You can also run a program while in the RUN • MAT Mode by inputting: Prog ”<file name>” w.
#Pressing wwhile the final result of a program executed using this method is on the display re-executes the program.
#An error occurs if the program specified by Prog ”<file name>” cannot be found.
20011101199904
8-2-1
Program Mode Function Keys
8-2 Program Mode Function Keys
• {NEW} ... {new program}
uWhen you are registering a file name
•{RUN}/{BASE} ... {general calculation}/{number base} program input
•{Q} ... {password registration}
•{SYBL} ... {symbol menu}
uWhen you are inputting a program —— 1(RUN) … default
•{JUMP} ... {top}/{bottom} of program
•{SRC} ... {search}
•{MAT}/ {STAT}/{LIST}/{GRPH}/{DYNA}/{RECR}
... {matrix}/{statistic}/{list}/{graph}/ {Dynamic Graph}/{recursion} menu
•Pressing !J(PRGM) displays the following PRGM (PROGRAM) menu.
•{Prog} ... {program recall}
•{JUMP} ... {jump command menu}
•{?}/{^} ... {input}/{output} command
•{I/O} ... {I/O control/transfer command menu}
•{IF}/{FOR}/{WHLE}/{CTRL}/{LOGIC}
... {conditional jump}/{loop control}/{conditional loop control}/{program control}/ {logical operation} command menu
•{CLR}/{DISP} ... {clear}/{display} command menu
•{:} ......... {separator for expressions and commands}
See “8-5 Command Reference” for full details on each of these commands.
• Pressing u3(SET UP) displays the mode command menu shown below.
• {ANGL}/{DISP}/{CPLX}/{GRPH}/{STAT}/{DERIV}/{T-VAR}/{Σ DSP}
See “SET UP Screen Function Key Menus” on page 1-7-1 for details about each of these commands.
19990401
8-2-2
Program Mode Function Keys
uWhen you are inputting a program —— 2(BASE)*1
•{JUMP}/{SRC}
•{d~o} ... {decimal}/{hexadecimal}/{binary}/{octal} value input
•{LOG} ... {logical operators}
•{DISP} ... conversion of displayed value to {decimal}/{hexadecimal}/{binary}/{octal}
•{SYBL} ... {symbol menu}
•Pressing !J(PRGM) displays the following PRGM (PROGRAM) menu.
•{Prog}/{JUMP}/{?}/{^}
•{= ≠<} ... {logical operator menu}
•{:} ......... {separator for expressions and commands}
•Pressing u3(SET UP) displays the mode command menu shown below.
•{Dec}/{Hex}/{Bin}/{Oct}
•{EXE}/{EDIT}
... program {execute}/{edit}
•{NEW} ... {new program}
•{DEL}/{DEL·A}
... {specific program}/{all program} delete
• {SRC}/{REN}
... file name {search}/{change}
*1 Programs input after pressing 2(BASE) are
indicated by B to the right of the file name.
19990401
8-3-1
Editing Program Contents
8-3 Editing Program Contents
kDebugging a Program
A problem in a program that keeps the program from running correctly is called a “bug,” and the process of eliminating such problems is called “debugging.” Either of the following symptoms indicates that your program contains bugs that require debugging.
•Error messages appearing when the program is run
•Results that are not within your expectations
u To eliminate bugs that cause error messages
An error message, like the one shown below, appears whenever something illegal occurs during program execution.
When such a message appears, press ito display the place in the program where the error was caused. The cursor will be flashing at the location of the problem. Check the “Error Message Table” (page α-1-1) for steps you should take to correct the situation.
•Note that pressing idoes not display the location of the error if the program is password protected. Instead, it returns to the program list screen.
u To eliminate bugs that cause bad results
If your program produces results that are not what you normally expect, check the contents of the program and make necessary changes.
The 1(JUMP) key is also useful when editing program contents.
1(JUMP)b(Top) ....... |
Moves the cursor to the |
|
top of the program |
1(JUMP)c(Bottom)…Moves the cursor to the bottom of the program
19990401
8-3-2
Editing Program Contents
kUsing an Existing Program to Create a New Program
Sometimes you can input a new program by using a program already in memory as a base. Simply recall the existing program, make the changes you need, and then execute it.
Example 2 To use the OCTA program (page 8-1-2) to create a program that calculates the surface area (cm2) and volume (cm3) of regular tetrahedrons when the length of one side is 7, 10, and 15 cm
Use TETRA as the file name.
AThe following are the formulas used for calculating surface area S and volume V of a regular tetrahedron for which the length of one side A is known.
|
2 |
|
S = 3 A2, V = –––– A3 |
|
12 |
Use the following key operations when inputting the program. |
|
Length of One Side A .. !J(PRGM)3(?)aav(A)6(g)6(g)3(:) |
|
Surface Area S |
............ !x( )d*av(A)x6(g)4(^) |
Volume V ..................... |
!x( )c/bc*av(A)Md |
Compare this with the program for calculating the surface area and volume of a regular octahedron.
Length of One Side A .. !J(PRGM)3(?)aav(A)6(g)6(g)3(:)
Surface Area S ............ |
c*!x( )d*av(A)x6(g)4(^) |
||
Volume V ..................... |
!x( )c/d*av(A)Md |
||
|
|
|
|
As you can see, you can produce the TETRA program by making the following changes in the OCTA program.
•Deleting c* (underlined using a wavy line above)
•Changing d to bc(underlined using a solid line above)
19990401
8-3-3
Editing Program Contents
Now edit OCTA to produce the TETRA program.
1. Edit the program name.
6(g)2(REN)ATETRAw
2. Edit the program contents.
2(EDIT)
eeeeDD cdDbc
i
3. Try running the program.
1(EXE) or w
hw(Value of A) w
w wbaw w
w wbfw w
19990401
8-3-4
Editing Program Contents
kSearching for Data Inside a Program
Example To search for the letter “A” inside the program named OCTA
1.Recall the program.
2.Press 2(SRC) or wand input the data you want to find.
2(SRC)
av(A)
3.Press wto begin the search. The contents of the program appear on the screen with the cursor located at the first instance of the data you specified.*1
4.Each press of wor 1(SRC) causes the cursor to jump to the next instance of the data you specified.*2
*1 The message “Not Found” appears when the search data you specify cannot be found in the program.
*2 If there are no more instances of the data you specified, the search operation ends and the cursor returns to the point from which you started your search.
#You cannot specify the newline symbol (_) or display command (^) for the search data.
#Once the contents of the program are on the screen, you can use the cursor keys to move the cursor to another location before searching for the next instance of the data. Only the part of the program starting from the current cursor location is searched when you press w.
#Once the search finds an instance of your data, inputting characters or moving the cursor causes the search operation to be cancelled.
#If you make a mistake while inputting characters to search for, press Ato clear your input and re-input from the beginning.
20011101199904
8-4-1
File Management
8-4 File Management
kSearching for a File
u To find a file using initial character search
Example To use initial character search to recall the program named OCTA
1.While the program list is on the display, press 6(g)1(SRC) and input the initial characters of the file you want to find.
6(g)1(SRC)
OCT
2.Press wto search.
• The name that starts with the characters you input highlights.
|
|
|
“Not Found” appears on the display. If this |
|
# If there is no program whose file name starts |
||
|
|
with the characters you input, the message |
happens, press ito clear the error message. |
|
|
|
|
19990401
8-4-2
File Management
kEditing a file name
Example To change the name of a file from TRIANGLE to ANGLE
1.While the program list is on the display, use f and c to move the highlighting to the file whose name you want to edit and then press 6(g)2(REN).
2.Make any changes you want.
DDD
3.Press wto register the new name and return to the program list.
The program list is resorted according to the changes you made in the file name.
kDeleting a Program
u To delete a specific program
1.While the program list is on the display, use f and c to move the highlighting to the name of the program you want to delete.
2.Press 4(DEL).
3.Press w(Yes) to delete the selected program or i(No) to abort the operation without deleting anything.
|
|
# If the modifications you make result in a file |
• Press ito clear the error and return to the file |
|
|
||
|
|
name that is identical to the name of a |
name editing screen. |
|
|
program already stored in memory, the |
• Press Ato clear the input file name and input |
|
|
message “Already Exists” appears. When this |
a new one. |
|
|
happens, you can perform either of the |
|
|
|
following two operations to correct the |
|
|
|
situation. |
|
|
|
|
|
19990401
8-4-3
File Management
u To delete all programs
1.While the program list is on the display, press 5(DEL·A).
2.Press w(Yes) to delete all the programs in the list or i(No) to abort the operation without deleting anything.
•You also can delete all programs by entering the SYSTEM Mode from the Main Menu, and then pressing 1(Mem) to display the memory management screen.
See “9-2 Memory Operations” for details.
kRegistering a password
When inputting a program, you can protect it with a password that limits access to the program contents to those who know the password.
• You do not need to input the password to run a program.
Example To create a program file under the name AREA and protect it with the password CASIO
1.While the program list is on the display, press 3(NEW) and input the file name of the new program file.
3(NEW)
AREA
2. Press 5(Q) and then input the password.
5(Q)
CASIO
#The password input procedure is identical to that used for file name input.
19990401
8-4-4
File Management
3.Press wto register the file name and password. Now you can input the contents of the program file.
4.After inputting the program, press !i(QUIT) to exit the program file and return to the program list. Files that are password protected are indicated by an asterisk to the right of the file name.
kRecalling a Password Protected Program
Example To recall the file named AREA which is protected by the password CASIO
1.In the program list, use f and c to move the highlighting to the name of the program you want to recall.
2.Press 2(EDIT).
3.Input the password and press wto recall the program.
#Pressing wwithout inputting a password while saving a new program causes the file to be saved without a password. Pressing w without inputting a password registers the file name only, without a password.
#Inputting the wrong password when recalling a password protected program causes the message "Mismatch" to appear. Press ito return to the password input screen.
19990401
8-5-1 |
|
|
|
Command Reference |
|
|
|
8-5 Command Reference |
|
|
|
|
|
|
|
kCommand Index |
|
|
|
Break ............................................................................................................... |
8-5-6 |
|
|
ClrGraph ....................................................................................................... |
8-5-11 |
|
|
ClrList ............................................................................................................ |
8-5-11 |
|
|
ClrText ........................................................................................................... |
8-5-12 |
|
|
ClrMat ............................................................................................................ |
8-5-12 |
|
|
DispF-Tbl, DispR-Tbl ..................................................................................... |
8-5-12 |
|
|
Do~LpWhile ..................................................................................................... |
8-5-5 |
|
|
DrawDyna ..................................................................................................... |
8-5-12 |
|
|
DrawFTG-Con, DrawFTG-Plt ........................................................................ |
8-5-13 |
|
|
DrawGraph ................................................................................................... |
8-5-13 |
|
|
DrawR-Con, DrawR-Plt ................................................................................. |
8-5-13 |
|
|
DrawRΣ-Con, DrawRΣ-Plt ............................................................................. |
8-5-14 |
|
|
.......................................................................................................DrawStat |
8-5-14 |
|
|
DrawWeb ....................................................................................................... |
8-5-14 |
|
|
Dsz .................................................................................................................. |
8-5-9 |
|
|
For~To~(Step~)Next ........................................................................................ |
8-5-4 |
|
|
Getkey ........................................................................................................... |
8-5-15 |
|
|
Goto~Lbl ....................................................................................................... |
8-5-10 |
|
|
If~Then~(Else~)IfEnd ...................................................................................... |
8-5-4 |
|
|
Isz .................................................................................................................. |
8-5-11 |
|
|
Locate ............................................................................................................ |
8-5-16 |
|
|
Prog ................................................................................................................ |
8-5-7 |
|
|
Receive ( / Send ( .......................................................................................... |
8-5-17 |
|
|
Return ............................................................................................................. |
8-5-8 |
|
|
Stop ................................................................................................................ |
8-5-8 |
|
|
While~WhileEnd .............................................................................................. |
8-5-6 |
|
|
? (Input Command) ......................................................................................... |
8-5-2 |
|
|
^ (Output Command) ..................................................................................... |
8-5-3 |
|
|
: (Multi-statement Command) .......................................................................... |
8-5-3 |
|
|
_ (Carriage Return) ....................................................................................... |
8-5-3 |
|
|
’ (Comment Text Delimiter) .............................................................................. |
8-5-3 |
|
|
=, G, >, <, ≥, ≤ (Relational Operators) ........................................................... |
8-5-18 |
|
|
19990401
8-5-2 Command Reference
The following are conventions that are used in this section when describing the various commands.
Boldface Text ............... |
Actual commands and other items that always must be |
|
input are shown in boldface. |
{Curly Brackets} ........... |
Curly brackets are used to enclose a number of items, |
|
one of which must be selected when using a command. |
|
Do not input the curly brackets when inputting a com- |
|
mand. |
[Square Brackets] ........ |
Square brackets are used to enclose items that are |
|
optional. Do not input the square brackets when inputting |
|
a command. |
Numeric Expressions ... Numeric expressions (such as 10, 10 + 20, A) indicate constants, calculations, numeric constants, etc.
Alpha Characters ......... |
Alpha characters indicate literal strings (such as AB). |
kBasic Operation Commands
? (Input Command)
Function: Prompts for input of values for assignment to variables during program execution.
Syntax: ? → <variable name>, ”<prompt>” ? → <variable name>
Example: ? → A
Description:
•This command momentarily interrupts program execution and prompts for input of a value or expression for assignment to a variable. If you do not specify a prompt, execution of this command causes “?” to appear indicating the calculator is standing by for input. If a prompt is specified, “<prompt>?” appears to prompt input. Up to 255 bytes of text can be used for a prompt.
•Input in response to the input command must be a value or an expression, and the expression cannot be a multi-statement.
•You can specify a list name, matrix name, function memory (fn), graph (Yn), etc. as a variable name.
1999120104
8-5-3 Command Reference
^ (Output Command)
Function: Displays an intermediate result during program execution.
Description:
•This command momentarily interrupts program execution and displays alpha character text or the result of the calculation immediately before the command.
•The output command should be used at locations where you would normally press the w key during a manual calculation.
: (Multi-statement Command)
Function: Connects two statements for sequential execution without stopping.
Description:
•Unlike the output command (^), statements connected with the multi-statement command are executed non-stop.
•The multi-statement command can be used to link two calculation expressions or two commands.
•You can also use a carriage return indicated by _ in place of the multi-statement command.
_ (Carriage Return)
Function: Connects two statements for sequential execution without stopping.
Description:
•Operation of the carriage return is identical to that of the multi-statement command.
•You can create a blank line in a program by inputting a carriage return only. Using a carriage return in place of the multi-statement command makes the displayed program easier to read.
’ (Comment Text Delimiter)
Function: Indicates comment text inserted inside a program.
Description: Anything following the apostrophe is treated as non-executable comment text.
1999120104
8-5-4 Command Reference
kProgram Commands (COM)
If~Then~(Else~)IfEnd
Function: The Then-statement is executed only when the If-condition is true (non-zero). The Else-statement is executed when the If-condition is false (0). The IfEndstatement is always executed following either the Then-statement or Else-statement.
Syntax: |
|
|
|
|
|
|
|
|
|
|
|
|
|
If |
<condition> |
_ |
Then <statement> |
_ |
<statement> |
||||||||
: |
: |
||||||||||||
|
numeric expression |
^ |
|
|
|
|
^ |
|
|
|
|||
|
_ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_ |
|
|
|
|
_ |
|
|
||
|
: |
Else <statement> |
: |
<statement> |
: |
IfEnd |
|||||||
|
^ |
|
|
|
|
^ |
|
|
|
|
^ |
|
|
Parameters: condition, numeric expression
Description:
(1)If ~ Then ~ IfEnd
•When the condition is true, execution proceeds with the Then-statement and then continues with the statement following IfEnd.
•When the condition is false, execution jumps to the statement following IfEnd.
(2)If ~ Then ~ Else ~ IfEnd
•When the condition is true, execution proceeds with the Then-statement and then jumps to the statement following IfEnd.
•When the condition is false, execution jumps to the Else-statement and then continues with the statement following IfEnd.
For~To~(Step~)Next
Function: This command repeats everything between the For-statement and the Nextstatement. The starting value is assigned to the control variable with the first execution, and the value of the control variable is changed according to the step value with each execution. Execution continues until the value of the control variable exceeds the ending value.
Syntax: |
_ |
|
For <starting value> → <control variable name> To <ending value> |
Step <step value> |
: |
Next |
^ |
|
|
Parameters:
•control variable name: A to Z
•starting value: value or expression that produces a value (i.e. sin x, A, etc.)
•ending value: value or expression that produces a value (i.e. sin x, A, etc.)
•step value: numeric value (default: 1)
19990401