想做一个简易计算器,但是程序遇到点问题,只会写扫描函数 显示函数和运算函数不懂。求大神给个思路。下面是我写的一点程序,希望大神能指点一下!附件中有原理图!!!!!!!!!!!!
#include<reg51.h>
#include<intrins.h>
#include<math.h>
#define uint unsigned int
#define uchar unsigned char
sbit LSA=P2^2; //138译码器控制数码管位选
sbit LSB=P2^3;
sbit LSC=P2^4;
#define smg P0 //P0控制数码管段选
#define key P1 //P1控制矩阵键盘
uint x,i,j;
void ys(x) //延时函数
{
for(i=x;i>0;i--)
for(j=110;j>0;j--);
}
uint code sz[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71}; //共阴数组
void jzaj() //扫描函数
{
key=0x7f;
if(key!=0x7f)
{
ys(10);
if(key!=0x7f)
{
switch(key)
{
case(0x77):x=1;break;
case(0x7b):x=2;break;
case(0x7d):x=3;break;
case(0x7e):ysfh=1;break;
}
while(key!=0x7f);
}
}
key=0xbf;
if(key!=0xbf)
{
ys(10);
if(key!=0xbf)
{
switch(key)
{
case(0xb7):x=4;break;
case(0xbb):x=5;break;
case(0xbd):x=6;break;
case(0xbe):ysfh=2;break;
}
while(key!=0xbf);
}
}
key=0xdf;
if(key!=0xdf)
{
ys(10);
if(key!=0xdf)
{
switch(key)
{
case(0xd7):x=7;break;
case(0xdb):x=8;break;
case(0xdd):x=9;break;
case(0xde):ysfh=3;break;
}
while(key!=0xdf);
}
}
key=0xef;
if(key!=0xef)
{
ys(10);
if(key!=0xef)
{
switch(key)
{
case(0xe7):gl=1;break;
case(0xeb):x=0;break;
case(0xed):dy=1;break;
case(0xee):ysfh=4;break;
}
while(key!=0xef);
}
}
}
|