《2763.E简单电子计算器程序.doc》由会员分享,可在线阅读,更多相关《2763.E简单电子计算器程序.doc(4页珍藏版)》请在三一办公上搜索。
1、#include #include #define RS P1_7#define RW P1_6#define E P1_5int keytime;/获取按键次数unsigned int a10;/获取数值数组最大10位int yunsuan;/运算符识别yunsuan=0;unsigned int num1;/获取第一个数unsigned int num2;/获取第二个数unsigned int num;/用于暂存unsigned int result;/获取结果void mDelay(unsigned char DelayTime)/一个延时程序unsigned int j=0;for(;
2、DelayTime0;DelayTime-) for(j=0;j7)over();else LCD_output(+); yunsuan=1; suan1(); keytime=0; keyjian()if(keytime7)over();else LCD_output(-); yunsuan=2; suan1(); keytime=0;keycheng()if(keytime7)over();else LCD_output(*); yunsuan=3; suan1(); keytime=0;keychu()if(keytime7)over();else LCD_output(/); yuns
3、uan=4; suan1(); keytime=0;keydn()LCD_output(=);suan2();keytime=0;keyrst()yunsuan=0;keytime=0;num1=0;num2=0;result=0;num=0;SEND_I(0x01);SEND_I(0x80);/main()/主函数入口int keydown;/按键判定char keyNO;/存放键值int tmp4;/暂存num1=0;num2=0;result=0;keytime=0;SEND_I(0x01);SEND_I(0x38);SEND_I(0x0c);/0x08 关SEND_I(0x06);SE
4、ND_I(0x80);LCD_output(Cal 08053543);mDelay(500);SEND_I(0x01);SEND_I(0x80);while(1)/进入键盘扫描循环tmp4=0xff;P3=0xf0;tmp4=P3;tmp4=tmp4 & 0xf0;if(tmp4=0xF0)keydown=0;if(tmp4!=0xF0)mDelay(30);if(tmp4!=0xF0)keydown=1;/有键elsekeydown=0;/无键if(keydown=1)if(keytime=16)SEND_I(0x80);keytime=0;/扫描获取键盘码P3=0xfe;keyNO=P3
5、;switch(keyNO)case 0x7e:keytime+;key1();break;case 0xbe:keytime+;key2();break;case 0xde:keytime+;key3();break;case 0xee:keytime+;key4();break;P3=0xfd;keyNO=P3;switch(keyNO)case 0x7d:keytime+;key5();break;case 0xbd:keytime+;key6();break;case 0xdd:keytime+;key7();break;case 0xed:keytime+;key8();break;P3=0xfb;keyNO=P3;switch(keyNO)case 0x7b:keytime+;key9();break;case 0xbb:keytime+;key0();break;case 0xdb:keyjia();break;case 0xeb:keyjian();break;P3=0xf7;keyNO=P3;switch(keyNO)case 0x77:keycheng();break;case 0xb7:keychu();break;case 0xd7:keydn();break;case 0xe7:keyrst();break;keydown=0;return(0);