Lupine Systems Presents...Part Two of the Series
Build Your Own Microcontroller Calculator
THIS MONTH:   Build a Floating Point LCD/VFD Handheld Calculator
by Spike Tsasmali, Lupine Systems

Build Your Own Floating Point LCD/VFD Handheld Calculator

Beginner Project Difficulty=2 Howls

Introduction

In last month's article I explained how to build a basic LED fixed-point calculator. This month I will expand upon the basic four function fixed-point design, upgrading the calculator to include an alpha-numeric LCD or VFD display, floating-point decimal feature and a nice smooth surface tactile keyboard.

Adding decimal functions makes the calculator much more useful and allows for the addition of more advanced math functions. However, adding the decimal is no simple task, at least not in the software. The upgrade to the LCD/VFD display module greatly simplifies the display section and makes it so that the entire project can be easily fit into a small handheld form.

By using surface-mount components the design can also be miniaturized. To keep the project from becoming too difficult for the beginner experimenter, I have built the project around a PCB a bit over 3" x 5" in size, but the overall design can be reduced to a much smaller footprint with a bit of re-drafting of the PCB.

Since the size of the calculator has been drastically reduced, it would make sense to build this model portable and battery-powered. But since most PIC microcontrollers as well as LCD and VFD display modules operate at 5 volts, this poses a problem with batteries. It is easy enough to get 5 volts from four size "AAA" batteries by simply connecting them to the circuit through a series diode to drop the voltage by 1 volt or so, but then you would have to provide for the space for four batteries. This problem has been solved by using a step-up regulator. With the step-up regulator the entire calculator can be powered from a single "AAA" cell. This project provides for using two "AAA" cells for longevity but you could use only one.

Engineering a Floating-Point Calculator





Last month I discussed how to design the basic four-function calculator. The only differences in the engineering design between this month's project and last month's project are the upgrades to the display, math functions and power source.

LCD and VFD Display Modules

Although this month's project was originally designed around an LCD display module, there are other types of display modules that will work in place of the LCD. One type of module that makes an excellent display for a calculator is a VFD or "Vacuum Fluorescent Display." VFD modules communicate with the microcontroller exactly the same way as do the LCD modules so there is no software difference. The advantage VFD has over LCD is viewing angle and legibility in dark environments. The bright white-blue display can also be filtered to appear just about any color you wish using a colored piece of filter plastic (you can use theactrical lighting "gel" strips as an inexpensive filter to color VFD displays).


Display Modules. On the left, a typical LCD module. On the right, a typical VFD module.

Most of these modules use the Hitachi 44780 LCD display controller chip or equivalent. Since most displays use the same controller, there is no need to change the software for different types of displays. The 44780 communicates with the microcontroller via an 8-bit data bus and two control signal lines. The VFD display also uses the same controller type with the same command structure and is fully interchangeable with the LCD display.

Most LCD display modules are transflective, meaning that they require an external light source shining on them in order to read the display. There are some however that are "transmissive", which require a "backlight". Others are a mixture of both, where you can use a backlight when it is dark and use ambient light when available. This project does not provide for powering a backlit display but if the display you choose is LED backlit then you can pick up the 3v you need for the LED backlight from the 3v source on the PC board using two short jumper wires.

VFD displays are already lit up, so there is no need for backlight. But VFD displays cannot operate without a high voltage source (the high voltage in this case is only 60 volts or so, depending on the display size). Again, most VFD displays have a small "inverter" built-on to the control PCB so you do not need to provide this voltage; the display "creates" it's own from the 5 volt supply. But beware, there are some that require external sourcing of the display voltage as well as the 1.5v filament voltage. If you choose to use a VFD module, be sure it has all of the power supplies built-in. This will save you a lot of frustration in the end.

Building the Floating-Point Calculator

Fig. 1 shows a block diagram of the Floating-Point Calculator. Just like the LED version, all functions are performed by the microcontroller. Last month's LED calculator used a PIC16C62A and could add, subtract, multiply and divide in FIXED POINT. The addition of the decimal point requires a device with more memory so this time a PIC16C63A is used. (You can also use a FLASH PIC like the PIC16F878).


Fig. 1 -- LCD Floating-Point Calculator Block Diagram
Click Image to Enlarge

All circuits fit on a single PC board. You can re-draft the PC layout easily to reduce the size even further. The board is 3.8" x 5.6" in size and will easily fit on a single panel of GD152 Ever-Muse PC Board material (blank pre-sensitized PC board material is available from Circuit Specialists. Read the article, "Making Your Own PC Boards" for more information.). You will also want to cut a blank piece of PCB material the same size as the main board to use as the "back" of the calculator. More on this later....

A Note on Making Your Own PC Board

Making your own PC board can be fun and can save you a lot of money. But it will take time. By experimenter's standards, this is a small board -- not too difficult to manage. Since this project uses surface-mount components for the main items, there are not that many holes to drill(including via holes), most of them are .031" in size (that's thirty-one THOUSANDTHS). Many of these holes are occupied by part leads that must be soldered on both sides because there is no practical way to do the thru-hole plating in a home-brew environment. So be prepared to spend some time on the project and stay away from anything that will give you the "jitters" (like too much coffee...).

The board layout files are part of the Project Package, which includes all of the PC board layouts in both Gerber file format and in EasyTrax format. I highly recommend that you read about and then install EasyTrax before you begin construction. Having EasyTrax on your shop PC will greatly aid you in locating components, tracking down traces and of course, modifying the layout in the event you wish to make changes to the design.

You will also need an inkjet or laser printer to print out the PC board graphic files. The files can be printed directly from EasyPLOT (part of EasyTrax) or as Gerber files using GCPrevue. The Ever-Muse PC board material is very forgiving -- so much so you'll forget it is a form of photography! But the better your PC board artwork is to start with the better the outcome of the board will be. You can also print out two copies of each side of the layout and carefully overlap them to darken the artwork. If you do this, be careful to align each layer as exact as possible and add an additional 5 seconds (30 seconds if you use a regular fluorescent lamp) to the exposure time.

All components used in this project except for ONE are available from Mouser Electronics. You can also purchase some of the parts at Radio Shack, Jameco Electronics, Newark Electronics, or Circuit Specialists. If purchased new, the total cost of this project will be less than $35 at the time this article is published. You can save some money by using parts purchased from surplus dealers and by salvaging parts from your parts junk box. In any event, the entire project is well affordable for most experimenters and students.

This project is presented to you by Lupine Systems for educational purposes only and is not intended to be used as a base design for manufacture, and is not intended to implicate a complete and total solution suitable for all needs. All designs remain property of Lupine Systems at all times. Although this is an experimenter's project capable of producing excellent results, there remains room for improvements. This project is basic and provides all of the systems necessary to perform the desired task but is left open for you, the experimenter, to modify it to your own personal needs. Feel free to experiment with display types, keyboard types and review the processor source code. Enjoy the project, and learn how microcontrollers and microprocessors do math in the process.

How It Works

Fig. 2 shows the Schematic Diagram for the Floating-Point LCD Calculator. All math functions along with keyboard scan is handled by the single PIC microcontroller. A 12MHz 3-pin ceramic resonator is used as the PIC clock source and does not require external capacitors. Display functions are handled in their entirety by the LCD display module using the Hitachi 44780 LCD controller chip.

5 volts is obtained from the two 1.5v "AAA" cells by using an up-converter. The MAX856 is such an up-converter. 3 volts is applied to the MAX856 chip, which uses "Buck" conversion technique to pulsing coil L1 at a high frequency. The flyback from the magnetic rise/fall across the inductor is captured and rectified by fast-recovery Schottky diode D8 and stored in capacitor C2. Capacitor C1 acts as a current "pump" making sure enough current is available to the Buck converter to produce a useful output.

You may use any Schottky diode in place of D8. If you do not have a Schottky diode you can use most fast-recovery diodes, but you cannot use a regular rectifier like a 1N4001. Standard rectifiers do not have a fast enough recovery time to process the high frequency flyback from the Buck conversion and therefore no up-conversion will take place. If the calculator does not function once built and the power supply output measures 3v or so, then diode D8 is most likely the culprit.


Fig. 2 -- Floating-Point Calculator Schematic Diagram
Click Image to Enlarge

Assembling the Floating-Point Calculator

Since this project uses surface-mount components, assembly on perforated or pad-per-hole board is not recommended. Begin assembly by installing all of the vias first. Be sure to identify ONLY the via holes and not component holes! Insert a short piece of AWG#24 wire through each via hole and solder on the TOP layer first, then flip the board and solder on the BOTTOM layer. Trim only after soldering BOTH SIDES.


Basic LCD Floating-Point Calculator PC Board Parts Placement Diagram
Click Image to Enlarge

After installing the vias, begin by installing the 28 surface-mount tactile switches. To align the switches so that they are perfectly in a row, use a metal ruler or metal straight edge. Align the edge along the bottom edge of the bottom row of pads for each row of switches. Once aligned, tape the straight edge in place using masking tape. Then when you place the switch on the pads, work it into alignment using the straight edge as a guide for the lower legs of the switch, then solder one of the upper legs in place. Do this for each switch in the row. Then come back and solder the remaining upper leg. Finally, remove the straight edge and solder both legs on the bottom row. Repeat for each of the remaining three rows.

Next, install the two surface-mount chips. Begin by installing the tiny 8-pin MAX856 chip. Be extremely careful soldering this chip in place! Once the MAX856 is soldered in place, install the PIC16C63A (be sure to program this chip first because the project does not provide connections for In-Circuit Programming!). Again, use extreme caution when soldering this chip in place! Be sure not to overheat these chips when soldering! Solder ONE side at a time, let it cool off, then come back and solder the other side. Once soldered in place, triple check your work to be sure there are no shorts or pins that did not solder well. Touch up all errors before continuing.

Install the .1uF capacitor C1 and all five 1K resistors R1-R5. All of the passive components are formed on .300" forms. Trim excess lead wires close to the board.

Install the seven 1N914 diodes. Observe polarity. Next, install the 12MHz ceramic resonator X1. Be sure to trim any excess lead wires.

Install the two 100uF 16v low-profile capacitors C2 and C3. Observe polarity! Next, install the 47uH coil L1 (this coil looks like a 1/4 watt resistor and has the exact same color codes so be careful not to confuse it with a 47-ohm resistor!!!). You can use either set of mounting holes, whichever fits your coil.

Install the Schottky diode D8. Be sure to observe polarity!

Install the 5K trimmer potentiometer. Trim any excess lead lengths.

Install the DPDT power switch. Mount this switch so that only enough of the solder tabs poke through the PCB to solder them in place. This maximizes the height of the switch, which will be advantageous later on.

Install the 14-pin MALE Molex Series KK .100" header in place of DISPLAY on the main PCB. Then solder the 14-pin FEMALE Series KK .100" header to the LCD or VFD display module.

You may choose which type of RESET circuit you wish to use.

The inexpensive way is to use an R/C reset. The better way is to use a "RESET" device. The PCB is laid out for either/or but NOT both at the same time!

If you choose to use the R/C method, install a 1K resistor in place of R6 and a 100uF 16v low-profile capacitor in place of C4.

If you choose to use a "reset device", install the 3-pin reset chip at U3.

Install a double-"AAA" cell battery holder just above the Molex header and solder the RED (+) wire to the bottom most pad to the left side of the holder and the BLACK (-) wire to the upper pad. You can mount the holder to the PCB using double-sided mounting tape or you can drill two small mounting holes in the PCB and use two #2x52 x 1/4" screws.

Install four #2x52 x 1" screws in the display module mounting holes from the BACK (SOLDER) side of the PCB and secure them to the PCB using nuts and washers. Thread an extra nut on each screw approx. 1/4" down each screw. Make sure these extra nuts are even between the four screws (same height from PCB).

Mount the LCD/VFD display module on the four #2x52 screws. Align the Molex headers together as you mount the display so that the male plugs into the female properly. You may have to slightly "bend" the pins if you accidently mount the female header "backwards" on the display module. This is OK but don't bend too hard or you may damage the traces on the PCB.

Fasten the display module in place using four #2x52 screws and washers.

The electronics part of the calculator is now assembled and is ready for testing.

Switch ON the calculator. You should see "Lupine Systems" on the first line, and "0" on the second line. If you do not see this display, or the display appears really dark or all of the digits are "black", then adjust the 5K trimmer potentiometer. This adjustment sets the display contrast. If you still do not get a display, check the voltage across capacitor C2. It should read 5.0 to 5.1 volts. If you do not have any power at all, recheck the batteries to be sure they are good and be sure coil L1 is not open or that you have any open traces on the PCB. If you read 3v, then the most likely problem is diode D8. The diode MUST be a FAST RECOVERY or Schottky diode. A regular 1N4001 will NOT work!

Table 1
Parts List
Floating-Point LCD/VFD Calculator

DesignatorQuantityDescriptionVendorPart Number
C11.1uF (104) Axial Conformal CapacitorMouser80-C410C104M5U
C2,C3 (C4)2 (3)100uF 16v 6mm Capacitor (see text)Mouser140-L10V100-RC
R1-R5 (R6)6 (7)1K Ohms 1/8 Watt Metal Film Resistor (see text)Mouser299-1K-RC
R715K Ohms Trim PotentiometerMouser652-3306P-1-502
D1-D771N914 Switching DiodeMouser610-1N914
D81Schottky Diode 1N5817Mouser621-1N5817
L1147uH CoilMouser434-23-470J
X1112MHz Ceramic ResonatorMouser520-ZTT1200MT
U11PIC16C63A Microcontroller (see text)Mouser579-PIC16C63A-10/P
U21MAX856 3.3v/5v Up-Converter ICNewark67K6793
U31MCP130-450DI/TO Reset Chip (see text)Mouser579-MCP130-450DI/TO
U412-Line x 16 Character LCD ModuleMouserHDM16216H-B-S00S
J1-A214-Pin Molex Series KK .100" Header MALE
Use (2) 7-Pin Headers
Mouser538-2203-2071
J1-B214-Pin Molex Series KK .100" Header FEMALE
Use (2) 7-Pin Headers
Mouser538-22-02-2075
S11Slide Switch, DPDTMouser629-GF1263011
S2-S2928Tactile Data Entry KeyMouser101-0164-EV
--4Screw, #2x52 1"----
--8Screw, #6x32 1"----
--12Nut, #2x52 Hex----
--2Nut, #6x32 Hex----
--8Washer, #2x52, 1/4" ----
--4Washer, #6x32 Hole Size, 3/16" ----
--4Standoff, #6x32, 1/4" ----
--1Bare PC Board (See Text)Lupine Systems22-904-6B

Notes:

  • As of publication, the PIC16C63A was still available, however if you wish to use a flash part, you can use a PIC16F878 or PIC16F77. You will need to modify the PROCESSOR statement in the assembly file accordingly.
  • Parts list is for purchase of "new" parts. Use of surplus components can save you a lot of money and make projects like this affordable, even for students on tight budgets. Check for parts on Ebay, salvage yards, yard sales, flea markets and other outlets where used or broken electronic items can be found at a discount price.
  • Making the Keyboard Frame and Overlay

    Since the keys on this calculator are tiny surface-mount tactile switches, it would be to a great advantage to have some sort of keyboard overlay to mark which key is which and protect the tiny switches from spillage.

    Included with the Project Package is the printout for the keyboard overlay. The file, "keyboard.pcb" is the draft for this overlay. The Gerber version "keyboard.gkb" is also part of the Project Package.

    In order to use this overlay, you will need to install EasyTrax or GCPrevue. You can print out the overlay from EasyPLOT (a part of EasyTrax) or you can print out the Gerber version using GCPrevue. For more information on how to do this, refer to the Lupine Systems article, "Making Your Own PC Boards". Remember that all drawings such as this overlay and schematics are on the 1 Mid Layer, so be sure to go to Setup, Toggle Layers and turn ON the 1 Mid Layer and turn OFF the Overlay layer.

    Note: The reason this overlay, as well as the PCB layouts and other artwork are NOT presented as .JPG files, .PDF files or any other classic "graphic" format is because these formats do not guarantee proper sizing when printed out. When doing engineering of any kind, accuracy is of upmost importance. The draft files used by EasyTrax and Gerber plots are vector graphic files and will print out to the exact size every time on any printer on any computer without any adjustments. It is a lot easier to simply install EasyTrax and GCPrevue than it is to screw with a .JPG image of printed-circuit file for hours, trying to print out both the TOP and BOTTOM layers so that they both LINE UP IN REGISTRATION good enough to actually make a PCB. Believe me, it's worth the install, and once you get used to using CAD software, you'll find hundreds of other uses for it as well.

    Besides, older PCs are easy to come by nowadays, and are either FREE or DIRT CHEAP. So are monochrome laser printers. I actually picked up 14 perfectly good laser printers and over 50 very decent PCs from the SIDE OF THE ROAD for FREE on the day the city held its "heavy trash day", or the day you get to throw away things like appliances, furniture, etc. Having a dedicated PC in the shop to print out this kind of artwork and draft PCBs and other drawings is a fantastic tool to have. And since it is the "shop", the PC can be an old one, say 200-500MHz running Windows 95 or 98. Excellent for running both EasyTrax and GCPrevue while still being fast enough to provide good network connection for file sharing and some quick "photoshopping".

    To make the overlay, you will need the following items. You can purchase these items from any office supply store or big-box discount store.

  • 1 Pack of Avery Sticker Project Sheets
  • 1 Pack of Avery Self-Adhesive Laminating Sheets
  • You will also need a small piece of 3/16" sheet plastic, about 3" x 4". You can use polycarbonate (Lexan) or acrylic. Polycarbonate is easier to tool and does not break or shatter as easy but any plastic will work as long as you can tool it without shattering it. The thickness should be no less than 3/16" and no more than 5/16".

    The panel overlay assembly is held to the main PCB using #6x32 screws. Two of these screws will attach with nuts and two will thread into 1/4" standoffs. #6x32 screws are extremely common, so about any #6x32 screw that you can cut to length using a screw cutter (usually there is a screw cutter as part of a terminal crimping tool).

    First print out the overlay on a sheet of Avery Sticker paper using EasyTrax or GCPrevue. There are two copies of the sticker in the draft. One will be used as the actual overlay. The other one will be used as a "guide" to tool the plastic riser piece.

    Cut the two overlay prints apart along the marked cutting line. Set one overlay aside for now.

    Carefully remove the starting edge of the backing paper on one sheet of Avery Self-Adhesive Laminating film. Apply the laminating film to the overlay starting BELOW the area where the starting edge piece was peeled off. If you use the area of the laminating sheet where the starter backing paper was peeled off, there will be a hideous "line" across the overlay and will degrade the appearance. Use only enough of the laminating film to cover the overlay. Cut the excess off along the same cutting line as you used to cut out the overlay. Once you have completed laminating the overlay, place this piece to the side for now.

    In this step you will tool out the riser piece of the keyboard overlay. You will need a Dremel tool and a sharp miniature rasp file, some #100 grit sandpaper on a block of wood or sanding block, a sabre saw (jigsaw), band saw or reciprocating saw -- AND a lot of patience. This is a SKILL THING so be CAREFUL using power tools and TAKE YOUR TIME. If you break the plastic during this step you will have to start all over again.

    Begin tooling the plastic by first sticking the remaining overlay printed out in the first step on the plastic surface. If the plastic sheet you are using has a protective paper coating, leave this paper in place. It will help prevent the plastic from shattering during tooling.

    Using a sabre saw, band saw or reciprocating saw, cut the plastic along the outer edge of the draft as shown. Unless you are an expert at using these tools, it is a good practice to cut a bit outside the line, then use a piece of #100 sandpaper on a sanding block to slowly hone the edge down to the line. When complete, the plastic rectangle will be 2.35" x 3.75".

    Next, drill the four corner holes in the plastic as marked. Drill these holes 1/8" but no larger than 5/32". Take caution if you are using acrylic plastic--drilling is the easiest way to shatter the plastic so be slow and if possible use a drill press.

    Drill a hole in the center of the plastic, straight through the center of where the keyboard should be. Drill out the hole back and forth large enough to fit the blade of a sabre saw through. Then using a sabre saw, carefully cut out the inside of the keyboard area along the inside marks. Use of a fine-toothed blade helps trememdously (a "metal-cutting" blade works best). Smooth out the cut using a small rasp file. This cut is not critical but it needs to be within one blade's width of the cutting line for best performance.

    Clean off the plastic and remove all paper items including the overlay sticker, protective papers or tape you may have placed on the overlay during tooling. Thoroughly clean the plastic with Windex and avoid touching the surface with your fingers afterwards.

    Finally, carefully remove the backing paper from the laminated overlay you did earlier. Now center up the overlay on the plastic riser. Use the drill holes and edge guide to help align the overlay exactly to the edge with the plastic. Next, use a small screwdriver to punch out the drill holes from the front side to the back side.

    Carefully wrap the overlay around the edges of the riser and adhese to the underside of the plastic. Use a razor knife to trim off any excess that extends into the keyboard area. Use angle cuts at the corners to remove any overlay that overlaps other parts you have folded under. Punch out the drill holes once again, this time from back to front using a small screwdriver.

    The areas of this overlay that you wrapped around may peel up slightly. This is OK because you can stick it back in place before you mount it to the PCB.

    Cut a piece of Avery Self-Adhesive Laminating film to the size of the key area (the inside of the overlay area). Peel off the protective backing and adhese this film to the UNDERSIDE of the keyboard area. You will be sticking GLUE TO GLUE in this step so be careful!

    Mount the keyboard overlay assembly to the PCB using four #6x32 screws, two nuts and two 1/4" standoffs. Cut the screws to 7/16" in length (this is not accurate but if you get the screws too long they will extend into the standoffs too far and prevent the bottom mounting screws from threading into the standoff). Place a #6-32 3/16" washer on each screw and carefully push each screw through the overlay mounting holes. When pushing the screws through, be careful not to disturb the wrap-around part of the overlay.

    Center up the overlay with the overlay mounting holes and install the overlay onto the PCB. Use the two #6x32 nuts to fasten the top two screws and two #6x32 x 1/4" standoffs for the bottom two.

    Hint: When tightening these screws, use a Philips screwdriver to hold the screw head. Then use a pair of pliers to tighten the nut from the SOLDER SIDE of the PCB. Do NOT "screw" the screw into the nut. Doing so will grab the plastic sticker on the overlay and twist it, destroying it in the process.

    Now the keyboard is complete and should resemble the prototype photograph below.


    Closeup of Keyboard Overlay Assembly

    Complete the calculator assembly by first installing two #6x32 1/4" standoffs at the two remaining mounting holes at the top of the PCB (above the display and to the right an left of the battery pack). Then cut a piece of material to use as the "back" of the calculator. You can use a piece of PCB material, or you can use a piece of plastic just like you used to make the keyboard riser piece. Drill the four corner mounting holes in the exact same places on the back piece as are on the PCB. Then mount the back piece to the calculator using four #6-32 screws. You may have to cut these screws shorter so they do not thread into the standoffs so far as to bottom-out against the screws used to hold the standoffs to the main PCB.

    The final step is to install two size "AAA" cells in the battery holder. The calculator is now complete and ready for use!

    Using the Floating-Point Calculator



    Floating-point arithmetic is much more complex in software than fixed-point, therefore, the software has limitations when it comes to certain functions.

    Addition, subtraction and multiplication are fairly straightforward and have no accuracy issues. But division is a whole 'nother ball game.

    Since this project was designed to be an introduction to microcontroller arithmetic, I have chosen to limit the accuracy of the division routine to three cycles of 8-digit division. (There will be much more on this and how to add more cycles to the division routine in the section to follow, "Software for the Floating-Point Calculator").

    Although the division routine is limited, it will divide two floating-point numbers accurately each and every time. The limitation is realized in the decimal and how many places the machine will calculate the quotient out to. For most calculations, the machine will carry out the entire display, but there are a few instances where the final answer has not been fully computed. This is because of the limited number of division cycles performed, and if you wish to improve accuracy, it is possible to have the machine perform as many division cycles as necessary to give the accuracy you desire. But for most human beings, accuracy to at least 5 decimal places is more than adequate and in most cases you'll actually get all of the available decimal places. So don't sweat it too much unless you plan to use this project to calculate the circumference of the universe!

    I still think that by this time in history most people already know how to use a calculator, so I will only provide a quick overview of each key and its function. (actually the first part is the same as this section for the LED Fixed-Point Calculator).

    Arithmetic Keys and Their Functions

    Calculators work in the sense of performing an arithmetic operation on two variables, X and Y. The calculator in this project ALWAYS performs the desired operation on the variables X and Y and these two variables can be swapped in the event they are entered in reverse (very useful when doing subtraction or division). Arithmetic is entered in the classic algebraic format, i.e. 2+2=4. Operations can be done sequentially but do NOT follow the algebraic rule of Order of Operations. Example: Algebra rules state that the equation:

    2 + 3 x 5 =

    should be solved as:

    2 + (3 x 5) = 17

    Calculators classically do not follow these rules unless they are scientific algebraic entry calculators. Instead, most classic pocket calculators solve equations in sequential operation order rather than the mathematically defined "Order of Operations" as described above.

    Therefore, our sample equation,

    2 + 3 x 5 =

    would be solved as:

    2 + 3 x (understood equals, 5 appears on display) 5 = 25.

    Rule: The desired function is always performed on the number in the display (X). When a function key is pressed, the number on the display is transferred to the (Y) register and the calculator awaits another number to be entered as (X). The operation is completed with the (=) key OR the pressing of another function key.

    Numerical Entry Keys (0-9)

    Used to enter numbers into the calculator. The longest number that can be entered is 8 digits plus one decimal point. Unlike some calculators, this calculator will realize all 8 digits when the decimal is used rather than wasting one digit for the leading "zero" before the decimal.

    Format: (1) (2) (3) will enter the number 123 on the display and the (X) register.

    Decimal Key (.)

    Used to enter the decimal point in a floating-point expression.

    Format: (1) (2) (.) (3) will enter 12.3 on the display.

    Addition Key (+)

    Adds the number on the display to the value in the (Y) register and returns the sum to the (X) register and display.

    Format: Y + X = (display)

    Subtraction Key (-)

    Subtracts the number on the display from the value in the (Y) register and returns the difference to the (X) register and display.

    Format: Y - X = (display)

    Use of the (x<>y) key will swap these two variables. So if you entered,

    12 - 19, but meant to enter 19 - 12, all you have to do is press the (x<>y) key and the two terms are reversed.

    Multiplication Key (*)

    Multiplies the value on the display times the value in the (Y) register and returns the product to the (X) register and display.

    Format: X * Y = (display)

    Division Key (/)

    Divides the number in the (Y) register by the number in the (X) register and returns the quotient to the (X) register and display and the fractional modulus component (undivisable remainder) of the quotient in the (Y) register. Use of the (x<>y) key swaps the quotient and fractional modulus values. When the fractional modulus is displayed, the letter "M" is also displayed in the "ERROR" display to indicate you have completed a division and are viewing the fractional modulus component of the quotient.

    Format: Y / X = [Quotient](display) [Fractional Modulus] (Y)

    The (x<>y) key will swap the dividend (Y) and the divisor (X) prior to the pressing of the (=) key or another function key.

    If a sequential operation is performed after a division, only the quotient component is passed on to the next operation sequence. The modulus component is lost forever.

    In the event you need to extend the accuracy of a division, you may use the fractional modulus to continue the division process by dividing the modulus by the divisor (X). The display will then display the next 8 digits of the decimal component of the quotient for each time you divide the sequential fractional modulus component by the divisor (X).

    Note: Since division by zero is mathematically impossible, attempting to divide by zero will result in an error and the error message "ERROR" will appear in the error area of the display.

    Change Sign Key (+/-)

    Changes the sign of the number on the display. If the current number is positive, then it will become negative. If the current number is negative, it will become positive.

    Format: (X) (+/-) --> (-X)

    Equals Key (=)

    Terminates all functions and returns the solution to the entered equation to the display (X). The (=) key also clears the (Y) register. Sequential operations may be entered following the (=) key.

    Format: [Desired Operation] (=) [Solution to Equation --> (X)], (Y) = 0

    Clear Key (C)

    Clears all registers (X, Y and internal registers), clears all operations (+, -, *, /) and returns the machine to an initialized state. Cancels any operation in mid-sequence. The CLEAR key has no affect on data stored in memory.

    Format: (C) --> (X) = 0, (Y) = 0, [Internal Working Registers] = 0, --> Operations Cancelled

    Clear Entry Key (CE)

    Clears the display (X). Has no affect on any other register or operation.

    Format: (CE) --> (X) = 0

    Reciprocal Key (1/x)

    Finds the mathematical reciprocal of the number on the display (X). This key only affects the number on the display. The (Y) register or any pending operations are not affected.

    Format: Reciprocal of 17 (1) (7) (1/x) --> .05882352

    Square Key (1/x)

    Finds the mathematical square of the number in the display. This key only affects the number on the display. The (Y) register or any pending operations are not affected.

    Format: Square of 52 (5) (2) (x2) --> 2704

    Percent Key (%)

    Calculates using percentages. This key only affects the number on the display. The (Y) register or any pending operations are not affected.

    Format: Calculates (X)% of (Y) and returns the answer to the display and (X).

  • Percentages as Part of a Calculation. Enter (Y) value first. Then enter the desired math operation. Then enter percentage and press (%). (X)% of (Y) is displayed. Pressing (=) finalizes the sequence.
    • 15 + (25% of 15) = 18.75 --> (1) (5) (+) (2) (5) (%) (=) --> 18.75

  • Finding Raw Percentage. Enter the base number, then press (x<>y). Then enter the percentage and press (%).
    • 45% of 93 --> (9) (3) (x<>y) (4) (5) (%) [no equals required]

    Memory Add Key (M+)

    Adds a cumulative sum to the caculator's memory (Epsilon +). Each time (M+) is pressed the number on the display is added to memory. The MEAN counter is incremented each time this key is pressed. The display (X) and the (Y) register remain unchanged.

    Format: Add 29.3 to Memory --> [Display]29.3 (M+) --> [Memory + 29.3]

    Memory Recall Key (MR)

    Displays the value currently saved in memory on the display. The (Y) register remains unchanged.

    Format: (MR) --> [Memory Value] --> [Display]

    Memory Clear Key (MC)

    Clears the memory. Also resets the MEAN counter.

    Format: (MC) --> [Memory] = 0

    MEAN Key (MEAN)

    Calculates the statistical MEAN of the numbers entered into memory and places the answer in the display and (X). Up to 255 entries can be made. This key has no affect on the (Y) register.

    Format: Enter each number you wish to average, or you can use the result of a calculation. Press (M+) after each entry. Once all numbers have been entered, press (MEAN). The statistical MEAN will be displayed.

    Display Mean Counter Key (DMC)

    Displays the number of entries into memory that have been made. This is the number that will be used as the divisor during the MEAN calculation. Cleared by pressing the (MC) key. The (Y) register remains unchanged.

    Format: (DMC) --> [Mean Counter] --> [Display] and (X)

    The Display

    The display represents the (X) register and is 8 digits long, or 9 spaces long if the decimal point display is included, and occupies the right-most spaces on the display module. To the left of the main display area, the SIGN display (-) shows for negative numbers. This area can also display "ERROR" in the event of overflow, underflow or division by zero. An "M" will appear in the display when viewing the fractional modulus value of the division operation.

    There's More to Come!

    Since most math functions are derivatives of the basic four functions, just about any math function can be added to the calculator. This project leaves one PIC port unused (PORTA,0), and this port could be used to add another row or column to the keyboard. One more row would give you an additional 7 keys, or one more column would give you an additional 4 keys. You could also re-assign one of the current keys on the keyboard to be a "2nd" function key and "re-use" the existing keys to add more functions.

    Much like the x2 function, advanced math functions can easily be added. You can also add features such as "English-to-Metric/Metric-to-English" conversions, d-m-s to decimal degree conversion, LOG, xy, and many others. The only restriction you will have is lower memory allocation (more on this in the next section on software) and RAM. Use of a larger PIC would greatly facilitate the addition of these features. Also, you could port the code from PIC16xxx code to PIC17xxx or PIC18xxx code and use a MUCH MORE POWERFUL and FASTER processor with HUGE amounts of RAM and ROM. Running this code on an 18F4582 at 40MHz would allow for the creation of a full-blown scientific calculator with 20-digit display and three-digit exponent (capable of working with numbers as large as [449!], with USB support and capable of graphing three-dimentional space and plotting those graphs by driving a color laser or inkjet printer directly!

    In the next section I will discuss the PIC microcontroller software that makes this calculator work. I will go in to detail and give lengthy explinations on the processes necessary to complete each operation. I will outline the registers used, RAM and ROM allocation, processor loads and the time it takes to complete each operation. This section is VERY VERY VERY LONG and detailed but for those who have never done math with a microprocessor it will be a dive into code that will remain with you for a lifetime.

    Why Unpacked BCD?

    This project incorporates a technique to process unpacked BCD numbers. Most programmers would have used packed BCD numbers, mainy because packed BCD uses less RAM space and can manipulate two digits simultaneously. So the question is, why unpacked BCD?

    Here's why...Most of the time, out here in the real world, experimenters and hobbyist (and often times engineers facing a daunting challenge) run into numbers in one of two forms:

  • Seven Segment format on some LED display, or
  • Binary represented, or Binary-Coded Decimal (BCD) single digit numbers.
  • For example, have you ever thought about the display on a digital time clock? What "if" you had to "access" this digital information for one reason or another?...So you take the thing apart, just to find that the display is driven directly from the processor. You don't have "access" to the actual individual digit data. But you do! You can "re-encode" the 7-segment display data back into BCD and presto! But how can you deal with this if all that's available deals with packed BCD? What if you need to deal with the numbers in an "unpacked" way, which is the way most displays work?...

    Now you know. Experimenters classically write code that manipulates displays one at a time. So the math routines used in this project manupulate the numbers ONE AT A TIME, making the routines useable in many projects without having to do binary/hex or pack/unpack conversions.

    I know this is the long way around this ride but necessary to facilitate easy integration into other projects, designs or concepts. Personally I know of many projects I've passed up because of one reason or another, and one of those reasons has been the lack of the ability to calculate basic numbers. Well, now YOU don't have to pass up any of these projects because you will soon know how this is done!

    If you are clever, you "could" pack the digits, compress the code some and save some RAM...but that would take a lot of time...!!

    Click Here to Continue to the page...
    Software for the Floating-Point Calculator

    Click Here to Go to Next Month's Article...
    Build an Advanced Floating-Point Nixie Tube Desk Calculator

    Parts Suppliers

    Here are links and contact information for the recommended parts suppliers. You can purchase all of the parts used in this project from the suppliers listed below (not all from one, see the Parts List for supplier information), or you can shop around on the Internet for better prices and sources. Surplus outlets are especially useful when purchasing TTL logic chips, sockets, resistors and capacitors.

  • Circuit Specialists
    • Phone: 800-528-1417

  • Digi-Key
    • Phone: 800-DIGI-KEY

  • Jameco Electronics
    • Phone: 800-831-4242

  • Mouser Electronics
    • Phone: 800-346-6873

  • Newark Electronics
    • Phone: 800-4-Newark (800-463-9275)

  • Radio Shack
  • We're Sorry, but this project is not being offered as an assembled ready to use product at this time. Please do not inquire into having us build one for you!
  • Click Here to go on to the next page, "Software for the Floating-Point Calculator".

    Click Here to go to Next Month's Article, "Build an Advanced Floating-Point Nixie Tube Desk Calculator".

    Back to the Lupine Systems Homepage
    Lupine Systems Download Section
    How to Make PC Boards
    How to Use EasyTrax CAD Software

    © 2007 Lupine Systems. It's a WOLF Thing! ®