Programming HP Calculators/Introduction
This book is an unofficial guide to programming your HP calculator. It will teach you the basic commands mentioned in the official manual but will also include some other commands, such as easter eggs and glitches.
The fact that HP calculators are programmable means that they are not calculators but computers. Although the language used by the calculators is simple it is similar to many of the complex languages used on PCs, making it a great starting point for people who want to learn more about programming.
'Hello World' Example
1►L: DISP L; "Hello,": DISP 2; "World!": FREEZE:
This program basically does the following:
- Store 1 to the variable, 'L'
- On line 'L' (1) display 'Hello,'
- On Line 2 display 'World!'
- Freeze the calculator's display so that the text displayed doesn't disappear.
Type this example into a new program so you can see what it does.
BTW: 'Hello, World!' is a standard program for most programming tutorials and guides. It has no real significance that I know of.
Storing and Retrieving Variables
On HP calculators you can store numbers into variables. This is done with the '►' or '1►L: DISP L;' symbol, like in the example above. In the example above we store 1 in the variable, 'L'. This means that 'L=1".
On HP calculators there are only prescribed variables, see the variable reference to see them all. Because all variables are prescribed there is no need to declare them at the start of the program like in most languages. Most of the time the A...Z and θ are the only variables used in programs.
Program Commands are instructions for the calculator. A program can contain any number of commands. When your calculator reads a command it will take the appropriate action; however , sometimes we might want that action to be slightly different each time we call it. This is why we have arguments after the command seperated by a semicolon. Some commands have an unlimited number of arguments but most have somewhere between 0 and 8 arguments.
So that means that commands are formatted as:
COMMAND <arg1>; <arg2>; ... <arg#>
The arguments can be of various types. Sometimes they are numbers and sometimes they are strings (a collection of letters and symbols with quotation marks on each side). The 'DISP' command, for example, uses a number and a string for its arguments. It has the format:
DISP <line#>; <string>
The first argument is a number and the second argument is a string. This command basically tells the calculator to write 'string' on line 'line#'. If you want a more detailed description check the command reference.
Also, at the end of every command or variable asignment we need to put a colon so that the calculator knows that the command has ended.
Because it can be slow to type the commands and variables manually and they are easy to mis-spell you can select them from menus. These menus can be accessed by pressing the MATH button for commands and the VAR button for variables.