circuitcellar.com
Magazine Support   Digital Library   Products & Services   Suppliers Directory 
 
 





 

Four Functions and Beyond
Tips for Designing an RPN Calculator


RPN LANGUAGE

If you want to build a device that’s similar to one already on the market, you should use the best example possible. The HP-45 was the best example I could find. After reading over one of my old HP-45 application handbooks, I decided to try to emulate some of its functions. I used my four-function calculator’s hardware and wrote an application that allows you to enter a mathematical expression with HP’s unique RPN.

The HP-45 handles complicated expressions with only a four-level stack and nine registers, which eliminates the need to handle nested parentheses in complicated mathematical expressions—one of the hallmarks of RPN. To evaluate a complicated expression, start from the innermost set of parentheses and work outward (all the while pushing, popping, or manipulating values from the stack). The HP stack manipulations are similar to the Forth computer language, which is also stack-based, although the stack can be greater than four levels.

Figure 4 shows some of the register and stack operations available to the HP-45 that I emulated using the current hardware and firmware. The remaining math functions will be modeled in the RPN calculator using the keypad. An optional separate push-button switch is designated the Gold function key, which is akin to HP-45’s gold function key. The secondary functions are only accessible when you press the push button; otherwise they are disabled.

The RPN calculator expressions listed in Table 4 are available when X and Y are the two floating-point operands and Z is the result shown on the LED, LCD, PC, or laptop display. The substitute characters “A,” “D,” “#,” and “×” must be used with the 4 × 4 keypad. The ASCII characters “+,” “/,” “E,” and “.” must be used with the serial interface. Exponential notation using the “E” character is not supported at this time via the keypad or serial interface, because a 4 × 4 keypad doesn’t have enough keys for the function. Let’s look at an example.

To evaluate 4.5 + 2.2 = 6.7 using the serial interface, enter the following keystrokes:

4.5 # 2.2 +                  

 Note that the answer, 6.7, should appear on the LED, LCD, and the host PC display.

The basic stack operations have remained the same with the new generation of HP RPN calculators, including the programmable ones. More information on HP calculators, including the process of evaluating expressions and manipulating the stack, is readily available in the user manuals for the new calculators.

My RPN calculator application (hp45.c) doesn’t completely emulate the HP-45, because it was my intention to show only some of the basic stack operations and calculator functions. Again, to carry out a complete emulation, a more powerful microcontroller or a more highly optimized implementation in assembly language may be required.

In addition to modifying the RPN firmware to emulate programmable RPN calculators similar the to the HP-65, you can modify it to take advantage of EEPROM using the on-board 24LC256 serial EEPROM and the PIC’s I2C interface. The PIC’s SRAM can be used for the RPN stack, and the EEPROM can be used to store tokenized RPN programs.

Developing an emulator for the programmable HP-65 calculator emulator is an easier task than developing for the TI-59 algebraic operating system (AOS) calculator from Texas Instruments. The firmware changes for the RPN calculator are probably the easiest to implement of the aforementioned calculator languages, which can handle complicated mathematical expressions without getting too involved in complex compiler generation tools. In addition, an AOS emulator would require a more powerful microcontroller or a highly optimized PIC assembly because the PIC18F452 is limited in SRAM and flash memory.