可以常规运算和开根,解方程,和算二阶矩阵,代码挺简单的
Altium Designer画的原理图和PCB图如下:(51hei附件中可下载工程文件)
单片机源程序如下:
- #include<reg52.h>
- #include<math.h>
- typedef unsigned char uint8;
- typedef unsigned int uint16;
- sbit rs=P2^5;
- sbit rw=P2^6;
- sbit e=P2^7;
- sbit led=P3^7;
- sbit k4=P2^0;
- sbit k2=P2^1;
- sbit k3=P2^2;
- sbit k1=P2^3;
- sbit beep=P2^0;
- uint8 key,num;
- uint8 fuhao;
- uint8 flag;
- long a,b,c,d,f,g;
- uint8 k;
- uint8 biao;
- float n,x;
- int i,j=0;
- uint8 dat1[]={1,2,3,0x2b-0x30,
- 4,5,6,0x2d-0x30,
- 7,8,9,0x2a-0x30,
- 0,0x48+0x30,0x3d-0x30,0x2f-0x30 };
- void delay(uint16 i)
- {
- while(i--);
- }
- void lcdwrc(uint8 c)
- {
- delay(1000);
- rs=0;
- rw=0;
- e=0;
- P0=c;
- e=1;
- delay(1000);
- e=0;
- }
- void lcdwrd(uint8 dat)
- {
- delay(1000);
- rs=1;
- rw=0;
- e=0;
- P0=dat;
- e=1;
- delay(1000);
- e=0;
- rs=0;
- }
- void lcdinit()
- {
- delay(1500);
- lcdwrc(0x38);
- delay(500);
- lcdwrc(0x38);
- delay(500);
- lcdwrc(0x38);
- delay(500);
- lcdwrc(0x38);
- lcdwrc(0x08);
- lcdwrc(0x01);
- lcdwrc(0x06);
- lcdwrc(0x0c);
- key=0;
- num=0;
- flag=0;
- fuhao=0;
- a=0;
- b=0;
- c=0;
- d=0;
- biao=0;
- led=0;
- }
- void keyscan()
- {
-
- if(k1==0) //检测按键K1是否按下
- {
- delay(1000); //消除抖动 一般大约10ms
- if(k1==0) //再次判断按键是否按下
- {
- k=0;
- lcdwrc(0x4f+0x80);
- lcdwrc(0x04);//设置光标左移,屏幕不移动
- c=(long)(((float)sqrt(a))*1000);
- while(c!=0) //一位一位显示
- {
- k++;
- lcdwrd(0x30+c%10);//显示结果的最后一位在0x4f的位置
- c=c/10;//取前面的结果数据
- //lcdwrd(0x3d);
-
- if(k==3)
- {
- lcdwrd(0x2e);
- k=0;
- }
- }
- lcdwrd(0x3d); //显示等于号=
-
- }
- while(!k1); //检测按键是否松开
- }
-
-
- if(k2==0)
- {
- delay(1000);
- if(k2==0)
- {
- j++;
- }
-
- if(j==1)
- {
- lcdwrd(0x50-0x30);
- flag=1;
- }
- if(j==2)
- {
- lcdwrc(0x40+0x80);
- flag=2;
- }
- if(j==3)
- {
- lcdwrd(0x50-0x30);
- flag=3;
- }
- if(j==4)
- {
-
- lcdwrc(0x4f+0x80);
- lcdwrc(0x04);
- c=(a*g)-(b*f);
- while(c!=0)
- {
- lcdwrd(0x30+c%10);
- c=c/10;
- }
- if((a*g)<(b*f))
- {
- lcdwrd(0x2d);
- }
- lcdwrd(0x3d);
- a=0;
- b=0;
- flag=0;
- fuhao=0;
-
-
- }
- while(!k2);
- }
-
-
-
- if(k3==0)
- {
- delay(1000);
- if(k3==0)
- {
-
- if(fuhao==1)//加
- {
- lcdwrc(0x4f+0x80);
- lcdwrc(0x04);//设置光标左移,屏幕不移动
- c=(long)(((float)b/a)*1000);
- //c=a+b;
- while(c!=0)
- {
- k++;
- lcdwrd(0x30+c%10);
- c=c/10;
- if(k==3)
- {
- lcdwrd(0x2e);
- k=0;
- }
- }
- lcdwrd(0x2d);
- lcdwrd(0x3d);
- lcdwrd(0x48+0x30);//显示x
- a=0;
- b=0;
- flag=0;
- fuhao=0;//全部清除为0
- }
- if(fuhao==2) //减
- {
- lcdwrc(0x4f+0x80);
- lcdwrc(0x04);
- /*if(a>b)
- c=a-b;
- else
- c=b-a;
- */
- c=(long)(((float)b/a)*1000);
- while(c!=0)
- {
- k++;
- lcdwrd(0x30+c%10);
- c=c/10;
- if(k==3)
- {
- lcdwrd(0x2e);
- k=0;
- }
- }
-
- /*if(a<b)
- {
- lcdwrd(0x2d); //显示-号
- }
- */
- lcdwrd(0x3d); //显示等于号=
- lcdwrd(0x48+0x30);//显示x
- a=0;
- b=0;
- flag=0;
- fuhao=0;//全部清除为0
- }
- }
- while(!k3);
- }
- if(k4==0) //检测按键K1是否按下
- {
- delay(1000); //消除抖动 一般大约10ms
- if(k4==0) //再次判断按键是否按下
- {
- lcdwrc(0x01); //清屏指令
- a=0;
- b=0;
- flag=0;
- fuhao=0;
-
- }
- while(!k4); //检测按键是否松开
- }
-
- P1=0xfe;
- if(P1!=0xfe)
- {
- delay(1000);
- if(P1!=0xfe)
- {
- key=P1&0xf0;
- switch(key)
- {
- case 0xe0: num=0;break; //1
- case 0xd0: num=1;break; //2
- case 0xb0: num=2;break; //3
- case 0x70: num=3;break; //加
- }
- }
- while(P1!=0xfe);
- if(num==0||num==1||num==2) //确认第一行的数1,2,3
- {
- if(flag==0) //没有按下符号键
- {
- //led=1;
- a=a*10+dat1[num];
- }
- if(flag==1)
- {
- //led=1;
- b=b*10+dat1[num];
- }
- if(flag==2)
- {
- f=f*10+dat1[num];
- }
- if(flag==3)
- {
- g=g*10+dat1[num];
- }
-
- }
- if(num==3)
- {
- //led=0;
- flag=1;
- fuhao=1;//加号+
- }
- lcdwrd(0x30+dat1[num]);
- }
- P1=0xfd; //令第二行为0
- if(P1!=0xfd)
- {
- delay(1000);
- if(P1!=0xfd)
- {
- key=P1&0xf0;
- switch(key)
- {
- case 0xe0: num=4;break; //4
- case 0xd0: num=5;break; //5
- case 0xb0: num=6;break; //6
- case 0x70: num=7;break; //减—
- }
- }
- while(P1!=0xfd);
- if(num==4||num==5||num==6)
- {
- if(flag==0) //没有按下符号键
- {
- //led=1;
- a=a*10+dat1[num];
- }
- if(flag==1)
- {
- //led=1;
- b=b*10+dat1[num];
- }
- if(flag==2)
- {
- f=f*10+dat1[num];
- }
- if(flag==3)
- {
- g=g*10+dat1[num];
- }
- }
- else
- {
- flag=1;
- fuhao=2;//带表减号
- }
- lcdwrd(0x30+dat1[num]);
- }
- P1=0xfb;
- if(P1!=0xfb)
- {
- delay(1000);
- if(P1!=0xfb)
- {
- key=P1&0xf0;
- switch(key)
- {
- case 0xe0: num=8;break; //7
- case 0xd0: num=9;break; //8
- case 0xb0: num=10;break; //9
- case 0x70: num=11;break; //乘*
- }
- }
- while(P1!=0xfb);
- if(num==8||num==9||num==10)
- {
- if(flag==0) //没有按下符号键
- {
- //led=1;
- a=a*10+dat1[num];
- }
- if(flag==1)
- {
- //led=1;
- b=b*10+dat1[num];
- }
- if(flag==2)
- {
- f=f*10+dat1[num];
- }
- if(flag==3)
- {
- g=g*10+dat1[num];
- }
- }
- else
- {
- flag=1;
- fuhao=3;//带表乘号*
- }
- lcdwrd(0x30+dat1[num]);
- }
- P1=0xf7;
- if(P1!=0xf7)
- {
- delay(1000);
- if(P1!=0xf7)
- {
- key=P1&0xf0;
- switch(key)
- {
- case 0xe0: num=12;break; //0
- case 0xd0: num=13;break; // x
- case 0xb0: num=14;break; //等号=
- case 0x70: num=15;break; //除/
- }
- }
- while(P1!=0xf7);
- switch(num)
- {
- case 12:
- if(flag==0) //没有按下符号键
- {
- //led=1;
- a=a*10+dat1[num];
- lcdwrd(0x30);
- }
- if(flag==1)
- {
- //led=1;
- b=b*10+dat1[num];
- lcdwrd(0x30);
- }if(flag==2)
- {
- f=f*10+dat1[num];
- lcdwrd(0x30);
- }
- if(flag==3)
- {
- g=g*10+dat1[num];
- lcdwrd(0x30);
- }
- break;
-
- case 13:
- lcdwrd(0x48+0x30);
-
- break;
-
- case 15:
-
- flag=1;
- fuhao=4;
- lcdwrd(0x2f);//除号/
- break;
-
- case 14:
- if(fuhao==1)//加
- {
- lcdwrc(0x4f+0x80);
- lcdwrc(0x04);
- c=a+b;
- while(c!=0) //一位一位显示
- {
- lcdwrd(0x30+c%10);//显示结果的最后一位在0x4f的位置
- c=c/10;
- }
- lcdwrd(0x3d); //显示等于号=
- a=0;
- b=0;
- flag=0;
- fuhao=0;//全部清除为0
- }
- if(fuhao==2) //减
- {
- lcdwrc(0x4f+0x80);
- lcdwrc(0x04);
- if(a>b)
- c=a-b;
- else
- c=b-a;
-
- while(c!=0) //一位一位显示
- {
- lcdwrd(0x30+c%10);//显示结果的最后一位在0x4f的位置
- c=c/10;
- }
-
- if(a<b)
- lcdwrd(0x2d); //显示-号
- lcdwrd(0x3d); //显示等于号=
- a=0;
- b=0;
- flag=0;
- fuhao=0;//全部清除为0
- }
- if(fuhao==3)//乘法
- {
- lcdwrc(0x4f+0x80);
- lcdwrc(0x04);
- c=a*b;
- while(c!=0)
- {
- lcdwrd(0x30+c%10);
- c=c/10;
- }
- lcdwrd(0x3d); //显示等于号=
- a=0;
- b=0;
- flag=0;
- fuhao=0;//全部清除为0
- }
- if(fuhao==3)//乘法
- {
- lcdwrc(0x4f+0x80);
- ……………………
- …………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码
所有资料51hei提供下载:
原理图和pcb.rar
(1.04 MB, 下载次数: 86)
|