51单片机计算器程序

  • 格式:docx
  • 大小:15.97 KB
  • 文档页数:6

下载文档原格式

  / 19
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
float a=0;
uint a1=0;
uint a2=0;
while(ch1[i]!='=')
{
if(ch1[i]!='+'&&ch1[i]!='-'&&ch1[i]!='*'&&ch1[i]!='/')
a2=ch1[i];
}
}*/
void counter()
{
uint a;
LcdInit();
while(1)
TR0=1;//启动定时
ET0=1;//启动中断
EA=1;
}
void delay_1s()
{
uchar h;
for(h=0;h<20;h++)
{delay_50ms();}
}*/
void delay(uchar i)
{
uchar h,t;
t=200;
for(h=0;h<i;h++)
{
while(t--);
{
scan();
if(S==1)break;
}
error();//cure
RPN();
a=ch1[0];
sprintf(show,"%d",a);
Display(0,1,show);
while(1);
}
void main()
{
counter();
}
k=k-2;
}
else if(ch1[k]=='*')
{
ch1[k-2]=ch1[k-2]*ch1[k-1];
k=k-2;
}
else if(ch1[k]=='/')
{
ch1[k-2]=ch1[k-2]/ch1[k-1];
k=k-2;
}
k++;f--;
}
}
}
}
/*void compute()
{
uchar i=0;
}
}
unsigned char up()
{
unsigned char P0Buf;
P0=0xf0;
delay(1);
P0Buf=P0;
return(P0Buf-0xf0);
}
void jilu()
{
uchar i;
for(i=0;i<16;i++)
{
if(KeyV==Key[i])
{
if(key1[i]=='=')S=1;
{
delay(3);
P0=0xf0;
P0Buf=P0;
if(P0Buf!=0xf0)
{
P0=0x0f;
P0Buf2=P0;
P0Buf=P0Buf+P0Buf2;
KeyV=P0Buf;
while(up());/*判断按键放开*/
jilu();
}
}
}
void error()
{
uchar i=0;
for(i=0;i<Y;i++)
uchar code key1[16]={//键位
1,2,3,'+',
4,5,6,'-',
7,8,9,'*',
'.',0,'=','/'
};
uchar code Key[16]=
{
0x77,0x7b,0x7d,0x7e,
0xb7,0xbb,0xbd,0xbe,
0xd7,0xdb,0xdd,0xde,
0xe7,0xeb,0xed,0xee,
};
uchar mode[17];
uchar show[16];
uint ch1[16];
/*void T0Server() interrupt 1
{
EA=0;
}
void delay_50ms()
{
TMOD=0x01;//定时器0方式1
TL0=0XAF;
TH0=0X3C;//50mS
if(Y>15)S=1;
show[Y]=show1[i];
mode[Y]=key1[i];
Display(0,0,show) ;
Y++; break;
}
}
}
void scan()
{
unsigned char P0Buf,P0Buf2;
KeyV=17;
P0=0xf0;
P0Buf=P0;
if(P0Buf!=0xf0)
k=k-2;
}
k++;
f-ห้องสมุดไป่ตู้;
if(show[f]=='=')a2=0;
if(show[f]=='+'||show[f]=='-')a2=1;
if(show[f]=='*'||show[f]=='/')a2=2;
}
f++;
show[f]=mode[Z];
}
}
else if(mode[Z]=='=')
{
if(show[f]=='=')break;
while(show[f]!='=')
{
ch1[k]=show[f];
if(ch1[k]=='+')
{
ch1[k-2]=ch1[k-2]+ch1[k-1];
k=k-2;
}
else if(ch1[k]=='-')
{
ch1[k-2]=ch1[k-2]-ch1[k-1];
uchar K=0;//错误标示
uchar Z=0;//扫描位
uchar S=0;//结束标志
uchar A=0;
uchar code show1[16]={
'1','2','3','+',//键位显示
'4','5','6','-',
'7','8','9','*',
'.','0','=','/'
};
#include<reg52.h>
#include<intrins.h>
#include<stdio.h>
#include"1602.h"
#include"math.h"
#define uchar unsigned char
#define uint unsigned int
uchar KeyV;
uchar Y=0;//长度
{
if(mode[i]>9&&mode[i+1]>9)
{K=1;
Display(0,1,"error");
while(1);
}
}
}
void l()
{
uint q=0;
while(mode[Z]>=0&&mode[Z]<=9)
{
q=q*10+mode[Z];
Z++;
}
Z--;
A=q;
}
void RPN()
{
uchar i=0;
uchar k=0,f=0;
uchar a1,a2;
show[0]='=';
a2=0;
for(Z=0;Z<Y;Z++)
{
f++;
show[f]=mode[Z];
a2=a1;
}
else
{
while(a1<=a2)
{
ch1[k]=show[f];
if(ch1[k]=='+')
{
ch1[k-2]=ch1[k-2]+ch1[k-1];
k=k-2;
}
else if(ch1[k]=='-')
{
ch1[k-2]=ch1[k-2]-ch1[k-1];
k=k-2;
}
else if(ch1[k]=='*')
{
ch1[k-2]=ch1[k-2]*ch1[k-1];
k=k-2;
}
else if(ch1[k]=='/')
{
ch1[k-2]=ch1[k-2]/ch1[k-1];