|
仿真负责人:岳红玲
进度:代码出错;
仿真时lcd板不能显示计算结果,只能显示算式;
问题: 现在代码基础上加上sprinf语句,编译报错
- #include<reg52.h>
- #define uchar unsigned char
- #define uint unsigned int
- sbit dula=P2^6;
- sbit wela=P2^7;
- sbit Icden=P1^2; // 液晶使能端 E
- sbit Icdrs=P1^4;
- sbit mh=P1^3;
- uint key;
- uint num,i;
- uchar table3[30];
- uchar table4[30]; //液晶数据命令选择端 RS
- uint table2[]={0x31,0x32,0x33,0x2b,
- 0x34,0x35,0x36,0x2d,
- 0x37,0x38,0x39,0x2a,
- 0x30,0x3d,0x01,0x2f}; //LCD显示
- void delay(uint xms)
- {uint i,j;
- for(i=xms;i>0;i--)
- for(j=110;j>0;j--);
- }
- void write_com(uchar com)
- {
- Icdrs=0;
- P0=com;
- delay(5);
- Icden=1;
- delay(5);
- Icden=0;
-
- }
- void write_data(uint data1)
- { Icdrs=1;
- P0=data1;
- delay(5);
- Icden=1;
- delay(5);
- Icden=0;
- }
- void init()
- { dula=0;
- wela=0;
- Icden=0;
- write_com(0x38);
- write_com(0x0c);
- write_com(0x06);
- write_com(0x01);
- }
- void ji_suan(void)
- { uint sum=0,shu=0,shu2=0,mer=1;
- double guo1=0,guo2=0,jie=0;
- for(num=0;num<30;num++)
- { if(table3[num]<='9'||table3[num]>='0')
- { sum=sum*10;
- sum=table3[num]-'0'; }
- else
- {table4[shu]=sum;
- shu=shu+1;
- table4[shu]=table3[num];
- shu++;
- }
- }
- for(shu2=0;shu2<shu;shu2++)
- {
- if(table4[shu2]=='*')
- { if(mer==1)
- {
- guo1=table4[shu2-1]-'0';
- guo2=table4[shu2+1]-'0';
- jie=guo1*guo2;
- }
- else {
- guo1=table4[shu2+1]-'0';
- jie=jie*guo1;
- }
- }
- if(table4[shu2]=='/')
- { if(mer==1)
- {
- guo1=table4[shu2-1]-'0';
- guo2=table4[shu2+1]-'0';
- jie=guo1/guo2;
- }
- else {
- guo1=table4[shu2+1]-'0';
- jie=jie/guo1;
- }
- }
- if(table4[shu2]=='+')
- { if(mer==1)
- {
- guo1=table4[shu2-1]-'0';
- guo2=table4[shu2+1]-'0';
- jie=guo1+guo2;
- }
- else {
- guo1=table4[shu2+1]-'0';
- jie=jie+guo1;
- }
- }
- if(table4[shu2]=='-')
- { if(mer==1)
- {
- guo1=table4[shu2-1]-'0';
- guo2=table4[shu2+1]-'0';
- jie=guo1*guo2;
- }
- else {
- guo1=table4[shu2+1]-'0';
- jie=jie-guo1;
- }
- }
- } //计算完成
- write_data(jie); //输出函数
- }
- void matrixkeyscan()
- { uchar temp;
- P3=0xfe;
- temp=P3;
- temp=temp&0xf0;
- if(temp!=0xf0)
- { delay(10);
- temp=P3;
- temp=temp&0xf0;
- if(temp!=0xf0)
- {temp=P3;
- switch(temp)
- {case 0xee: key=0;table3[i]='1';break;
- case 0xde: key=1;table3[i]='2';break;
- case 0xbe: key=2;table3[i]='3'; break;
- case 0x7e: key=3;table3[i]='+';break;}
- while(temp!=0xf0)
- { temp=P3;
- temp=temp&0xf0;
- }
- write_data(table2[key]);
- }
- }
- P3=0xfd;
- temp=P3;
- temp=temp&0xf0;
- if(temp!=0xf0)
- { delay(10);
- temp=P3;
- temp=temp&0xf0;
- if(temp!=0xf0)
- {temp=P3;
- switch(temp)
- {case 0xed: key=4;table3[i]='4';break;
- case 0xdd: key=5;table3[i]='5';break;
- case 0xbd: key=6;table3[i]='6';break;
- case 0x7d: key=7;table3[i]='-';break;}
- while(temp!=0xf0)
- { temp=P3;
- temp=temp&0xf0;
- }
- write_data(table2[key]);
- }
- }
- P3=0xfb;
- temp=P3;
- temp=temp&0xf0;
- if(temp!=0xf0)
- { delay(10);
- temp=P3;
- temp=temp&0xf0;
- if(temp!=0xf0)
- {temp=P3;
- switch(temp)
- {case 0xeb: key=8;table3[i]='7';break;
- case 0xdb: key=9;table3[i]='8';break;
- case 0xbb: key=10;table3[i]='9';break;
- case 0x7b: key=11;table3[i]='*';break;}
- while(temp!=0xf0)
- { temp=P3;
- temp=temp&0xf0;
- }
- write_data(table2[key]);
- }
- }
- P3=0xf7;
- temp=P3;
- temp=temp&0xf0;
- if(temp!=0xf0)
- { delay(10);
- temp=P3;
- temp=temp&0xf0;
- if(temp!=0xf0)
- {temp=P3;
- switch(temp)
- {case 0xe7: key=12;table3[i]='0';write_data(table2[key]);break;
- case 0x77: key=15;table3[i]='/';write_data(table2[key]);break;}
- if(temp!=0xf0)
- {temp=P3;
- if(temp==0xb7)
- { key=13;
- write_com(0x10);
- write_data(0x20);
- write_com(0x10);
- i=i-3; }
- if(temp==0xd7)
- {key=14;
- ji_suan();
- i=-1; }
- while(temp!=0xf0)
- { temp=P3;
- temp=temp&0xf0;
- }
-
- } write_com(0x06);
- }
-
-
- }}
- void main()
- { mh=0;init();write_com(0x80);
- while(1){
- matrixkeyscan();
- delay(5);
- i++;
-
-
-
- }}
-
复制代码
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?立即注册
x
|