pcbway




design calculator with 8051 microcontroller,calculator with 8051, calculator design 8051,8051 calculatorHello friends, today’s post is about designing a simple calculator with 8051 Microcontroller. In our previous post, we have seen How to Interface keypad with 8051 Microcontroller in Proteus ISIS. Moreover, we have also worked on Interfacing of LCD with 8051 Microcontroller in Proteus ISIS. If you haven’t read these two posts then my suggestion is to read them first before going into the details of this post, as we are going to use both keypad and LCD in order to design the simple calculator with 8051 Microcontroller.

Actually we have already understood the working of both keypad and LCD so I thought to share this small project as it will give you the practical application of both keypad and LCD. And if you are new to 8051 Microcontroller then its always better to first design a small project and then move to pro one. The Simulation file along with hex file and complete code is given at the end for download. But my suggestion is to design it by yourself as it will help you in learning. You will do mistakes but obviously it will help you in learning so make mistakes and learn with it. So, let’s get started with it.

Design a Simple Calculator with 8051 Microcontroller

  • The calculator we are going to design in this post is quite basic calculator, it will only perform 4 tasks, which are as follows:
    • When you press the (+) button then it will add the two digits. For example, you want to add 2 and 3 then you need to press 2 + 2 = these four buttons in sequence and when you press the = button it will automatically will give you the sum.
    • When you press (-) button it will subtract the two digits like 3 – 2 = and it will give you the result.
    • When you press (x) button it will multiply the two digits.
    • When you press the (/) button it will simply divide the two digits.
  • Whenever you press the (=) button, it will give you the output depending on the function you used before and if you press (=) in the start then it will give “Wrong Input”.
  • Finally, there’s (ON/C) button on the Calculator, when you press this it will simply reset the code and will clear the LCD.
  • So, that’s how this calculator is gonna work. Moreover, it will always reset when you try to calculate new value.
  • As its a simple calculator, so its only limited to 1 digit, means it will only apply the operation on single digit input like 2+3 but it won’t work on more than 1 digit like 12 + 13.
  • I will soon design a more complicated calculator but for this one its only limited to single digit.
  • So, now let’s design this calculator, so first we are gonna have a look at the Proteus simulation of Simple calculator with 8051 Microcontroller.
  • After that, we will do the coding part for calculator with 8051 Microcontroller.
  • So, now let’s get started with Proteus Simulation.
Proteus Simulation

keypad with 8051,keypad lcd 8051, display keypad on lcd with 8051,keypad lcd 8051, keypad values on lcd 8051 microcontroller, keypad on lcd 8051

  • So, you can see we have used the same LCD which is 20×4 and have used the same keypad as did in previous tutorial.
  • You can see this keypad has all the required operations for this project which are (+), (-), (x) and (/).
  • So, now let’s have a look at the programming code for calculator with 8051 Microcontroller.
Programming Code
  • We have already seen the programming code for keypad and LCD and I am assuming that you have also read those posts so I am not going into the details of those posts.
  • So,we know that how to print data on LCD and we are also aware of how to get key press from keypad and then display it on LCD.
  • So, now let’s move on to adding these functions.

  • As you can see in the above function, I have first check for the first key press.
  • When you pressed the first key on keypad then I get this key and converter it to integer.
  • After that I waited for the next key which must be some operation key like + – X or / otherwise it will generate the error message.
  • After that code is waiting for the third key which should be some numerical digit and then I converter it to integer again and if you entered some invalid key then it will generate the error.
  • Finally waiting for the = sign. When you press the = sign it will automatically perform the required operation which I placed in the switch case loop.
  • It will calculate the value and then print out the result and on next key press it will first clear the screen and then get the value and will continue.
  • Below is the detailed code for the project with comments and I hope you wont get into any trouble and will get it clearly.

  • The above code is quite self explanatory and the main part I have already explained but still if you get into any troubled then ask in comments and I will resolve them.
  • Now copy this code in your keil uvision 3 and get the hex file.
  • Upload your hex file in Proteus ISIS and run your simulation.
  • The first screen you will get is as follows, which obviously displays our website address 😛

design calculator with 8051 microcontroller,calculator with 8051, calculator design 8051,8051 calculator




  • Now, let’s add 3 + 5 and we will get as shown in below figure:

design calculator with 8051 microcontroller,calculator with 8051, calculator design 8051,8051 calculator

  • Next operation, we are gonna do is the subtract one, so lets do this operation 3-9 = , shown below:

design calculator with 8051 microcontroller,calculator with 8051, calculator design 8051,8051 calculator

  • Now, lets do the third operation which is multiplication, so let’s do this operation 9×9, shown below:

Design a Simple Calculator with 8051 Microcontroller

  • Now, finally do the last operation which is division, so I did 6/3 and result is shown below:

design calculator with 8051 microcontroller,calculator with 8051, calculator design 8051,8051 calculator

  • So, all the operations are shown in above figures, now if you give it wrong number like 2 digit number then it will display error message, as shown below:

design calculator with 8051 microcontroller,calculator with 8051, calculator design 8051,8051 calculator

  • It has become quite a lengthy post, so let’s have the ending part. 🙂
  • You can download the Proteus Simulation along with hex file and code by clicking the below button.

Download Proteus Simulation and Code



So, that’s all with the designing of simple Calculator with 8051 Microcontroller. I will try to work on advanced calculator, if I got time but I am not sure of that. 🙂 So, that’s all for today and will meet in next tutorial soon. till than have fun. !!! 🙂

1 Comment

  1. How to convert it into a 3 digit calculator? what change in the c code should we make? One other thing is that it is totally an integer calculator, what if it is to be converted into a floating point number calculator?

Leave a Reply

Your email address will not be published. Required fields are marked *

Post comment