Skip to content

BitterOcean/Calculator

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Calculator Awesome

A simple calculator which can perform Signed operations on 64bits numbers with max of two different math symbols or any number of operands but with the same math symbol.

Author : Maryam Saeedmehr

Language : C

Functionalities

  • Can perform (+,-,/,*) operations whether signed or unsigned.
  • Generic number of operands with only one math operation like (2225..) : the number of operands can be set before compilation in calculator_blocks.h in (MaxNumberOfOperands) macro
  • Only can handle two different math operations like 2*3+10 with priority.
  • Almost detecting the user mistyping and throw exception .

Requirement

For implementing this code yourself, You Need to install below applications :

The main Workflow of the program

This is just a general explaintion of what you will see in the code but the code is already commented when needed to be able to trace it

  • calculator.c contains globel flag which can contain state of the program flow inside the code in enum var as defined in calculator_blocks.h: enum StageFlag{Reset,StartPoint,AnalyzePoint,CalculatePoint,DisplayPoint,ErrorPoint}; and by that i cannot move to the next stage until i complete the previous stage correctly with a flag is set to the next value when sucess.

  • the next idea is that my uint8 KeyPad_getPressedKey(); returns one byte of data[0..9] but if the user enters 54578,how i convert it to valuable data to make operations on it? this is done using a simple math trick: * storing the keypad inputs in MyArr for instance * then taking the last element MYArr[len-1] + MyArr[len-2]*10 +..+MyArr[len-i]*PowerOf(10,i)= Valuable Number to use( it's deciaml number of base 10 :) )

  • When the application starts, i stored all the inputs coming from the user inside an array using GetData(); then i analyze it using Analyze() and seperate the operands in another array and the operations as well.

  • then i do the required operation in calculate(); then display if the input is valid.

  • Higher range number(greater than signed 32bits) weather inputs or a result won't display on the LCD correctly due to the limiation in itoa.c standard function, so i modifiy it to LCD_Signed_Int64_ToString function :) .

Step1 : Create the C code in Atmel Studio

Create a new project in the atmel studio and copy all files in the /Codes folder into your new project folder .

Step2 : Build your project

After you have built it , a Calculator.hex file will be created in your project's folder. This is the only thing you need to program your avr in the proteus.

Step3 : Create your circuit

Use proteus to emulate your circuit. Try to make it as I have done....

calculator_proteus

Step4 : Program Atmega32

To ptogram your microcontroler in the proteus , just double click on it and choose the .hex file and press OK !

Step5 : Enjoy It

EXC3_Q1

Files

Support

Reach out to me at one of the following places!

License

License