Professional Documents
Culture Documents
LAB PROJECT
Submitted by:
Ch. Avinash teja(1601-16-735-327)
Durgam Lalith(1601-16-735-329)
B.Kiran kumar(1601-16-735-331)
Introduction:
The calculator we are going to design is quite basic calculator, it will
only perform 4 tasks, which are as follows:
o 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.
o When you press (-) button it will subtract the two digits like 3 – 2
= and it will give you the result.
o When you press (x) button it will multiply the two digits.
o When you press the (/) button it will simply divide the two digits.
Flow chart:
start
YES
NO
Key =
function
v YES
NO Key
=num
YES
NO Key
=equal
YES
v
stop
Proteus Simulation
So, you can see we have used the same LCD which is 20×4 and have
used the same keypad.
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
#include<reg51.h>
#include<string.h> //Define Macros
#define Error 13 // Any value other than 0 to 9 is good
// Define Pins
sbit RowA = P1^0; //RowA
sbit RowB = P1^1; //RowB
sbit RowC = P1^2; //RowC
sbit RowD = P1^3; //RowD
// Main program
//
int main(void)
{
char key; //key char for keeping record of pressed key
int num1 = 0; //First number
char func = '+'; //Function to be performed among two num
int num2 = 0; //Second number
void DisplayTitle()
{
writecmd(0x95);
writedata('M'); //write
writedata('P'); //write
writedata('M'); //write
writedata('C'); //write
writedata('_'); //write
writedata('M'); //write
writedata('I'); //write
writedata('N'); //write
writedata('I'); //write
writedata('-'); //write
writedata('P'); //write
writedata('R'); //write
writedata('O'); //write
writedata('J'); //write
writedata('E'); //write
writedata('C'); //write
writedata('T'); //write
writedata('.'); //write
writecmd(0xd8);
writedata('E'); //write
writedata('C'); //write
writedata('E'); //write
writedata('-'); //write
writedata('C'); //write
writedata('B'); //write
writedata('I'); //write
writedata('T'); //write
writedata('.'); //write
writecmd(0x80);
}
void cct_init(void)
{
P0 = 0x00; //not used
P1 = 0xf0; //used for generating outputs and taking inputs from
Keypad
P2 = 0x00; //used as data port for LCD
P3 = 0x00; //used for RS and E
}
void delay(int a)
{
int i;
for(i=0;i<a;i++); //null statement
}
void writedata(char t)
{
RS = 1; // This is data
P2 = t; //Data transfer
E = 1; // => E = 1
delay(150);
E = 0; // => E = 0
delay(150);
}
void writecmd(int z)
{
RS = 0; // This is command
P2 = z; //Data transfer
E = 1; // => E = 1
delay(150);
E = 0; // => E = 0
delay(150);
}
void lcdinit(void)
{
///////////// Reset process from datasheet /////////
delay(15000);
writecmd(0x30);
delay(4500);
writecmd(0x30);
delay(300);
writecmd(0x30);
delay(650);
/////////////////////////////////////////////////////
writecmd(0x38); //function set
writecmd(0x0c); //display on,cursor off,blink off
writecmd(0x01); //clear display
writecmd(0x06); //entry mode, set increment
}
char READ_SWITCHES(void)
{
RowA = 0; RowB = 1; RowC = 1; RowD = 1; //Test Row A
if( chf!='+' && chf!='-' && chf!='x' && chf!='/' ) //if input is not
from allowed funtions then show error
{
DispError(1);
DisplayTitle();
return 'e';
}
if(numb<0)
{ 8
numb = -1*numb; // Make number positive
writedata('-'); // Display a negative sign on LCD
}