One digit Calculator project
It is a simple one digit calculator. You can add ,multiply ,subtract and divide two single digits using this calculator. Design is very simple but coding is ,as always rather complex. Proteus design and code is given below:
Matarial
- 89c52 microcontroller
- LCD Display 16 by 2
- A 4x4 Keypad
- IC 7805
#include<AT89x52.h>
sbit RS=P1^0; //Register Select Pin on P1 ^0
sbit RW=P1^1 ; //Read or Write Select Pin on P1 ^1
sbit E=P1^2; //Enable Select Pin on P1 ^2
sbit BF=P2^7; //Busy Flag on MSB of Data Port
sbit colm1 =P3^4;
sbit colm2=P3^5;
sbit colm3=P3^6;
sbit colm4=P3^7;
sbit row1=P3^0;
sbit row2=P3^1 ;
sbit row3=P3^2;
sbit row4=P3^3;
int a=0;
int b=0;
int ans=0;
unsigned int tenth=0;
unsigned char unit=0;
unsigned char inc=0;
char plus=0;
char minus=0;
char multiply=0;
char divide;
int numb1;
int numb2;
char c[]={'0','1','2','3','4','5','6','7','8','9','E'};
char Opr[]={'+','-','/','x','.','='};
char cursorpos=0;
char data1;
int ready() //For checking that the LCD is ready or not?
{
char ch;
for(ch=0;ch<100;ch++);
return 1 ;
} //Ready Function Ends
void delay(unsigned int z) //For delay (Starts)
{
int x,y;
for(x=0;x<z;x++)
for(y=0;y<=1000;y++);
} //Delay Function Ends
int LCD_Run_Command(unsigned char COMMAND)
{
if(ready())
{
P2=COMMAND;
RS=0;delay(1);
RW=0;delay(1);
E=0;delay(1);
E=1;delay(1);
}
return 1 ;
}
void LCD_Show (char CHARACTER)
{
if(ready()) //if LCD internal controller is not busy
{
P2=CHARACTER;
RS=1;delay(1);
RW=0;delay(1);
E=0;delay(1);
E=1;delay(1);
}
}
void LCD_Initialize()
{
LCD_Run_Command(0x38); // 8 data lines, two lines, Font 5x7.
LCD_Run_Command(0x0E); // Display=ON, Curson=ON, Cursor Blonking=ON
LCD_Run_Command(0x01); // Clear display and return cursor to the home position
LCD_Run_Command(0x06); // During read/write operation only cursor (not text)
// should move right
}
/*************************Check Colum 1***************************/
void func_colm1()
{
row1=row2=row3=row4=1 ;
row1=0;
if(colm1==0)//1 is pressed
{
delay(50);
inc++;
if(inc==1)
{
//LCD_Run_Command(0xC0); // Cursor at Line 2, Position 0
a=1;
LCD_Show(c[1]);
LCD_Run_Command(0x06);//move cursor by one character
}

Comments
Post a Comment