1个回答
展开全部
#include <AT89X52.H>
#include <intrins.h>
#include "lcd_drive.h"
#define uchar unsigned char
#define uint unsigned int
void main()
{
uint key();
void deplay(uchar j_p);
void deplay_s(long a);
uchar i=1;
uchar jp=-1;
uchar flat;
uint a,b;
delay_ms(10);
lcd_init();
lcd_clr();
lcd_wcmd(0x80);
while(1)
{
while(jp==-1)
jp=key();
deplay(jp);
switch (jp)
{
case '=': switch(flat)
{
case '+': a+=b; deplay_s(a); break;
case '-': a=b-a; deplay_s(a); break;
case '*': a*=b; deplay_s(a); break;
case '/': a=b/a; deplay_s(a); break;
default:break;
}
break;
case '+':flat='+';b=a;i=0;break;
case '-':flat='-';b=a;i=0;break;
case '*':flat='*';b=a;i=0;break;
case '/':flat='/';b=a;i=0;break;
case 'c':a=0;b=0;lcd_clr();break;
case 0:
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
case 8:
case 9:a=a*10*i+jp;i=1;break;
}
jp=-1;
}
}
//-------矩阵键盘扫描-------
uint key()
{
uchar h = 0,l = 0;//矩阵行h,列l
uchar j_p;
P3 = 0x0f;
if(P3 != 0x0f)
{
delay_ms( 2 );
if(P3!=0x0f)
{
l = P3 & 0x0f ;
P3 = 0xf0;
h = P3 & 0xf0;
}
}
switch(l | h)
{
case 0x7e:j_p=0;break; //按键0
case 0x7d:j_p=1;break; //按键1
case 0x7b:j_p=2;break; //按键2
case 0x77:j_p=3;break; //按键3
case 0xbe:j_p=4;break; //按键4
case 0xbd:j_p=5;break; //按键5
case 0xbb:j_p=6;break; //按键6
case 0xb7:j_p=7;break; //按键7
case 0xde:j_p=8;break; //按键8
case 0xdd:j_p=9;break; //按键9
case 0xdb:j_p='+';break; //按键a
case 0xd7:j_p='-';break; //按键b
case 0xee:j_p='=';break; //按键Enter
case 0xed:j_p='*';break; //按键c
case 0xeb:j_p='/';break; //按键e
case 0xe7:j_p='c';break; //按键取消
default:return -1;break;
}
P3=0x0f;
while(P3!=0x0f);
return j_p;
}
void deplay(uchar j_p)
{
if(j_p != -1)
{
if(j_p >= 0 && j_p <= 9)
j_p+=48;
lcd_wdat(j_p);
}
}
void deplay_s(long a)
{
int n[10];
uint i=0;
while(a)
{
n[i]=a%10;
a/=10;
i++;
}
while(i)
deplay(n[--i]);
}
#include <intrins.h>
#include "lcd_drive.h"
#define uchar unsigned char
#define uint unsigned int
void main()
{
uint key();
void deplay(uchar j_p);
void deplay_s(long a);
uchar i=1;
uchar jp=-1;
uchar flat;
uint a,b;
delay_ms(10);
lcd_init();
lcd_clr();
lcd_wcmd(0x80);
while(1)
{
while(jp==-1)
jp=key();
deplay(jp);
switch (jp)
{
case '=': switch(flat)
{
case '+': a+=b; deplay_s(a); break;
case '-': a=b-a; deplay_s(a); break;
case '*': a*=b; deplay_s(a); break;
case '/': a=b/a; deplay_s(a); break;
default:break;
}
break;
case '+':flat='+';b=a;i=0;break;
case '-':flat='-';b=a;i=0;break;
case '*':flat='*';b=a;i=0;break;
case '/':flat='/';b=a;i=0;break;
case 'c':a=0;b=0;lcd_clr();break;
case 0:
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
case 8:
case 9:a=a*10*i+jp;i=1;break;
}
jp=-1;
}
}
//-------矩阵键盘扫描-------
uint key()
{
uchar h = 0,l = 0;//矩阵行h,列l
uchar j_p;
P3 = 0x0f;
if(P3 != 0x0f)
{
delay_ms( 2 );
if(P3!=0x0f)
{
l = P3 & 0x0f ;
P3 = 0xf0;
h = P3 & 0xf0;
}
}
switch(l | h)
{
case 0x7e:j_p=0;break; //按键0
case 0x7d:j_p=1;break; //按键1
case 0x7b:j_p=2;break; //按键2
case 0x77:j_p=3;break; //按键3
case 0xbe:j_p=4;break; //按键4
case 0xbd:j_p=5;break; //按键5
case 0xbb:j_p=6;break; //按键6
case 0xb7:j_p=7;break; //按键7
case 0xde:j_p=8;break; //按键8
case 0xdd:j_p=9;break; //按键9
case 0xdb:j_p='+';break; //按键a
case 0xd7:j_p='-';break; //按键b
case 0xee:j_p='=';break; //按键Enter
case 0xed:j_p='*';break; //按键c
case 0xeb:j_p='/';break; //按键e
case 0xe7:j_p='c';break; //按键取消
default:return -1;break;
}
P3=0x0f;
while(P3!=0x0f);
return j_p;
}
void deplay(uchar j_p)
{
if(j_p != -1)
{
if(j_p >= 0 && j_p <= 9)
j_p+=48;
lcd_wdat(j_p);
}
}
void deplay_s(long a)
{
int n[10];
uint i=0;
while(a)
{
n[i]=a%10;
a/=10;
i++;
}
while(i)
deplay(n[--i]);
}
追问
不对啊
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
111
2024-12-20 广告
2024-12-20 广告
在对很多的顾客来说,他们都是比较新鲜的事物,并且带有着比较好的性能。而工业级lcd显示屏就是在大家能够发现的产品中来不断体会到的,从而利用到工业中也会尽可能地发现到它能够发挥出来的功能。...
点击进入详情页
本回答由111提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询