hp-support-head-portlet

Actions
Loading...

HP Customer Support

hp-contact-secondary-navigation-portlet

Actions
Loading...

hp-share-print-widget-portlet

Actions
Loading...

hp-concentra-wrapper-portlet

Actions
Loading...

HP 20s Calculator - Programming

Introduction
A program allows repeat calculations without repeating keystrokes. To enter a program, use the same keystrokes as normally used manually, but press the keystrokes when in Program mode. The calculator will then repeat them on command.
The programming features on the HP 20s may be used in two ways. Write original programs by having the calculator repeat keystrokes or run any one of six built-in programs.
Any program, regardless of whether it is manually entered or loaded from the built-in program library, can be run and edited. This document explains how to do original programming and editing.
Before programming concepts and commands are explained in detail, try this quick example. Start by writing out the formula, then solve the problem from the keyboard.
Calculator symbol key
The procedures in this document use the following text to represent symbol keys:
Key
Description
Text Representation
Right shift key
RS
Left-shift key
LS
Move cursor left
cursor-left
Move cursor right
cursor-right
Move cursor up
cursor-up
Move cursor down
cursor-down
Backspace/clear
backspace
Divide
divide
pi
pi
A simple programming example
To find the cross-sectional area of a pipe with a diameter of 5 inches, use the formula in Figure 1.
Figure : Simple program formula
Before doing the calculation, rearrange the equation in the order in Figure 2.
Figure : Rearranged formula
Enter 5 in the display and press LS, x2, x, RS, pi, divide, 4, then =
The result should be 19.6350 square inches.
In order to find the area of many different pipes, rather than repeat the keystrokes each time (varying only the 5 for the different diameters), put the repeatable keystrokes into a program that would look like this:
01
2
02
X
03
04
05
4
06
=
This program assumes that the value for the diameter is in the display when the program starts to run. It calculates and displays the area. To enter this program into program memory, press the following keys. (Do not worry about the numbers that appear in the display - they are called keycodes and are explained later.) If a mistake occurs while typing a line, press backspace to erase the line, then type it over.
Keys
Display
Description
Press LS, then PRGM
Enters Program mode
Press RS, then CLPRGM
00-
Clears any previously stored programs
Press LS, then x2
01- 51 11
Enters the keystrokes that create the program
Press x
02 55
Press RS, then pi
03- 61 22
Press divide
04- 45
Press 4
05- 4
Press =
06- 74
Press LS, then PRGM
Exits Program mode
Now try running this program to find the area of a pipe with a diameter of 5 inches.
Keys
Display
Description
Press C
0.0000
Clears the display
Press LS, GTO, [.], then [.]
0.0000
Goes to the first line of the program
Press 5, then R/S
19.6350
The answer
Creating programs
The steps to create programs are:
  1. Enter Program mode.
  2. Enter the repeatable keystrokes.
  3. Exit Program mode.
  4. Run the program.
The pipe area program example above will continue to be used to illustrate programming concepts. The numbers that appear in the display as programming is being entered are line numbers and keycodes.
  • Line Numbers: Line numbers appear left-justified in the display as a program is entered. The numbers, 00 through 99, are followed by a dash. The dash separates the line numbers from keycodes.
  • Keycodes: The numbers to the right of the line number are called keycodes. A keycode indicates which key was pressed. The first digit indicates which row on the keyboard the key is in. The second digit indicates which column the key is in. A line contains one or more keycodes that together represent a single operation. Labels and number keys do not appear as keycodes, but instead as A through F or 0 through 9.
Checksum
After a program is entered, check to see if the keystrokes are entered correctly by comparing the checksum listed in this document to the checksum created by the program. The checksum is a unique hexadecimal value assigned to the specific keystrokes entered. To view the checksum, press and hold LS+SHOW for a moment while in Program mode. The checksums for the examples in this document are valid if there is only one program in memory. The checksum for the pipe area program example is 9Ad7.
Program boundaries
In order to store more than one program in the HP 20s calculator, the program needs boundaries - a label to mark its beginning and a return to mark its end.
Program labels
Programs and segments of programs (called routines) start with a label that acts as a name. Use a label to separate programs any time there is more than one program in memory. The keystrokes to create a label are RS, then LBL, followed by A through F or 0 through 9. A label is used to execute a specific program or routine.
When the XEQ label is pressed, the program pointer moves to the specified label and begins execution. (The program pointer is an internal pointer that marks the line that is displayed while in Program mode.) All of memory is searched for the specified label, starting at the program pointer. If no label is found, the message "Error - LbL" is displayed.
Return
Programs end with a return (RS, RTN) instruction. When a program finishes running, the RTN instruction returns the program pointer to line 00. If the last line of the program is not a RTN instruction, the program pointer automatically returns to line 00. The keystrokes are RS, then RTN.
Entering programs
Pressing LS, then PRGM toggles the calculator into and out of Program mode (PRGM annunciator on). While the HP-20s is in Program mode, keystrokes are stored as program lines. The calculator has enough memory for 99 program lines. Each function and each digit of a number occupy one program line.
To enter a program into memory
  1. Press LS, then PRGM to enter Program mode. The PRGM annunciator appears in the display.
  2. Press LS, GTO, [.], then [.] to display line 00. This sets the program pointer to line without affecting other programs.
    If no other programs that might be in memory are needed, clear program memory by pressing RS, then CLPRGM. This sets the program pointer to line 00 since there are no other lines to display.
  3. To start entering the program, press RS, then LBL followed by the label to assign; A through F or 0 through 9.
  4. To enter program instructions, press the same keys as those used to perform the operation manually.
  5. End the program with a return instruction by pressing RS, then RTN
  6. Press LS, then PRGM to exit Program mode.
Data input
There are many ways to supply a program with data. Here are two ways to supply data to a program that expects one data item:
  • Enter the number in the display before running the program.
  • Store the number into a register before running the program, then recall it from within the program.
Here are two ways to supply data to a program that expects data items:
  • Enter data in the display before running the program by using number1 , INPUT, number2. The program can store number2 then press LS, followed by SWAP to access number1
  • Store both items in registers before running the program, then recall them from within the program.
Example of entering a program
This example clears the pipe area program and enters a new version of the program that includes a label and a return instruction. (See Clearing Programs below for instructions on clearing programs without clearing all of the program memory.) To correct a mistake during entry, press backspace to delete the current program line, then re-enter it correctly.
Keys
Display
Description
Press LS, then PRGM
Enters Program mode (PRGM annunciator on)
Press RS, then CLPRGM
00-
Clears program memory
Press RS, LBL, then A
01- 61 41 A
Labels this program routine "A"
Press LS, then x2
02- 51 11
Enters the program lines
Press x
03- 55
Press RS, then pi
04 61 22
Press divide
05- 45
Press 4
06- 4
Press =
07- 74
Press RS, then RTN
08- 61 26
Ends the program
Hold LS and SHOW
CF08
Checksum (see Checksum above)
Press LS, then PRGM
Exit Program mode (PRGM annunciator off)
Positioning the program pointer
Program memory starts at line 00. The list of program lines is circular, so a program pointer may be wrapped from the bottom to the top. There are several ways to move the program pointer to view different lines.
Whether in program mode or not:
  • Press LS, GTO, [.], then [.] to move to line 00.
  • Press LS, GTO, [.], then line number to move to a specified line.
  • Press LS, then cursor-up or LS, then cursor-down to move one line at a time.
  • Hold LS and press cursor-up or cursor-down to move up or down.
When in Program mode:
  • Press LS, then cursor-up or LS, then cursor-down to move up or down rapidly.
When not in Program mode:
  • Press LS, then GTO label to move to a specified label.
Running programs
There are two ways to run a program:
  • Use XEQ
  • Use GTO and R/S (Run/Stop)
The PRGM annunciator blinks on and off, and the message "running" appears in the display while the program is running.
Starting programs with XEQ
To execute a program using XEQ:
  1. Enter data required by the program, if necessary.
  2. Press XEQ, then LBL
  3. To display the line where execution will begin, hold down LBL after pressing XEQ. The program starts to run when LBL is released.
Example of running a program
Run the program labeled A to find the areas of three different pipes with diameters of 5, 2.5, and 2 pi. Remember to enter the diameter before executing label A.
Keys
Display
Description
Press 5, XEQ, then A
19.6350
Enters the diameter, then starts program A. The resulting area is displayed.
Press 2.5, XEQ, then A
4.9087
Area of second pipe.
Press 2, x, RS, then pi
3.1416
Diameter of third pipe.
Press =
6.2832
Area of third pipe.
Press XEQ, then A
31.0063
Starting programs with GTO and R/S
To execute a program using GTO and R/S:
  1. Use GTO to position the program pointer at the desired beginning point (see Positioning the Program Pointer) above.
  2. Enter data required by the program, if necessary.
  3. Press R/S. Holding down R/S will display the line where execution will begin. The program starts to run when R/S is released.
Stopping programs
When a program is running, stop it by pressing R/S or C
Programming a stop
Pressing R/S while in Program mode inserts a STOP instruction. This halts a running program until R/S is pressed again. To stop a program to enter data, use R/S rather than RTN to end a program. When the program halts, the program pointer will not return to the top of the program.
Error stops
If an error occurs while a program is running, program execution halts at the point the error occurred, and an error message is displayed. (There is a list of error messages and conditions on page 122). Press C or backspace to clear the display. To see the program line containing the error-causing instruction, press LS, then PRGM
Clearing programs
The calculator must be in Program mode (the PRGM annunciator must be on) to clear programs. Press RS, then CLPRGM to clear all programs from memory.
To clear a specific program, delete each line individually. Position the pointer at the last line of the program to delete and press backspace repeatedly.
Editing programs
A program can be modified by inserting and deleting program lines. Even if a program line requires only a minor change, delete the old line and insert a new one.
Deleting program lines
  1. Enter Program mode.
  2. Position the pointer at the desired starting point. (If deleting more than one consecutive program line, start with the last line in the group).
  3. Delete the line to change by pressing backspace. Succeeding lines are automatically renumbered.
  4. To exit Program mode, press LS, then PRGM
For example, to delete lines 05 through 08, first display line 08, then press backspace four times. Subsequent program lines are moved up and automatically renumbered.
Inserting program lines
  1. Enter Program mode.
  2. Position the pointer to the line before the desired point for adding lines.
  3. Enter the new lines. They are inserted after the displayed line. Succeeding lines are automatically renumbered.
  4. To exit Program mode, press LS, then PRGM
For example, to insert several new lines between lines 04 and 05 of a program, first display line 04, then enter the instructions. Subsequent program lines, starting with the original line 05, are moved down and renumbered accordingly.
Stepping through programs
Programs can be tested by stepping through them. The program executes one line at a time while stepping through it. The result is displayed after each program line is executed, so the progress of the calculations can be verified. To execute a program one line at a time:
  1. Exit Program mode.
  2. Position the pointer at the desired starting point.
  3. Enter data in the display, if necessary.
  4. Press LS, then press and hold cursor-down. This displays the current program line. The line is executed when cursor-down is released. The result of that execution is then displayed, and the program pointer moves to the next line.
  5. Repeat step 4 until an error is discovered or the end of the program is reached.
To move to the preceding line, press LS, then cursor-up. No execution occurs.
Example of stepping through a program:
Step through the execution of the program labeled A. Use a diameter of 5 for the test data. Check that the PRGM annunciator is off before beginning.
Keys
Display
Description
Press LS, GTO, then A
Moves program pointer to label A
Press 5
5_
Enters 5 in the display
Press and hold LS+cursor-down
Release
01- 61 41 A
5.0000
Label A
Press and hold LS+cursor-down
Release
02- 51 11
25.0000
Squares input
Press and hold LS+cursor-down
Release
03- 55
25.0000
Multiplies 25 by ...
Press and hold LS+cursor-down
Release
04- 61 22
3.1416
...
Press and hold LS+cursor-down
Release
05- 45
78.5398
Calculates intermediate result
Press and hold LS+cursor-down
Release
  1. 4
4_
... 4
Press and hold LS+cursor-down
Release
  1. 74
19.6350
... =
Press and hold LS+cursor-down
Release
  1. 61 26
19.6350
End of program. Result is correct

hp-feedback-input-portlet

Actions
Loading...

hp-online-communities-portlet

Actions
Loading...

Ask the community!


Support Forum

Support Forum

Join the conversation! Find Solutions, ask questions, and share advice with other HP product owners. Visit now


hp-feedback-banner-portlet

Actions
Loading...

hp-country-locator-portlet

Actions
Loading...
Country: Flag United States

hp-detect-load-my-device-portlet

Actions
Loading...