Home > HP > Calculator > HP 12c Owners Manual

HP 12c Owners Manual

    Download as PDF Print this page Share this page

    Have a look at the manual HP 12c Owners Manual online for free. It’s possible to download the document as PDF or print. UserManuals.tech offer 1114 HP manuals and user’s guides for free. Share the user manual or guide on Facebook, Twitter or Google+.

    							  Section 8: Programming Basics  91 
     
    File name: hp 12c_users guide_English_HDPMBF12E44  Page: 91 of 209   
    Printered Date: 2005/7/29    Dimension: 14.8 cm x 21 cm 
     
    Identifying Instructions in Program Lines 
    Each key on the hp 12c keyboard — except for the digit keys 0 through 9 — is 
    identified by a two-digit “keycode” that corresponds to the key’s position on the 
    keyboard. The first digit in the keycode is the number of the key row, counting 
    from row 1 at the top; the second digit is the number of the key in that row, 
    counting from 1 for the first key in the row through 9 for the ninth key in the row 
    and 0 for the tenth key in the row. The keycode for each digit key is simply the 
    digit on the key. Thus, when you keyed the instruction b
     into program memory, 
    the calculator displayed 
    04–      25 
    This indicates that the key for the instruction in program line 04 is in the second 
    row on the keyboard and is the fifth key in that row: the b
     key. When you keyed 
    the instruction +
     into program memory, the calculator displayed 
    07–      40 
    This indicates that the key for the instruction in program line 07 is in the fourth row 
    on the keyboard and is the tenth key in that row: the + 
    key. When you keyed the 
    digit 5 into program memory, the keycode displayed was only the digit 5
    . 
     
    Since keystroke sequences beginning with f
    , g
    , ?
    , :
    , and i
     are stored 
    in only one program line, the display of that line would show the keycodes for all 
    the keys in the keystroke sequence. 
     Instruction  Keycode 
     gÒ 
    nn-    43  26 
     ?=1 nn- 44 40  1 
     gi00 nn- 43,33  00  
    						
    							92  Section 8: Programming Basics 
     
     
    File name: hp 12c_users guide_English_HDPMBF12E44  Page: 92 of 209   
    Printered Date: 2005/7/29    Dimension: 14.8 cm x 21 cm 
     
    Displaying Program Lines 
    Pressing fs
     to set the calculator from Run mode to Program mode displays the 
    line number and keycode for the program line to which the calculator is currently 
    set. 
    Occasionally you’ll want to check several or all of the instructions stored in 
    program memory. The hp 12c enables you to review program instructions either 
    forward or backward through program memory: 
    z  Pressing Ê (single step) while the calculator is in Program mode advances 
    the calculator to the next line in program memory, then displays that line 
    number and the keycode of the instruction stored there. 
    z  Pressing gÜ (back step) while the calculator is in Program mode sets the 
    calculator back to the previous line in program memory, then displays that 
    line number and the keycode of the instruction stored there. 
    For example, to display the first two lines of the program now stored in program 
    memory, set the calculator to Program mode and press Ê
     twice: 
    Keystrokes Display   
    fs 
    00- Sets calculator to Program mode 
    and displays current line of 
    program memory   
    Ê 
    01-    36 Program line 01: \
     
    Ê 
    02-    2 Program line 02: digit 2. 
    Pressing gÜ
     does the reverse: 
    Keystrokes Display   
    gÜ 
    01-    36 Program line 01. 
    gÜ 
    00- Program line 00. 
    If either the Ê
     key or the Ü
     key is held down, the calculator displays all of the 
    lines in program memory. Press Ê
     again now, but this time hold it down until 
    program line 07 is displayed. 
    Keystrokes Display   
    Ê 
    01-    36 Program line 01 
     . 
    . 
    . . 
    . 
    . 
    (Release Ê) 
    07-    40 Program line 07  
    						
    							  Section 8: Programming Basics  93 
     
    File name: hp 12c_users guide_English_HDPMBF12E44  Page: 93 of 209   
    Printered Date: 2005/7/29    Dimension: 14.8 cm x 21 cm 
     
    Program line 07 contains the last instruction you keyed into program memory. 
    However, if you press Ê
     again, you’ll see that this is not the last line stored in 
    program memory: 
    Keystrokes Display   
    Ê 
    08- 43, 33   00 Program line 08 
    As you should now be able to tell from the keycodes displayed, the instruction in 
    program line 08 is gi
    00. 
    The 00 Instruction and Program Line 00 
    Whenever you run the program now stored in program memory, the calculator 
    executes the instruction in line 08 after executing the seven instructions you keyed 
    in. This i
    00 instruction — as its name implies — tells the calculator to “go to” 
    program line 00 and execute the instruction in that line. Although line 00 does not 
    contain a regular instruction, it does contain a “hidden” instruction that tells the 
    calculator to halt program execution. Thus, after each time the program is run, the 
    calculator automatically goes to program line 00 and halts, ready for you to key in 
    new data and run the program again. (The calculator is also automatically set to 
    program line 00 when you press fs
     to set the calculator from Program mode 
    to Run mode.) 
    The i
    00 instruction was already stored in line 08 — in fact, in all program 
    lines — before you keyed in the program. If no instructions have been keyed into 
    program memory, if Continuous Memory is reset, or if f
    CLEARÎ
     is pressed (in 
    Program mode), the instruction i
    00 is automatically stored in program lines 01 
    through 08. As you key each instruction into program memory, it replaces the 
    i
    00 instruction in that program line. 
    If your program should consist of exactly eight instructions, there would be no 
    i
    00 instructions remaining at the end of program memory. Nevertheless, after 
    such a program is executed the calculator automatically returns to program line 00 
    and halts, just as if there were a i
    00 instruction following the program. 
    If you key in more than eight instructions, program memory automatically expands 
    to accommodate the additional instructions.  
    						
    							94  Section 8: Programming Basics 
     
     
    File name: hp 12c_users guide_English_HDPMBF12E44  Page: 94 of 209   
    Printered Date: 2005/7/29    Dimension: 14.8 cm x 21 cm 
     
    Expanding Program Memory 
    If no instructions have been keyed into program memory, if Continuous Memory 
    has been reset, or if f
    CLEARÎ
     has been pressed (in Program mode), program 
    memory consists of 8 program lines, and there are 20 storage registers available 
    for storage of data. 
     
    As you key in a ninth instruction, storage register R
    .9 is automatically converted into 
    seven new lines of program memory. The instruction you key in is stored in 
    program line 09, and the instruction i
    00 is automatically stored in program 
    lines 10 through 15. 
      
    						
    							  Section 8: Programming Basics  95 
     
    File name: hp 12c_users guide_English_HDPMBF12E44  Page: 95 of 209   
    Printered Date: 2005/7/29    Dimension: 14.8 cm x 21 cm 
     
    Program memory is automatically expanded like this whenever another seven 
    instructions have been keyed into program memory — that is, when you key an 
    instruction into program line 16, 23, 30 etc. In each case, the additional program 
    lines made available are converted, seven lines at a time, from the last available 
    data storage register (whether or not data has been stored in that register; if it has, 
    it will be lost). Furthermore, the six new program lines (following the 16th, 23th 
    etc.) will each contain the instruction i
    00. 
    To determine at any time how many program lines (including those containing 
    i
    00) are currently in program memory and how many storage registers are 
    currently available for conversion to program lines or for data storage, press 
    gN
     (memory). The calculator will respond with a display like the following: 
     
    Up to 99 instructions can be stored in program memory. Doing so would require 
    the conversion of 13 data storage registers (because 99 = 8 + [13 × 7]), leaving 
    7 storage registers — R
    0 through R6 — available for data storage. 
    If you find yourself creating long programs, you should create your programs so 
    that they don’t use up program lines unnecessarily, since program memory is 
    limited to 99 program lines. One way to minimize program length is to replace 
    numbers consisting of more than just one digit — like the number 25 in lines 02 
    and 03 of the program keyed in above — by a :
     instruction, and then storing 
    the number in the designated storage register before running the program. In this 
    case, this would save one program line, since the :
     instruction requires only 
    one program line, not two as are required by the number 25. Of course, doing so 
    uses up data storage registers that you might want to save for other data. As in 
    many business and financial decisions, there is a trade off involved; here it is 
    between program lines and data storage registers. 
    Setting the Calculator to a Particular Program Line 
    There will be occasions when you’ll want to set the calculator directly to a 
    particular program line — such as when you’re storing a second program in 
    program memory or when you’re modifying an existing program. Although you 
    can set the calculator to any line by using Ç 
    as described above, you can do so 
    more quickly as follows: 
    z  With the calculator in Program mode, pressing gi. followed by two 
    digit keys sets the calculator to the program line specified by the digit keys, 
    and then displays that line number and the keycode of the instruction stored 
    there.  
    						
    							96  Section 8: Programming Basics 
     
     
    File name: hp 12c_users guide_English_HDPMBF12E44  Page: 96 of 209   
    Printered Date: 2005/7/29    Dimension: 14.8 cm x 21 cm 
     
    z  With the calculator in Run mode, pressing gi followed by two digit keys 
    sets the calculator to the program line specified by the digit keys. Since the 
    calculator is not in Program mode, the line number and keycode are not 
    displayed. 
    The decimal point is not necessary if the calculator is in Run mode, but it is 
    necessary if the calculator is in Program mode. 
    For example, assuming the calculator is still in Program mode, you can set it to 
    program line 00 as follows: 
    Keystrokes Display  
    gi.00 
    00- Program line 00 
    Executing a Program One Line at a Time 
    Pressing Ç
     repeatedly with the calculator in Program mode (as described earlier) 
    enables you to verify that the program you have stored is identical to the program 
    you wrote — that is, to verify that you have keyed the instructions in correctly. 
    However, this does not ensure that the program you wrote calculates the desired 
    results correctly: even programs created by the most experienced programmers 
    often do not work correctly when they are first written. 
    To help you verify that your program works correctly, you can execute the program 
    one line at a time, using the Ç
     key. Pressing Ç
     while the calculator is in Run 
    mode advances the calculator to the next line in program memory, then displays 
    that line’s number and the keycode of the instruction stored there, just as in 
    Program mode. In Run mode, however, when the Ç
     key is released the 
    instruction in the program line just displayed is executed and the display then 
    shows the result of executing that line. 
    For example, to execute the program stored in the calculator one line at a time:   
    Keystrokes Display  
    fs 
    124.25 Sets calculator to Run mode and 
    to line 00 in program memory. 
    (Display shown assumes results 
    remain from previous 
    calculation.) 
    625 
    625. Keys in price of typewriter. 
    Ç 
    01-    36Program line 01: \
     
     
    625.00 Result of executing program line 
    01. 
    Ç 
    02-    2Program line 02: 2.  
    						
    							  Section 8: Programming Basics  97 
     
    File name: hp 12c_users guide_English_HDPMBF12E44  Page: 97 of 209   
    Printered Date: 2005/7/29    Dimension: 14.8 cm x 21 cm 
     
    Keystrokes Display  
     
    2. Result of executing program line 
    02. 
    Ç 
    03-    5Program line 03: 5. 
     
    25. Result of executing program line 
    03. 
    Ç 
    04-    25Program line 04: b
     
     
    156.25 Result of executing program line 
    04. 
    Ç 
    05-    30Program line 05: -
     
     
    468.75 Result of executing program line 
    05. 
    Ç 
    06-    5Program line 06: 5 
     
    5. Result of executing program line 
    06. 
    Ç 
    07-    40Program line 07: +
     
     
    473.75 Result of executing program line 
    07 (the last line of the program). 
    Pressing gÜ
     while the calculator is in Run mode sets the calculator to the 
    previous line in program memory, then displays that line’s number and the 
    keycode of the instruction stored there, just as in Program mode. In Run mode, 
    however, when the Ü
     key is released the display again shows the same number 
    as it did before gÜ
     was pressed: no instruction in program memory is 
    executed. 
    Interrupting Program Execution 
    Occasionally you’ll want a program to stop executing so that you can see an 
    intermediate result or enter new data. The hp 12c provides two functions for doing 
    so: u
     (pause) and t
     (run/stop). 
    Pausing During Program Execution 
    When a running program executes a u
     instruction, program execution halts for 
    about 1 second, then resumes. During the pause, the calculator displays the last 
    result calculated before the u
     instruction was executed. 
    If you press any key during a pause, program execution is halted indefinitely. To 
    resume program execution at the program line following that containing the u
     
    instruction, press t
    .  
    						
    							98  Section 8: Programming Basics 
     
     
    File name: hp 12c_users guide_English_HDPMBF12E44  Page: 98 of 209   
    Printered Date: 2005/7/29    Dimension: 14.8 cm x 21 cm 
     
    Example:
     Create a program that calculates the entries in the AMOUNT, TAX, 
    and TOTAL columns for each item on the jewelry distributor’s invoice shown on the 
    next page, and also calculates the total in each of these columns for all items on 
    the invoice. Assume the sales tax is 6
    3/4%. 
    To conserve lines of program memory, instead of keying in the tax rate before the 
    b
     instruction we’ll store it in register R
    0 and recall it before the b
     instruction. 
    Before storing the program in program memory, we’ll calculate the required 
    amounts for the first item on the invoice manually. The keystroke sequence will use 
    storage register arithmetic (described on page 24) in registers R
    1, R2, and R3 to 
    calculate the column sums. Since these registers are cleared when f
    CLEAR²
     is 
    pressed, we’ll press those keys before beginning the manual calculation — and 
    also later, before running the program — to ensure that the column sums are 
    “initialized” to zero. (Pressing f
    CLEARH
     would clear registers R
    1 through R3, 
    but would also clear R
    0, which will contain the tax rate.) 
      
    						
    							  Section 8: Programming Basics  99 
     
    File name: hp 12c_users guide_English_HDPMBF12E44  Page: 99 of 209   
    Printered Date: 2005/7/29    Dimension: 14.8 cm x 21 cm 
     
    Pressing the gu
     keys is not necessary when we do the calculations manually, 
    since in Run mode the result of every intermediate calculation is displayed 
    automatically; but we’ll include u
     instructions in the program so that the 
    intermediate results AMOUNT and TAX are automatically displayed when the 
    program is executed. 
    Keystrokes Display  
    6.75?0 
    6.75 Stores tax rate in R0. 
    fCLEAR² 
    0.00 Clears the registers in R1 through 
    R
    6. 
    13 
    13. Keys in quantity of item. 
    \ 
    13.00 Separates quantity of item from 
    cost of item to be keyed in next. 
    68.5 
    68.5 Keys in cost of item. 
    § 
    890.50 AMOUNT. 
    ?+1 
    890.50 Adds AMOUNT to sum of 
    AMOUNT entries in register R
    1. 
    :0 
    6.75 Recalls tax rate to display. 
    b 
    60.11 TAX. 
    ?+2 
    60.11 Adds TAX to sum of TAX entries 
    in register R
    2. 
    + 
    950.61 TOTAL. 
    ?+3 
    950.61 Adds TOTAL to sum of TOTAL 
    entries in register R
    3. 
    Now, we’ll store the program in program memory. Do not key in the quantity and 
    cost of each item; these numbers will vary each time the program is run. 
    Keystrokes Display  
    fs 
    00- Sets calculator to Program 
    mode. 
    fCLEARÎ 
    00- Clears program memory. 
    § 
    01-    20 
    gu 
    02-  43  31Pauses to display AMOUNT. 
    ?+1 
    03- 44 40   1 
    :0 
    04-  45  0 
    b 
    05-    25  
    						
    							100  Section 8: Programming Basics 
     
     
    File name: hp 12c_users guide_English_HDPMBF12E44  Page: 100 of 209   
    Printered Date: 2005/7/29    Dimension: 14.8 cm x 21 cm 
     
    Keystrokes Display  
    gu 
    06-  43  31Pauses to display TAX. 
    ?+2 
    07- 44 40   2 
    + 
    08-    40 
    ?+3 
    09- 44 40   3 
    Now, to run the program: 
    Keystrokes   Display   
    fs 
    950.61 Sets calculator to Run mode. 
    fCLEAR² 
    0.00 Clears registers R1– R6. 
    6.75?0 
     Stores tax rate. 
    13\68.5 
    68.5 Enters quantity and price of first 
    item on invoice. 
    t 
    890.50 AMOUNT for first item. 
     
    60.11 TAX for first item. 
     
    950.61 TOTAL for first item. 
    18\72.9 
    72.9 Enters quantity and price of 
    second item on invoice. 
    t 
    1,312.20 AMOUNT for second item. 
     
    88.57 TAX for second item. 
     
    1,400.77 TOTAL for second item. 
    24\85 
    85. Enters quantity and price of third 
    item on invoice. 
    t 
    2,040.00 AMOUNT for third item. 
     
    137.70 TAX for third item. 
     
    2,177.70 TOTAL for third item. 
    5\345 
    345. Enters quantity and price of 
    fourth item on invoice. 
    t 
    1,725.00 AMOUNT for fourth item. 
     
    116.44 TAX for fourth item. 
     
    1,841.44 TOTAL for fourth item. 
    :1 
    5,967.70 Sum of AMOUNT column. 
    :2 
    402.82 Sum of TAX column. 
    :3 
    6,370.52 Sum of TOTAL column.  
    						
    All HP manuals Comments (0)

    Related Manuals for HP 12c Owners Manual