Four
Functions and Beyond
Tips
for Designing an RPN Calculator
SERIAL
INTERFACE
The
serial user interface (UI) is driven serially by the
PIC’s USART to communicate with a host PC or laptop
using HypeTerminal, Visual Basic, or Visual C++. The
UI interface was initially developed for debugging and
testing calculator functions, including the floating-point
I/O routines. You may also use it to communicate with
a master Stamp, PIC, or other any other microcontroller
that supports a serial interface.
The
UI has a menu that accepts simple ASCII commands, and
it’s always available by default to the RPN calculator.
Enter the calculator commands and operands to evaluate
floating-point expressions. Again, the results are displayed
on the PC or laptop screen.
The
PC or laptop display and keyboard provide the I/O when
connected to the serial port. Otherwise, the RPN calculator’s
keypad and LCD/LED display provide all of the I/O required,
allowing you to enter expressions and display the results.
If the PICDEMO2’s LCD is used, then the PC or laptop’s
keyboard is implmented for entering mathematical expressions.
Most
of the components used in a serial communications terminal
are included in the four-function calculator’s application.
It’s easy to add the missing functions, including a
serial communications ring buffer, in an effort to store
the serial input or scan the keypad for keystrokes.
The data may be sent to the LED or LCD for display.
In
addition, ANSI or VT-100 control sequences can be interpreted
to position the characters on multiline displays. This
is, in effect, a portable terminal, which you can use
with other embedded projects with only a serial interface.
GET
STARTED
In
this article, I described the firmware you’ll need to
make the four-function calculator perform useful mathematical
functions (i.e., the basic four, scientific, and trigonometric
functions). In addition, I covered the topic of conversion
functions for unit conversions, or base conversions,
and the coprocessor modes that provide added functionality
to microcontrollers, which either do not provide floating
point or are too busy performing high-level control
functions. I included a complete functional description
of the currently available functions. You are now familiar
with the various calculator languages for emulating
popular commercial calculators, as well as the Forth
and Basic languages.
The
RPN calculator, although extremely educational, is not
particularly useful for small robotics projects. On
the other hand, the coprocessor mode that forms the
core of the four-function calculator is an ideal companion
for your selected microcontroller (whether you use a
PIC, Stamp, or AVR).
In
addition to the RPN calculator, you can also use the
firmware to build your own TI-59 AOS-based programmable
calculator emulator. To do so, use a simple recursive
descent calculator algorithm written in Pascal. For
more information on recursive descent algorithms, I
once again recommend Algorithms + Data Structures
= Programs.