Simple Calculator
Purpose
To interact with additional devices:
- Use the Liquid Crystal Display (LCD)
- Use the key pad
Due dates
You must hand in your answers to the
questions
at the beginning of your laboratory session on Thursday, December 4.
This part of the assignment is worth 20 points.
You must be prepared to discuss your work at the beginning of your
laboratory session on
Tuesday, December 9,
and to demonstrate
your program to your TA during that period.
This part of the assignment is worth 30 points.
Background
In previous assignments, a TeraTerm window was used to not only
download code to the MB5, but also to interact with the program
running on the MB5.
With this assignment, the TeraTerm window will only used to download
code and start the program running.
After that, all interaction with the program will be through
two devices that have not previously been used.
These devices are the Liquid Crystal Display (LCD) and the keypad.
Liquid Crystal Display
The MB5 has an LCD that is just a smaller and simpler version of those
found on notebook computers.
It has only 4 lines of 20 characters each.
It cannot display graphics, nor can it display different colors.
Nonetheless, it is a very common piece of hardware used by many devices
that need a small dedicated screen for displaying status information.
The LCD has the advantage of being relatively inexpensive.
Click here for details of
how to use the LCD.
The LCD displays ASCII characters.
In order to display a number, that number must be converted into
a sequence of ASCII characters representing its digits.
You have already written a routine to perform that conversion (click
here for a description of the algorithm).
Keypad
The keypad is also a commonly-used device for entering data when a
complete keyboard is too large or unnecessary.
Click here for a description
of how the keypad is read.
A sequence of key presses corresponding to numeric digits must be
converted to a binary integer.
Unfortunately, the code for a key that is read from the keypad does not
correspond to the numeric value of the label on that key,
nor is it an ASCII code.
Thus instructions must be written to determine the numeric value
of the digit corresponding to the key press.
The value of the integer represented by a sequence of digits is given by
the polynomial
dn-1×10n-1 +
dn-2×10n-2 +
..
+ d1×101
+ d0×100
=
(...((dn-1)×10 +
dn-2)×10 +
..
+ d1)×10
+ d0
A simple loop to compute the value of this polynomial can be derived from
the second version.
Called Horner's method, it is the normal method of converting a
sequence of digits to an integer.
Horner's method processes the digits in the order in which they arrive.
An accumulator is loaded with the value of the first digit.
If there is another digit, the accumulator is multiplied by 10 and the next
digit added.
The process continues until all digits have been dealt with.
Task
Implement a decimal version of the calculator from an
earlier assignment.
Use the keypad to enter numbers and the LCD to display numbers and results.
Use of the keypad
The keys labeled with numbers should correspond to
those numbers.
The keys labeled A, B, C and D should perform the operations addition,
subtraction, multiplication and division, respectively.
The ``*'' key should be a clear operation, while the ``#'' should correspond
to pressing ``='' on a regular calculator.
Arithmetic Constraints
The 68000 multiply instruction only takes 16-bit operands.
You may limit the size of input values to be less than 216.
If a user enters a larger number, you should print an appropriate error
message.
So, you do not have to write double precision multiply or divide
routines.
All arithmetic is integer arithmetic.
There is no need to display real numbers when a division operation is
performed.
(If you choose, you may want to display the remainder in addition to the
quotient.)
Questions
-
This assignment specifies that ``*'' be used as a ``clear'' key.
It does not, however, specify what is supposed to happen when that
key is pressed.
- (5 points)
Carefully specify how your program will use the ``*'' key.
Take into account the fact that there is no backspace key, and also the
fact that you cannot correct a decimal number simply by letting high-order
digits disappear (as was done with the
hexadecimal calculator).
- (5 points)
Specify a state machine that implements
a calculator with the behavior you describe in (a).
- (5 points)
Suppose that you wanted to retain the basic structure of your hexadecimal
calculator, using a routine with the the
previous interface
to read from the keypad.
The keypad is an interrupt-driven device.
How could you make the previous implementation
compatible with the keypad?
- (5 points)
Multiplication by any integer constant no larger than 20 (except for 11, 13
and 19) can be carried out by doing two shifts and an add or subtract.
Are there any advantages to using this method for decimal-to-binary
conversion in the calculator program?
Explain briefly.
Demonstration
You must demonstrate
your program to your TA on one of the machines in the Microlab.