PIC16f877 Based Simple Calculator Project
PIC16f877 Based Simple Calculator Project
project
1 Features of this calculator
2 Main function code
3 Notes and References
4 Downloads
5 About The Author
In the above figure, we can see that a result of “2+2=4” is shown on the screen. To achieve
this result, first press ‘2’ from the keypad. Then press ‘+’ and then press ‘2’ again. After that,
on pressing ‘=’ from the keypad the result ‘4’ is automatically displayed on the screen.
/* Name : main.c
* Date : 25-11-12
* * Revision : None
*/
#include "Includes.h"
__CONFIG( FOSC_HS & WDTE_OFF & PWRTE_ON & CP_OFF & BOREN_ON
void main(void)
while(1)
//get numb1
key = GetKey();
num1 = get_num(key); // Get int number from char value, it checks for wrong input as
well
//get function
key = GetKey();
//get numb2
key = GetKey();
key = GetKey();
else
}
/*
*/
int num = 0;
switch(ch)
case 'C': ClearLCDScreen(); num = Error; break; //this is used as a clear screen
and then reset by setting error
return num;
if(chf=='C') //if clear screen then clear the LCD and reset
{
return 'e';
if( chf!='+' && chf!='-' && chf!='x' && chf!='/' ) //if input is not from allowed funtions
then show error
DispError(1);
return 'e';
{
ClearLCDScreen(); //clear display
switch(numb)
unsigned char TenthDigit = 0; //It will contain 10th position digit of numb
if(numb<0)
{
In the main code, firstly keypad and LCD are initialized. Then the code waits for the first
number[1] from the keypad. After getting this number LCD screen is cleared. And this number
is displayed on the LCD. After that, code waits for the function key [2] from the user. After
getting the function key, code waits for the second number [1] and then the equal sign. After
getting the equal sign, according to the desired function the result is calculated and
displayed on the screen.
[1]
You can give any single digit input from 0 to 9.
[2]
You can select any function i-e ‘+’ or ‘-‘ or ‘x’ or ‘/’.