1、项目一:简单计算器1。实验题目:用51单片机实现简单的计算器功能2。实验截图: 1)。实验运行前截图:2)。实验运行后截图:3。实验代码:include#includedefined。HincludeLCD1602.hunsigned char table116;/1602第一行显示字符unsigned char table216;/1602第二行显示字符unsigned char code table_error = error;/* 键扫描函数 /unsigned char keyscan() /扫描键盘函数unsigned char key_l,key_h,addres,num;P0=0
2、x0f;key_l=P0;P0=0xf0;key_h=P0;addres=key_l key_h;if(addres!=0xff)Delayms(1);if(addres!=0xff)P0=0x0f;key_l=P0;P0=0xf0;key_h=P0;addres=key_l key_h;switch(addres)case 0xee:num=1;break;case 0xde:num=2;break;case 0xbe:num=3;break;case 0xed:num=4;break;case 0xdd:num=5;break;case 0xbd:num=6;break;case 0xeb
3、:num=7;break;case 0xdb:num=8;break;case 0xbb:num=9;break;case 0xd7:num=0;break;/按键0case 0xe7:num=C;break;/按键case 0xb7:num=;break;/按键case 0x7e:num=/;break;/按键Acase 0x7d:num=;break;/按键Bcase 0x7b:num=;break;/按键Ccase 0x77:num=+;break;/按键Dwhile(addres!=0xff) P0=0x0f;key_l=P0;P0=0xf0;key_h=P0;addres=key_l
4、 key_h;return num; return 0;void clear_lcd(void)/清屏unsigned char j;for(j=0;j16;j+)table1j=0;table2j=0;void main()unsigned char i=0,j;unsigned char key;unsigned char flag_operator = 0;/加减乘除标志位unsigned char flag_equ = 0;/等于标志位unsigned char flag_key = 0;/运算位标志bit flag_MaxValue = 0;bit flag_minus = 0;/负
5、数long int value = 0; /最终运算结果unsigned long int value_H =0; /第一个数据unsigned long int value_L = 0; /第二个数据unsigned long int temp=1, 10, 100,1000,10000,100000,1000000,10000000,100000000;Initialize_LCD();while(1)key=keyscan();if(key != 0)if(key = C)/清除键C按下clear_lcd();i=0;flag_operator = 0; flag_equ = 0; va
6、lue = 0; value_H =0; value_L = 0; flag_key = 0; flag_minus=0;elsefor(j=0; ji; j+)table115-i+j = table115-i+j+1;table115 = key;/table1i = key;i+;if(key = =)for(j=0; j16; j+)/确定运算符位置if(table1j = =)flag_equ = j;flag_key+;break;if( table1j = + | table1j = | table1j = | table1j = /)flag_operator = j;flag
7、_key+;for(j=16i; jflag_operator; j+)/第一个数据处理/value_H = value_H + (table1j-48) * ( pow( 10 , (flag_operator-j-1)) );value_H = value_H + (table1j-48) * tempflag_operator-j1;for(j=flag_operator+1; j2000000000)flag_MaxValue = 1;/break;j=15;while(value!=0)table2j = (value10 + 48);value = value/10;j-;if(flag_minus)/负数table2j = ;if(flag_key 2 | table10 = 0 flag_MaxValue=1 )ShowString(5,1,table_error);while(keyscan() != C);clear_lcd();i=0;flag_operator = 0; flag_equ = 0; value = 0; value_H =0; value_L = 0; flag_key = 0; flag_minus=0;ShowString(0,0,table1);ShowString(0,1,table2);