level 9
kmsmg2004
楼主
#include <reg51.h>#
include void system_Ini(void);void printW(unsigned int );bit CheckKeyDown(void );unsigned char lastKey,lastKey3,K3; //键顺序吗
void delay(unsigned char x); //x*0.14MS、void keyscan(void);bit DATA_IN();bit coul();void Display();
unsigned char idata buf[8];unsigned char code SEG_Tab[] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x40}; //段码控制unsigned char pos=0;unsigned char temp;
//JP15和JP16用短路帽连接// P1与JP12 用排线连接
int OP1 = 0;int OP2 = 0;int OP = 0;int buff = 0;int key = 0;int Stat = 0;
main(){system_Ini();printW(0);for (;;){if (CheckKeyDown()){switch (Stat){case 0:if (key >= 0 && key <= 9){DATA_IN();Stat = 1;}
break;case 1:if (key >= 0 && key <= 9){if (DATA_IN())Stat = -1;
}else if (key >= 10 && key <= 13) //+ -* /{OP1 = buff;OP = key;Stat = 2;}else if (key == 14) // "="{OP1 = buff;buff = 0;Stat = 6;}else if (key == 15) // "C"{buff = 0;Stat = 0;}
break;
case 2:if (key >= 0 && key <= 9){buff = 0;DATA_IN();Stat = 3;
}else if (key >= 10 && key <= 13) //+ -* /{
OP = key;
}else if (key == 14) // "="{
Stat = 6;}else if (key == 15) // "C"{buff = 0;Stat = 0;}
break;
case 3:if (key >= 0 && key <= 9){if (DATA_IN())Stat = -1;
}else if (key >= 10 && key <= 13) //+ -* /{OP2 = buff;buff = 0;if (coul())Stat = -1;elseStat = 2;}else if (key == 14) // "="{OP2 = buff;buff = 0;if (coul())Stat = -1;elseStat = 6;}else if (key == 15) // "C"{buff = 0;Stat = 0;}
break;case 6:if (key >= 0 && key <= 9){buff = 0;DATA_IN();Stat = 1;
}else if (key >= 10 && key <= 13) //+ -* /{OP = key;buff = 0;Stat = 2;}else if (key == 14) // "="{
}else if (key == 15) // "C"{buff = 0;Stat = 0;}break;case -1:default:if (key == 15) // "C"{buff = 0;Stat = 0;}break;}Display();
}
}
}
bit coul(){bit r = 0 ;switch (OP){case 10: //"+"OP1 = OP1 + OP2;break;case 11://"-"OP1 = OP1 - OP2;break;
case 12: //"*"OP1 = OP1 *OP2;break;
case 13: // "/"if (OP2 != 0)OP1 = OP1 / OP2;elser = 1;break;
default:r = 1;break;
}if (OP1>9999)r=1 ;return r;}
bit DATA_IN(){bit Over = 1;buff = buff * 10 + key;if (buff < 9999) Over = 0;return Over;
}
//把一正整数据变为字形并存入缓存区void printW(unsigned int a){char i=0;char b;for(i=0;i<8;i++){b=a%10;a=a/10;if (a==0 && b==0 && i>0)buf[7-i]=0;elsebuf[7-i]=SEG_Tab[b];
2012年07月28日 15点07分
1
include void system_Ini(void);void printW(unsigned int );bit CheckKeyDown(void );unsigned char lastKey,lastKey3,K3; //键顺序吗
void delay(unsigned char x); //x*0.14MS、void keyscan(void);bit DATA_IN();bit coul();void Display();
unsigned char idata buf[8];unsigned char code SEG_Tab[] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x40}; //段码控制unsigned char pos=0;unsigned char temp;
//JP15和JP16用短路帽连接// P1与JP12 用排线连接
int OP1 = 0;int OP2 = 0;int OP = 0;int buff = 0;int key = 0;int Stat = 0;
main(){system_Ini();printW(0);for (;;){if (CheckKeyDown()){switch (Stat){case 0:if (key >= 0 && key <= 9){DATA_IN();Stat = 1;}
break;case 1:if (key >= 0 && key <= 9){if (DATA_IN())Stat = -1;
}else if (key >= 10 && key <= 13) //+ -* /{OP1 = buff;OP = key;Stat = 2;}else if (key == 14) // "="{OP1 = buff;buff = 0;Stat = 6;}else if (key == 15) // "C"{buff = 0;Stat = 0;}
break;
case 2:if (key >= 0 && key <= 9){buff = 0;DATA_IN();Stat = 3;
}else if (key >= 10 && key <= 13) //+ -* /{
OP = key;
}else if (key == 14) // "="{
Stat = 6;}else if (key == 15) // "C"{buff = 0;Stat = 0;}
break;
case 3:if (key >= 0 && key <= 9){if (DATA_IN())Stat = -1;
}else if (key >= 10 && key <= 13) //+ -* /{OP2 = buff;buff = 0;if (coul())Stat = -1;elseStat = 2;}else if (key == 14) // "="{OP2 = buff;buff = 0;if (coul())Stat = -1;elseStat = 6;}else if (key == 15) // "C"{buff = 0;Stat = 0;}
break;case 6:if (key >= 0 && key <= 9){buff = 0;DATA_IN();Stat = 1;
}else if (key >= 10 && key <= 13) //+ -* /{OP = key;buff = 0;Stat = 2;}else if (key == 14) // "="{
}else if (key == 15) // "C"{buff = 0;Stat = 0;}break;case -1:default:if (key == 15) // "C"{buff = 0;Stat = 0;}break;}Display();
}
}
}
bit coul(){bit r = 0 ;switch (OP){case 10: //"+"OP1 = OP1 + OP2;break;case 11://"-"OP1 = OP1 - OP2;break;
case 12: //"*"OP1 = OP1 *OP2;break;
case 13: // "/"if (OP2 != 0)OP1 = OP1 / OP2;elser = 1;break;
default:r = 1;break;
}if (OP1>9999)r=1 ;return r;}
bit DATA_IN(){bit Over = 1;buff = buff * 10 + key;if (buff < 9999) Over = 0;return Over;
}
//把一正整数据变为字形并存入缓存区void printW(unsigned int a){char i=0;char b;for(i=0;i<8;i++){b=a%10;a=a/10;if (a==0 && b==0 && i>0)buf[7-i]=0;elsebuf[7-i]=SEG_Tab[b];
