51单片机简易计算器程序

  • 格式:docx
  • 大小:18.40 KB
  • 文档页数:11

下载文档原格式

  / 11
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
uchar code table[] = {0xc0,0xf9,0xa4,0xb0,0x99,
0x92,0x82,0xf8,0x80,0x90,0xff};
uchar dbuf[8] = {10,10,10,10,10,10,10,10};
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
uchar keyscan()
{
uchar skey;
P1 = 0xfe;
while((P1 & 0xf0) != 0xf0)
{
delay(3);
while((P1 & 0xf0) != 0xf0)
{
switch(P1)
{
case 0xee: skey = '7'; break;
operand2[cut2+1] = '\0';
value2 = atoi(operand2);
cut2++;
buf(value2);
disp();
break;
default: break;
}
}
else if(ckey=='+'||ckey=='-'||ckey=='*'||ckey=='/')
{
bool = 1;
case '-' : value = va1-va2; break;
case '*' : value = va1*va2; break;
case '/' : value = va1/va2; break;
default : break;
}
return value;
}
void buf(uint val)
#include <</font>reg51.h>#include <</font>intrins.h>
#include <</font>ctype.h>
#include <</font>stdlib.h>
#define uchar unsigned char
#define uint unsigned int
bsel=0x01;
for(n=0;n<</font>8;n++)
{
P2=bsel;
P0=table[dbuf[n]];
bsel=_crol_(bsel,1);
delay(3);
P0=0xff;
}
}
{
if(isdigit(ckey))
{
switch(bool)
{
case 0:
operand1[cut1] = ckey;
operand1[cut1+1] = '\0';
value1 = atoi(operand1);
cut1++;
buf(value1);
disp();
break;
case 1:
operand2[cut2] = ckey;
operator = ckey;
buf(0);
dbuf[7] = 10;
disp();
}
else if(ckey == '=')
{
value = compute(value1,value2,operator);
buf(value);
disp();
while(1)
{
ckey = keyscan();
if(ckey == '$')
case 0xde: skey = '8'; break;
case 0xbe: skey = '9'; break;
case 0x7e: skey = '/'; break;
default: skey = '#';
}
while((P1 & 0xf0) != 0xf0)
;
}
}
P1 = 0xfd;
while((P1 & 0xf0) != 0xf0)
goto init;
else
{
buf(value);
disp();
}
}
}
else if(ckey == '$')
{ goto init;}
}
disp();
}
}
uint compute(uint va1,uint va2,uchar optor)
{
uint value;
switch(optor)
{
case '+' : value = va1+va2; break;
{
uchar i;
if(val == 0)
{
dbuf[7] = 0;
i = 6;
}
else
for(i = 7; val > 0; i--)
{
dbuf[i] = val % 10;
val /= 10;
}
for( ; i > 0; i--)
dbuf[i] = 10;
}
void disp(void)
{
uchar bsel, n;
default: skey = '#';
}
while((P1 & 0xf0) != 0xf0)
;
}
}
return skey;
}
void main()
{
uint value1, value2, value;
uchar ckey, cut1 = 0, cut2 = 0;
uchar operator;
uchar i, bool = 0;
{
delay(3);
while((P1 & 0xf0) != 0xf0)
{
switch(P1)
{
case 0xe7: skey = '$'; break;
case 0xd7: skey = '0'; break;
case 0xb7: skey = '='; break;
case 0x77: skey = '+'; break;
case 0xdb: skey = '2'; break;
case 0xbb: skey = '3'; break;
case 0x7b: skey = '-'; break;
default: skey = '#';
}
while((P1 & 0xf0) != 0xf0)
;
}
}
P百度文库 = 0xf7;
while((P1 & 0xf0) != 0xf0)
{
delay(3);
while((P1 & 0xf0) != 0xf0)
{
switch(P1)
{
case 0xed: skey = '4'; break;
case 0xdd: skey = '5'; break;
case 0xbd: skey = '6'; break;
case 0x7d: skey = '*'; break;
uchar operand1[9], operand2[9];
uchar operator;
void delay(uint);
uchar keyscan();
void disp(void);
void buf(uint value);
uint compute(uint va1,uint va2,uchar optor);
init:
buf(0);
disp();
value = 0;
cut1 = cut2 = 0;
bool = 0;
for(i = 0;i <</font> 9;i++)
{
operand1[i] = '\0';
operand2[i] = '\0';
}
while(1)
{
ckey = keyscan();
if(ckey != '#')
default: skey = '#';
}
while((P1 & 0xf0) != 0xf0)
;
}
}
P1 = 0xfb;
while((P1 & 0xf0) != 0xf0)
{
delay(3);
while((P1 & 0xf0) != 0xf0)
{
switch(P1)
{
case 0xeb: skey = '1'; break;