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





 

Four Functions and Beyond
Tips for Designing an RPN Calculator


by Daniel Ramirez

Last month, Daniel presented you with a step-by-step guide to building a four-function calculator. Now he’s back with several tips on how move beyond the basic functions. Follow his advice, and you’ll soon have your own customized RPN calculator.


Editor's note: To download Daniel Ramirez's "Build Your Own Four-Function Calculator" (Issue 157, August 2003), go to http://www.circuitcellar.com/magazine/157toc.htm.

Start Display ModesFirmware Calculator Modes RPN Language AOS Serial Interface Sources and PDF

“Effective April 1, 2003 Hitachi Semiconductor America has merged with the system LSI operations of Mitsubishi Electric U.S. and created Renesas Technology America, Inc.”

Last month, I led you through the process of building an electronic calculator by way of simple wire-wrap construction techniques (“Build a Four-Function Calculator,” Circuit Cellar 157). Now, I’ll describe the firmware you’ll need to give the calculator the ability to perform scientific and trigonometric functions. This month, I’ll present an improved schematic that incorporates common cathode LED displays rather than common anode LEDs. If you use common cathode LEDs, you don’t have to spend as much time making the connections for the circuit. Common cathodes LEDs worked well in some of my other projects (e.g., displays for a temperature sensor and sonar ranger).

This project requires both hardware and software expertise in relatively equal amounts because a calculator is, after all, related to the digital computer. It’s possible to develop a completely digital design using FPGA and VLSI techniques or a software-based virtual calculator, such as the one found in Windows. The former may be too advanced for some designers, while the latter doesn’t reward the hobbyist with the same feeling of accomplishment as actually building a working calculator.

Figure 1 is a diagram of my complete reverse Polish notation (RPN) calculator. I still have not completed all of the functions. Refer to my Circuit Cellar 157 article for a more detailed schematic.

(Click here to enlarge)

Figure 1—As you study the RPN calculator’s electronics, remember that some of the blocks haven’t been completed.

The differences between the four-function calculator and the RPN calculator are mostly in the firmware. Figure 2 shows the new LED driver schematic that’s used for driving common cathode LED digits. This version is simpler than the previous common anode LED display. The additional 24LC256 serial EEPROM uses the I2C interface, which may come in handy for future growth applications such as a Forth interpreter or a complete AOS-based programmable calculator.

(Click here to enlarge)

Figure 2—You can use this schematic to assemble the calculator’s optional common cathode numeric LED display driver circuit. Parts placement and board fabrication techniques are not crucial.

HARDWARE DEVELOPMENT TOOLS

The ICD2 is Microchip’s best deal, unless you count its inexpensive microcontroller family of products. You can have complete in-circuit debugging (ICD) and in-circuit serial programming (ICSP) for approximately $150, as compared to the more expensive ICE-2000, which costs nearly $2500.

The PICDEMO2 board is also available in combination with the ICD2. This would give you a complete development environment, including a PIC18F452 microcontroller, a serial port, and an LCD for approximately $230. Of course, only one breakpoint and a limited trace capability are provided with the ICD2, but it allows for a single step through the code, the ability to watch variables, the capacity to display all the microcontroller’s registers, and memory. I found these features invaluable. I no longer had to carefully place printf statements throughout my application during debugging and testing to send debug output to the serial port for display on a laptop with HyperTerminal. In addition, I increased my productivity. You can purchase the boards directly from Microchip or Digikey.

Photo 1 shows the ICD2 debugger running the RPN calculator application on the PICDEMO2 board. Notice some of the HP-45 variables shown in the Watch window. The result is in the X register, just like the real HP-45.

(Click here to enlarge)

Photo 1—I chose the MPLAB V. 6.20 to debug the RPN calculator’s firmware using a Microchip PICDEMO 2 board and an ICD2 debugger. The contents of the RPN stack are shown prominently in the Watch window.

You may find it desirable to download the USB drivers and MPLAB 6.20 first. Running the IDE2 in Serial mode is time-consuming. In addition, if you want to power the PICDEMO2 board from the ICD2, the current requirements should be kept to a minimum; otherwise, a separate 5-V power supply is necessary. You could also use another Microchip wall power supply. (For some reason, Microchip only ships the combined ICD2 and PICDEMO2 board with one power supply.)

The PICDEMO2 board already has a PIC18F452, serial port, and LCD, which are the calculator’s main ingredients. I’ve been able to run most of my calculator software applications on the board. The only missing components are a keypad and LED displays. As an alternative, you can use the serial port to redirect the keypad and calculator’s output to HyperTerminal on a PC or laptop. I haven’t figured out how to add the missing components to the PICDEMO2 board, because that would require soldering the board, which may void the warranty.