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





 

Four Functions and Beyond
Tips for Designing an RPN Calculator


DISPLAY MODES

In addition to building a calculator or floating-point coprocessor, you can construct a smart LCD or LED display module that functions like Scott Edwards Electronics’s popular serial LCD. In this mode of operation, the calculator uses the PIC’s USART for user output. It polls port B’s I/O lines to detect keystrokes, and builds floating-point numbers and expressions from them. Note that it is primarily used during display via an LCD or debugging and acts as a coprocessor, although the USART could provide additional storage capability when used in conjunction with a PC or laptop host.

Floating-point and integer values may be displayed on both the LED and LCD devices, but alphanumeric values—with the exception of “H,” “E,” “L,” and “P”—can be shown only on LCD devices. Advanced matrix LEDs and LCDs are not currently supported, but you can add them with additional hardware and firmware development.

SOFTWARE DEVELOPMENT

I used MPLAB 6.20 with USB support for the ICD2 to debug the application. I recommend the USB version because the serial RS-232 version of the ICD2 is too slow. In addition, I used Microchip’s latest PIC18C demo compiler and 3.0 linker, which were included in the CD-ROM. The tools were useful for finding bugs, particularly during the development phase, which took half the time it would have taken using other methods. The project-based development methodology supported by these tools worked well within the structure I had chosen for my application.

Microchip’s revamped integrated development environment (IDE) is used in MPLAB, and it is a big improvement over the previous version, which was not as easy to use (see Photo 2). The only problem I encountered had to do with saving the PIC programming configuration bits, which occasionally required resaving the values when I imported the application hex file.

(Click here to enlarge)

Photo 2—The RPN calculator’s project files open as separate windows. The C files that make up the RPN calculator are in the project window.

The PIC18C worked well after I implemented a few bug fixes. The code seemed tighter. Note that the compiler now supports the PIC18F452  used in this application. Still missing from the compiler are the math library functions in math.h and the I/O functions in stdio.h library. You may question why I didn’t use a PIC compiler that includes these library functions. Basically, I needed a demo C compiler capable of supporting the PIC18Fxxx devices along with all the PIC’s internal features. In addition, I’ve been using the compiler for a while, so I’m used to it. Other vendors such as HI-TECH and CCS provide these libraries with their PIC C compilers, although their demos are limited to using the low-end PICs, such as the PIC16F84, which cannot handle this application unless it is rewritten in highly optimized assembly language. In addition, I was able to learn more about implementing math functions in small microcontrollers by using the information in Jack Crenshaw’s book, Math Toolkit for Real-Time Programming.