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
- 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 .
For implementing this code yourself, You Need to install below applications :
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 inMyArr
for instance * then taking the last elementMYArr[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 usingAnalyze()
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 toLCD_Signed_Int64_ToString
function :) .
Create a new project in the atmel studio and copy all files in the /Codes
folder into your new project folder .
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.
Use proteus to emulate your circuit. Try to make it as I have done....
To ptogram your microcontroler in the proteus , just double click on it and choose the .hex file and press OK !
/Codes
: This is the main folder consists of :/Codes/SourceCodes/std_types.h
: Contains new types of standards data types/Codes/calculator_blocks.h
: Contains the configuarion you set to how much the calculator can handle number of operands,operation/Codes/calculator_blocks.c
: Contains the main work of the calculator as will be explain later/Codes/Calculator.c
: the main of the application/Codes/SourceCodes/lcd.c
: normal c driver/Codes/SourceCodes/keypad.c
: normal c driver
/Calculator.pdsprj
: Simulation file using proteus/LICENSE
: The license of this project
Reach out to me at one of the following places!
- Telegram at @BitterOcean
- Gmail at [email protected]