#include <reg51.h>
//# include <math.h>
#include"keyscanf.h"
#include<stdio.h>
#define READPORTS P2
#define COMMONPORTS P0
void init();
void display();
//double pow10(int c);
unsigned char flag2,KeyValue,i,fuhao;
unsigned char code TAB[8] = {0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe};
//--点阵字码--//
unsigned char code CHARCODE[18][8]={
{0x00,0x00,0x3e,0x41,0x41,0x41,0x3e,0x00}, //0
{0x00,0x00,0x00,0x00,0x21,0x7f,0x01,0x00}, //1
{0x00,0x00,0x27,0x45,0x45,0x45,0x39,0x00}, //2
{0x00,0x00,0x22,0x49,0x49,0x49,0x36,0x00}, //3
{0x00,0x00,0x0c,0x14,0x24,0x7f,0x04,0x00}, //4
{0x00,0x00,0x72,0x51,0x51,0x51,0x4e,0x00}, //5
{0x00,0x00,0x3e,0x49,0x49,0x49,0x26,0x00}, //6
{0x00,0x00,0x40,0x40,0x40,0x4f,0x70,0x00}, //7
{0x00,0x00,0x36,0x49,0x49,0x49,0x36,0x00}, //8
{0x00,0x00,0x32,0x49,0x49,0x49,0x3e,0x00}, //9
{0x18,0x18,0x18,0xff,0xff,0x18,0x18,0x18}, //P
{0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18}, //R
{0xc3,0xd7,0x7e,0x3c,0x3c,0x7e,0xd7,0xc3}, //E
{0x18,0x18,0x18,0xdb,0xdb,0x18,0x18,0x18}, //C
{0x00,0x00,0x7F,0x08,0x08,0x7F,0x00,0x00}, //H
{0x00,0x00,0x00,0xFF,0xFF,0x00,0x00,0x00}, //I
{0x00,0x7F,0x10,0x08,0x04,0x7F,0x00,0x00}, //N
{0x7C,0x48,0x48,0xFF,0x48,0x48,0x7C,0x00} //中
};
int m,n;
float result;
void main()
{
unsigned char i;
init(); //·····························波特率设置
while(1)
{
// key();
key();
if(KeyValue>=1&&KeyValue<=14)
{
for(i=0;i<200;i++)
{
display(); //······························点阵显示
}
}
change();
if(flag2==1)
{
ES=0;
TI=1; //printf函数特殊要求
flag2=0;
switch(fuhao)
{
case(11):
printf("%d+%d=%.4f\n",m,n,result);break;
case(12):
printf("%d-%d=%.4f\n",m,n,result);break;
case(13):
printf("%d*%d=%.4f\n",m,n,result);break;
case(14):
printf("%d/%d=%.4f\n",m,n,result);break;
}
m=n=0;
// printf("m%.4f\n",result);
while(!TI);
TI=0;
ES=1;
}
}
}
void init() //波特率设置
{
SCON=0X50; //设置为工作方式1
TMOD=0X20; //设置计数器工作方式2
PCON=0X80; //波特率加倍
TH1=0XF3; //计数器初始值设置,注意波特率是4800的
TL1=0XF3;
ES=1; //打开接收中断
EA=1; //打开总中断
TR1=1;
}
void display()
{
unsigned char tab,j;
for(tab=0;tab<8;tab++)
{
//消隐
COMMONPORTS=CHARCODE[KeyValue-1][tab]; //输出字码
READPORTS=TAB[tab];
while(j<250)
j++;
READPORTS=0xFF;
}
}