volatile static unsigned long operator_sign=0,d=0;
volatile static long i=0,y=0;
volatile char buffer[20];
void unsigned_long_to_string(unsigned long num,char *buffer);
#include "suryaa.h"
void setup()
{
pin_configure();
init_lcd();
display_welcome_message();
display_calculator_features();
display_instruction_manual();
display_start_message();
}
void loop()
{
init2_lcd();
volatile unsigned long a=0,b=0,c=0,m;
volatile float x=0.00;
a=digit_press1();
for(m=0;m<50000;m++);
if(i <= 5)
{
for(m=0;m<50000;m++);
b=digit_press2();
if(operator_sign==1)
{
c=a+b;
// sprintf(buffer, "%lu", c);
unsigned_long_to_string(c,buffer);
write_string(buffer);
clear_buffer();
}
else if(operator_sign==5)
{
out_data(0x01);
lcd_control_write();
out_data(0x80);
lcd_control_write();
write_string("out_of_bound..!!");
out_data(0xc0);
lcd_control_write();
write_string("press[*]=> RESET");
}
else if(operator_sign==2)
{
if(a>b)
{
c=a-b;
unsigned_long_to_string(c,buffer);
write_string(buffer);
clear_buffer();
}
else if(a==b)
{
unsigned_long_to_string(c,buffer);
write_string(buffer);
clear_buffer();
}
else
{
c=b-a;
write_string("-");
unsigned_long_to_string(c,buffer);
write_string(buffer);
clear_buffer();
}
}
else if(operator_sign==3)
{
c=a*b;
unsigned_long_to_string(c,buffer);
write_string(buffer);
clear_buffer();
}
else if(operator_sign==4)
{
x=(float)a/(float)b;
dtostrf(x, 4, 2, buffer);
write_string(buffer);
clear_buffer();
write_string("(approx)");
}
volatile long k=0;
y=0;
i=0;
operator_sign=0;
check_reset();
for(k=0;k<50000;k++);
}
else
{
volatile long k=0;
i=0;
operator_sign=0;
out_data(0x01);
lcd_control_write();
out_data(0x80);
lcd_control_write();
write_string("out_of_bound..!!");
out_data(0xc0);
lcd_control_write();
write_string("press[*]=> RESET");
for(k=0;k<50000;k++);
check_reset();
}
}