# Digital Logic Calculator Providing Calculations for Use with Microcontrollers Collin Butler John Reece

```Digital Logic Calculator
Providing Calculations for Use with Microcontrollers
Collin Butler
John Reece
EGGN383
Overview
Objective: create a calculator to perform
common calculations for typical microcontroller
use
Design Goals:
– Calculations for 16-bit systems
– Simple arithmetic operations
– Conversions to binary and hexadecimal
Hardware
MC9S12C32 Microcontroller
HD44780U LCD
Pushbuttons (x4)
Schematic
Operation
Arithmetic Operations
– Enter the first number
– Press desired operator button
– Enter the second number
– Press any operator button to display result
Base Conversions
– Enter the number
– Press desired operator (binary, hex)
– Result displayed automatically
Software
CodeWarrior IDE
– Initialization of LCD
– Arithmetic calculations and base conversions
– Display of input and output numbers on LCD
Flowchart
Initialization
• I/O Ports
• Port T
•
DDRT = 0x3f for LCD use
•
•
•
Defines direction of digital I/O on port AD
ATDDIEN = 0x6a
•
• Port M
•
All high impedance inputs
Number Input
• Waits for a user input
• Uses getkey() function for keypad input
• Replaced PTT with
• Key strokes are
placed in an array a[i]
Number input (continued)
• However, numbers input need to be placed in
a variable with the correct value
• Example:
If the user was to input a 1, 2, and 7:
a[] = [1, 2, 7, 0 . . . 0], i=3
We would desire the value of our variable to be 127.
• Need code to implement:
“one” = a[i-1]*(10^0) + a[i-2]*(10^1) +….+a[0]*(10^i)
Number input (continued)
• Accomplished by using:
• Note:
• Loop counter i is incremented during the number
input loop, thus if 3 numbers were entered, i=3
Operations
• Addition (0x2b, ‘+’), subtraction (0x2d, ‘-’),
multiplication (0x2a, ‘*’), and division (0x2f, ‘/’)
• Push buttons read from PTM pins going high
• To binary (0x62, ‘b’), To hex (0x78, ‘x’)
• On keypad, buttons * and #
• This skips the entry of a second number
• ASCII value is assigned to char variable “op”
Operations (continued)
• Once variables “one” and “two” have been
entered, they are operated on accordingly
• Operations done according to value assigned to
the op variable
• Results are placed in the integer variable “result”
Binary and Hex Conversions
For Binary:
log[ ] =
{32768, 16384,
8192, 4096, 2048,
1024, 512, 256, 128,
64, 32, 16, 8, 4, 2, 1}
For Hex:
log[ ] =
{4096, 256, 16, 1}
Possible Improvements
Provide option for logic operations (AND, OR,
XOR, NOT)
Implement keypad with a larger quantity of