Lupine Systems Presents...Part One of the Series
Build Your Own Microcontroller Calculator
THIS MONTH:   Build a Fixed Point LED Calculator
by Spike Tsasmali, Lupine Systems

Build Your Own Fixed Point LED Calculator

Beginner Project Difficulty=1 Howl


Electronic calculators have been around now for nearly 50 years. Early forms of electronic calculators were bulky, cumbersome and took quite a bit of knowledge to use. But in the mid 1960's Dr. Wang of Wang Laboratories made many improvements to the electronic calculator, eventually leading to the machine we know so well today.

Other manufacturers like Hewlett-Packard were also busy with early calculator designs. HP released the world's first "pocket" calculator in the late 1960's. The greatest improvement to any of these designs however was the use of microelectronics. Without the silicon chip Hewlett-Packard could have never invented the "pocket" calculator.

And the greatest microelectronic device ever created was actually intended to be a CALCULATOR CHIP! I am speaking of the Intel 4000, the world's first MICROPROCESSOR! Although it was never widely used by its original contractor for many calculators, the i4000 became the example for which all microprocessors were eventually designed. Instead, the calculator world went in a totally different direction--dense hardware. Calculator "chips" are not microprocessors. Instead, they are complicated large-scale integration devices which act "kinda-like" a microprocessor but actually do their work in dense hardware. This left the microprocessor available for use in other devices, and eventually in small mini computers. In the meantime, the calculator chip evolved into a compact, high transistor count specialized device, simplified down to the basics and manufactured on the cheap.

Unlike the days back in the 1970's when pocket calculators contained a "normal" packaged chip (typically 24 or 28 pin DIP package) mounted thru-hole on a regular PC board, nowadays calculator chips are so common and so cheap they are made in the form of "die cut" chips, epoxy "blobbed" onto a PC board and wired directly to the copper traces. In many cases the chip is bonded directly to the display substrate forming one complete integrated chip/display package. This method of manufacturing is very inexpensive, but it makes it so that a regular DIP package chip is no longer needed and therefore, no longer available. So if you went to build yourself a calculator, custom to your needs, with a HUGE display, or oversized keys, or fancy case, you could not find a NEW calculator chip anywhere. Yes, you could buy an old calculator at a flea market and salvage the chip, but then you face the chance of damaging those delicate (and aged) NMOS chips. So what do you do??

Although the microprocessor was never widely used as a "calculator" chip, microprocessors can do all of what a calculator chip can do and then some, as long as you know how to program it. Some high-end business calculators use a combination of dedicated calculator chips and microprocessors in order to form a very complex business machine but the classic calculator still does not use a microprocessor and very few use any version of a microcontroller.

In this article, I will explain to you how to implement true calculator functions within a simple microcontroller chip.

Engineering a Basic Calculator

Calculator design involves three basic considerations:

  • Display type
  • Keyboard type
  • Functions
  • Displays come in many flavors:

  • LED (usually red)
  • LCD (mainly transflective but can be backlit)
  • VFD (Vacuum Fluorescent, nice smooth green display with customizable characters)
  • Gas Discharge (bright orange displays)
  • LCD Modular (alpha-numeric in nature and modular, displays large numbers of characters)
  • CRT (a video screen, usually a type of vector (oscilloscope style) monitor)
  • Incandescent (like light-bulb filaments, bright, define but limited lifetime)
  • Nixie tubes (10-segment neon gas discharge displays in vacuum tube form, nice characters)
  • There are actually more choices!
  • The keyboard is one of the most important parts of any useful calculator design. Use of the wrong type of keyboard leads to the creation of a machine that is more hated than loved for no other reason than the frustration that a crappy keyboard creates.

    Depending on the final design of your calculator, you can choose any number of keyboards:

  • Tactile (snaps when key is depressed)
  • Magnetic reed (smooth, cannot be "trashed" by spilled coffee)
  • Optical (reliable in non-dusty environments)
  • Membrane (least desirable, flat, surfaceless but highly customizable)
  • Touch Sensor (very fast data entry but no "feedback")
  • There are two basic formats of calculators in use today:

  • Fixed Point, where the decimal point is fixed, usually at two places to represent money
  • Floating Point, where the decimal can be entered on the keyboard, moved and moves during calculations
  • Then there are two basic function sets commonly in use today:

  • Basic Function (or 4-function)
  • Scientific
  • So before a calculator design can be realized, you must first decide on what kind of display, what kind of keyboard and what math functions will your machine perform.

    In this article, I have chosen to build a calculator "adding" machine. So the choices are:

    Keyboard: Tactile Data Entry. Large typewriter-sized keys with feedback. Also inexpensive and comes in many styles.

    Display: Bright LED. LED displays can also be in a variety of colors including green, yellow, amber, orange and recently, blue. The type of display I have chosen is the Lite-On LTS-313, a .300" ultra-bright high-efficiency LED. This display is the "bright" version of the very common MAN74A or MAN3940 display and both are interchangeable. Also very inexpensive.

    Function: Classic adding machine. Fixed point arithmetic. With double-zero key for fast money values entry. Division is done in integers with remainder (no decimal fraction) which is very helpful when dividing up cash.

    Building the Fixed Point Calculator

    Fig. 1 shows a block diagram of the Fixed Point Calculator (adding machine). All fuctions except for the digit selection is done by the microcontroller PIC16C62A (you can use a PIC16F877 or any PIC 16C/F6xxx device). Digit selection is done using a single 74HC42 1-of-10 decoder. Digits are driven using common 2N3906 PNP transistors.

    Fig. 1 -- Basic LED Fixed 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 separate the display in the event you wish to put the display on a separate PC board so it can be "tilted" for better viewing. The board is 5.4" x 6.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 can make your own PC board or you can purchase a pre-etched board from Lupine Systems.

    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 medium-sized board -- not too difficult to manage. Although there are not that many holes (including via holes), most of them are .031" in size (that's thirty-one THOUSANDTHS). Many of these holes are occupied by part leads or chip pins 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 are available from Mouser Electronics. You can also purchase some of the parts at Radio Shack, Jameco Electronics, or Circuit Specialists. If purchased new, the total cost of this project will be less than $25 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 Basic Fixed Point LED Calculator. All math functions along with keyboard scan and display multiplexing 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. Digit selection is done by an external 74HC42 1-of-10 decoder chip U2. The PIC is capable of sourcing enough current for the LED displays but the 74HC42 is not capable of properly sinking enough current to light the displays to their proper brightness so an additional transistor drive stage is added to each digit drive to boost the current to the display. This stage consists of a 1K base coupling resistor and a 2N3906 PNP transistor.

    Fig. 2 -- Basic LED Fixed Point Calculator Schematic Diagram
    Click Image to Enlarge

    Assembling the Basic Fixed Point Calculator

    Since this project is simple and has very few interconnects, assembly can easily be done on perforated or pad-per-hole board or you can use a PC board. If you chose to make your own PC board, 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 LED Fixed Point Calculator PC Board Parts Placement Diagram
    Click Image to Enlarge

    First install all bypass capacitors and all resistors. All of the passive components are formed on .300" forms. Trim excess lead wires close to the board.

    Next install the 10 LED displays. The leads on these displays are exceptionally long and you may wish to trim them. It a good idea because these leads are SHARP and can cut you if left uncut.

    After you have the LED displays installed, install the 10 2N3906 transistors. Be sure to observe polarity. Then install the bridge rectifier BR1. Once again, observe polarity.

    Install the 7805 voltage regulator. Since this project draws such little current a separate heatsink is not required as long as you do not apply more than 8v to the power input. If you plan to use a 12v wall-wart, then you may need to add an additional heatsink.

    Install the power input jack and filter capacitor C3. Observe polarity!

    Install the six 1N914 diodes. Observe polarity. Next, install the 28-pin shrink-DIP socket for U1 and the 16-pin low-profile socket in place of U2. Do NOT put chips in the sockets yet! Finally, install the 12MHz ceramic resonator X1. Be sure to trim any excess lead wires.

    The final step is to install the 20 data entry keys and the power switch. Insert the keys one row at a time and use a strip of masking tape to help hold the keys flush against the board, then flip the board and solder ALL of the switch pins. After the switches have been soldered in place you can then snap on the key caps. Finally solder the power switch and trim any excess lead lengths.

    If you purchased removeable transparent keycaps you can then print out the description of each key on your printer using Photoshop or WordPad, then carefully cut out each character and insert the tiny paper slip in the removable keycap cover.

    The calculator is now assembled and is ready for power testing. DO NOT INSTALL THE PIC CHIP UNTIL THE POWER SUPPLY HAS BEEN TESTED!

    Connect a 6-8v AC or DC wall wart power transformer to the power input jack. Switch ON the power switch. Using a digital voltmeter, measure the voltage at Pin 16 of U2. Pick up GROUND at Pin 8 of U2. The voltage should be between 4.9 and 5.2v. If it is higher or lower then you have a power supply problem, most likely the wall wart. Use a different power source and retest. If you get the same results, be sure you have installed the bridge rectifier and filter capacitor properly. Correct any power supply issues before installing PIC U1.

    Once you are satisfied that the power supply is working properly, install the 74HC42 chip into socket U2 and a PIC 16C62A programmed with the source code ledcalc.asm into socket U1. When programming this PIC, set the oscillator for XT, the Power-ON timer ON, the Watchdog timer OFF and the Brown-Out Detect ON. You can choose whether or not you wish to use the Code Protect or not.

    Table 1
    Parts List
    Basic Fixed Point Calculator

    DesignatorQuantityDescriptionVendorPart Number
    C1,C22.1uF (104) Axial Conformal CapacitorMouser80-C410C104M5U
    C312200uF/25v Radial Electrolytic CapacitorMouser647-UVZ1E222MHD
    R1-R14141K Ohms 1/8 Watt Metal Film ResistorMouser299-1K-RC
    X1112MHz Ceramic ResonatorMouser520-ZTT1200MT
    Q1-Q10102N3906 PNP TransistorMouser512-2N3906TA
    U11PIC16C62A Microcontroller (see text)Mouser579-PIC16C62A-10/P
    U2174HC42 1-of-10 Decoder ICMouser511-M74HC42
    BR111A Bridge RectifierMouser833-RB151-BP
    U317805T Voltage RegulatorMouser511-L7805CV
    DSP1-DSP1010LTS-313 LED DisplayChoose Color-----------
    J113.5mm Power JackMouser161-3412-EX
    --116-Pin Low-Profile IC SocketMouser571-3902614
    --128-Pin Low-Profile IC SocketMouser571-3902619
    S1-S2020Tactile Data Entry KeyMouser653-B3F-4050
    --10Key Caps for Data Entry KeysChoose Color-----------
    S211Subminiature Push SwitchMouser688-SPPH430100
    --1Wall-Wart style Power Supply, 6-8v AC/DCMouser553-WDU75-200
    --1Bare PC Board (See Text)Lupine Systems22-904-6B


  • As of publication, the PIC16C62A was still available, however if you wish to use a flash part, you can use a PIC16F73. You will need to modify the PROCESSOR statement in the assembly file and add the necessary lines of code to switch all of the ports to digital.
  • Display color has no bearing on performance. You can use any of the LTE-313 part numbers OR you can use MAN74, MAN74A or MAN3940. There may be other displays with this same common pinout available. If you are designing your own PC board or building this project on perforated or pad-per-hole board then you may choose any common CATHODE LED display you wish to use.
  • 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.
  • Using the Fixed Point Calculator

    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.

    Decimal Fixed Point Keys

    This calculator uses "fixed point" arithmetic. Therefore, for convenience, you may set the decimal point at a handy location for your reference. You may choose from four options:

  • No Decimal, Integers only
  • Decimal at 2 Places -- useful when adding or working with money
  • Decimal at 4 Places
  • Decimal at 6 Places
  • To set the decimal, press the desired decimal placement key. The decimal will appear on the display at that point and remain lit until you turn off the calculator or press another decimal assignment key.

    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 and 00)

    Used to enter numbers into the calculator. The longest number that can be entered is 8 digits. The double-zero key (00) enters two zeros sequentially unless this key is pressed while 7 digits are already entered, then it will only enter one zero. The double-zero key is especially useful when entering whole dollar values.

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

    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 integer component of the quotient to the (X) register and display and the remainder component of the quotient in the (Y) register. Use of the (x<>y) key swaps the integer and remainder values. When the remainder is displayed, the letter "r" is also displayed on the "error" display to indicate you have completed a division and are viewing the remainder component of the quotient.

    Format: Y / X = [Integer](display) [Remainder] (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 integer component is passed on to the next operation sequence. The remainder component is lost forever.

    Note: Since division by zero is mathematically impossible, attempting to divide by zero will result in an error and the error message "E" will appear in the error 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.

    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

    The Display

    The display represents the (X) register and is 8 digits long. You may set the decimal place using the Decimal Placement keys at 0, 2, 4 or 6 points. The display also consists of two character readouts to the left of the eight number displays. The innermost (9th from the right) character is the SIGN display. This display will indicate a (-) sign if the number in the (X) register is negative and will be blank if the number in the (X) register is positive. The leftmost readout is the "error" display. This readout will display the character "E" in the event of an error (overflow, underflow or division by zero). It will display the character "r" when the main display contains the remainder of a division operation. Otherwise this readout will remain blank (no error, operation complete and accurate).

    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 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.

    Click Here to Continue to the page...
    Software for the Fixed Point 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

  • 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 Fixed Point Calculator".

    Coming Up in the Next Article...

    In the next installment, I will show you how to drastically miniaturize this project using a surface mount PIC and an LCD display module! This miniature version will also include an x2 (square) key and memory functions (M+, MR and MC), reciprocal, percentages and MEAN function as well as the drawings for making your own keyboard. The calculator is also battery-powered using two "AAA" cells. It includes an battery manager/up-converter/regulator to convert the 3v or so into 5v to drive the PIC and LCD display module.

    Click Here to go to the Next Article!

    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! ®