// LCD module connections sbit LCD_RS at PORTA2_bit; sbit LCD_EN at PORTA3_bit; sbit LCD_D4 at PORTA4_bit; sbit LCD_D5 at PORTA5_bit; sbit LCD_D6 at PORTA6_bit; sbit LCD_D7 at PORTA7_bit; sbit LCD_RS_Direction at DDA2_bit; sbit LCD_EN_Direction at DDA3_bit; sbit LCD_D4_Direction at DDA4_bit; sbit LCD_D5_Direction at DDA5_bit; sbit LCD_D6_Direction at DDA6_bit; sbit LCD_D7_Direction at DDA7_bit; // End LCD module connections int a[3],b[3],g=0,rez=0,r=0,e=0, i=0,j=0,op1,op2; unsigned rek; char rezu[8]; void main() { DDRD=0; DDRC=0; DDRB=0; Lcd_Init(); // Initialize LCD Lcd_Cmd(_LCD_CLEAR); // Clear display Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off do{if(PIND==0&&PINC==0&&PINB==0) do{ if (PIND4_bit==1) { lcd_out(1,i+1,"0"); a[i]=0; i++;delay_ms(100);break;} if (PIND7_bit==1) { lcd_out(1,i+1,"1"); a[i]=1; i++;delay_ms(100);break;} if (PINC7_bit==1) { lcd_out(1,i+1,"2"); a[i]=2; i++;delay_ms(100);break;} if (PINB7_bit==1) { lcd_out(1,i+1,"3"); a[i]=3; i++;delay_ms(100);break;} if (PIND6_bit==1) { lcd_out(1,i+1,"4"); a[i]=4; i++;delay_ms(100);break;} if (PINC6_bit==1) { lcd_out(1,i+1,"5"); a[i]=5; i++;delay_ms(100);break;} if (PINB6_bit==1) { lcd_out(1,i+1,"6"); a[i]=6; i++;delay_ms(100);break;} if (PIND5_bit==1) { lcd_out(1,i+1,"7"); a[i]=7; i++;delay_ms(100);break;} if (PINC5_bit==1) { lcd_out(1,i+1,"8"); a[i]=8; i++;delay_ms(100);break;} if (PINB5_bit==1) { lcd_out(1,i+1,"9"); a[i]=9; i++;delay_ms(100);break;} if (PINB4_bit==1) {lcd_out(1,i+1,"*"); r=1; g=1;delay_ms(100);break;} if (PINC4_bit==1) {lcd_out(1,i+1,"+"); r=2; g=2;delay_ms(100);break;} }while(1); } while (r==0); do{ e=0; if(PIND==0&&PINC==0&&PINB==0) do{ if (PIND4_bit==1) { lcd_out(2,j+1,"0"); b[j]=0; j++;delay_ms(100);break;} if (PIND7_bit==1) { lcd_out(2,j+1,"1"); b[j]=1; j++;delay_ms(100);break;} if (PINC7_bit==1) { lcd_out(2,j+1,"2"); b[j]=2; j++;delay_ms(100);break;} if (PINB7_bit==1) { lcd_out(2,j+1,"3"); b[j]=3; j++;delay_ms(100);break;} if (PIND6_bit==1) { lcd_out(2,j+1,"4"); b[j]=4; j++;delay_ms(100);break;} if (PINC6_bit==1) { lcd_out(2,j+1,"5"); b[j]=5; j++;delay_ms(100);break;} if (PINB6_bit==1) { lcd_out(2,j+1,"6"); b[j]=6; j++;delay_ms(100);break;} if (PIND5_bit==1) { lcd_out(2,j+1,"7"); b[j]=7; j++;delay_ms(100);break;} if (PINC5_bit==1) { lcd_out(2,j+1,"8"); b[j]=8; j++;delay_ms(100);break;} if (PINB5_bit==1) { lcd_out(2,j+1,"9"); b[j]=9; j++;delay_ms(100);break;} if (PINB3_bit==1) { lcd_out(2,i+1,"="); e=1;delay_ms(100);break;} } while(1); } while (e==0); if(i==1){op1=a[0];} else if(i==2){op1=a[0]*10+a[1];} else if(i==3){op1=a[0]*100+a[1]*10+a[2];} if(j==1){op2=b[0];} else if(j==2){op2=b[0]*10+b[1];} else if(j==3){op2=b[0]*100+b[1]*10+b[2];} if (g==1){ rez=op1*op2; rek=op1*op2; } if (g==2) { rez=op1+op2; } inttostr(rez,rezu); if (rek>32767) { lcd_out (2,5,"ERROR");} else {lcd_out(2,5,rezu);} delay_ms(1); // lcd_out(2,5,rezu); delay_ms(1); while(1); }