《简单电子计算器程序》由会员分享,可在线阅读,更多相关《简单电子计算器程序(4页珍藏版)》请在金锄头文库上搜索。
1、#include #include #define RS P1_7 #define RW P1_6 #define E P1_5 int 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)/一 个延时程序 unsigne
2、d int j=0; for(;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(keytime
3、7) over(); else LCD_output(“/“); yunsuan=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; keytim
4、e=0; SEND_I(0x01); SEND_I(0x38); SEND_I(0x0c);/0x08 关 SEND_I(0x06); SEND_I(0x80); LCD_output(“Cal 08053543“); mDelay(500); SEND_I(0x01); SEND_I(0x80); while(1) /进入键盘扫描循 环 tmp4=0xff; P3=0xf0; tmp4=P3; tmp4=tmp4 if(tmp4=0xF0) keydown=0; if(tmp4!=0xF0) mDelay(30); if(tmp4!=0xF0) keydown=1;/有键 else keyd
5、own=0;/无键 if(keydown=1) if(keytime=16) SEND_I(0x80); keytime=0; /扫描获取键盘码 P3=0xfe; keyNO=P3; 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(
6、);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);