#include #include int main() { int quit=0; int n; int x=0; int y=1; int i=0; int j=0; long int chr, temp, total, k, m; char c='+'; char data[10]; InitLib(); InitLCD(); LcdSetCursorOn(); /* Display cursor */ // *LcdShowKey = 1; total=0; /* quit program crotrol */ while(!quit) { x=x+1; k=1; SetCursorAt(x, y); /* move cursor to (x,y) */ chr=Getch(); /*iview screen wild and high control */ if(x==17) { x=1; y=y+1; } if (y==8) {ClrScrn(); x=1; y=1;} if (y==0) y=1; /* backspace [B.S.] control */ if (chr==8 || chr==207 ) { if(j >0) data[j-1] =0; x=x-1; TextOutAt(x, y, " "); Print("\b", " "); x=x-1; if(j >0) j=j-1; } else { TextOutAt(x, y, (char *)&chr); Print("%c", chr); } /* Quit program control use Q, ESC*/ if (chr=='q'||chr==27||chr==206) { x=1; y=1; quit=1;} // else if(chr<0x80) Print("%c",chr); // Print("(48) [%d]",chr); /*number too large warnning */ if (j>=10) { x=1; y=y+1; // TextOutAt_len(x, y, "too large!", 10); j=0; } /* calculate control */ if ((chr<58 && chr>46) || chr==45 ||chr==42||chr==43||chr==13||chr==205) { /*get number */ data[j]=(char)chr; /* calculate +, -, *, / */ if (chr=='+' || chr=='-' || chr=='*' || chr=='/' || chr==13 || chr==205) { data[j]='0'; temp=0; n=j; n=n-1; for (n; n>=0; n--) { temp=temp+(data[n]-48)*k; k=10*k; } //for loop // Print ("%d temp=%d\r\n", k,temp); // n=j; // Print ("(78) c= %c\r\n", c); switch(c) { case '+' : total=total+temp; c=(char)chr; j=0; break; case '-' : total=total-temp; c=(char)chr; j=0;break; case '*' : total=total*temp; c=(char)chr; j=0; break; case '/' : total=total/temp; c=(char)chr; j=0;break; } //end swich } else j=j+1; // if : calculate +,-,*,/ /* enter to show answer */ if (chr==13 || chr==205) { x=1; y=y+1; switch(c) { case '+' : total=total+temp; c=(char)chr; break; case '-' : total=total-temp; c=(char)chr; break; case '*' : total=total*temp; c=(char)chr; break; case '/' : total=total/temp; c=(char)chr; break; } //end swich TextOutAt(x, y, "="); x=x+1; /* count digit */ n=1; m=total; while (m>=10 || m<=-10) { m=m/10; n=n+1; } if (total<0) n=n+1; IntOutAt(x, y, n, total ); Print("\r\n =%ld\r\n", total); x=0; if (y<8) y=y+1; j=0;total=0; k=1;c='+'; } //end if : show answer }//end if : end of calculate control }//while loop : end of quit program control CloseLCD(); return 0; } //end main