Software Design

By pushing button Home, the calculator is in Calculator mode.  Users can do arithmetic operations. By pushing button Graph, the calculator is in Graphing mode.  Users can enter functions are plot functions.  This function is handled in function Keypad1().  Whenever button Home is pushed, variable screen_flag is set to 1, indicating that the calculator is in Calculator mode, and it also clears the screen and writes the current stack on the screen.  If the button Graph is pushed, variable screen_flag is set to 2, indicating that the calculator is in Graphing mode, and it also clears the screen and plots the XY-axis on the screen.

Manipulating Calculator Stack:

The stack in the calculator mode is maintained with an array of float.  We used a float variable named input to keep track of the current input.  Whenever a keypad number is pressed, input gets updated, in function Keypad1(). when user pressed the enter key, then input gets pushed onto the stack in function CommandHandler().  If one of the other function buttons are pushed, CommandHandler manipulates the stack accordingly.  Each functionality is assigned to a constant number.  When a button is pushed, that button's functionality number is assigned to a variable named command.  In CommandHandler, the value of command is checked to determine the functionality of the button pushed.

Manipulating Function Inputs:

The function is recorded in a stack struction.  Each stack element is of type function.  Type function consists of thress fields: coeff1, coeff2 and type.  Every basic function can be represented with these three parameters =>  coeff1*function_type(coeff2*x).  function_type in here could be sine, cosine, or exp.  Polynomials can be represented by coeff1*x^(coeff2).  In here, the function_type is polynomial.  So, only three parameters are needed to represent a basic function.  Each element of the function stack is one of these basic functions.  The whole stack is the user input of the linear combination of the these basic functions.  Inputs are handled in function Keypad2().  Users has to enter the function in a certain order.  First coeff1 is entered, then the function type, then coeff2, then indicator end of function, then either + to add another function, or Enter to plot the function.  These steps are handled in function Keypad2(), and the variable fState is used to keep track of which part of the function that user is currently entering.

Graphing functions:

When the Enter key is pressed, function CommandHandler() set display_flag = 1, indicating plotting function.  Function graphFunction() is called.  In graphFunction(), a pre-defined number of points are calculated.  X coordinate starts from Xmin, ends at Xmax.  Y coordinate is calculated for every X coordinate.  And every two pairs of XY-coordinates are send to function graphLine() to graph a line between the coordinates.  To optimize for speed, all the points outside the range of Ymin to Ymax are not plotted.

Display:

Whenever the user changes the input, manipulating the stack, entering a function, or plotting a function, display function is called to update the LCD display.  The following is a flow chart of the display function.

Main functions:

Handles numerical input.

Handles functionality input.

CommandHandler()

This function looks at the global variable called command, and determines what the user wants to do, and does it.

Display()

Updates the LCD screen with the current information

GraphFunction()

Plots function onto LCD screen.