Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.42 KB | None | 0 0
  1. #include <reg515.sfr>
  2. #include <lcd.h>
  3.  
  4. int a;
  5. int b;
  6. int state;
  7. char buff[24];
  8.  
  9. void print(const char *str){
  10.     //out_instr(1);
  11.     while(*str){
  12.         out_char(*str++);
  13.     }
  14. }
  15. void sleep(){
  16.     int t;
  17.     int i;
  18.     t = 20000;
  19.     for(i=0;i<t;i++);
  20. }
  21.  
  22. char * itoa(int s){
  23.     int x;
  24.     char *buffPos;
  25.     buff[23] = '\0';
  26.     buffPos = buff + 22;
  27.     while(s != 0){
  28.         x = s % 10;
  29.         s /= 10;
  30.         *buffPos-- = x + '0';
  31.     }
  32.     return buffPos + 1;
  33. }
  34.  
  35. void main(){
  36.     int x;
  37.     int c;
  38.     char *str;
  39.     a = 0;
  40.     b = 0;
  41.     state = 0;
  42.     sleep();
  43.     lcd_init();
  44.     sleep();
  45.     out_instr(1);
  46.     sleep();
  47.     //print("Hello");
  48.     while(1){
  49.        
  50.         unsigned char z = get_kb();
  51.         if( z != '\0' ){
  52.             if( z >= '0' && z <= '9'){
  53.                 x = z - '0';
  54.                 if(state){//liczba b
  55.                      b = b * 10 + x;
  56.                 }else{//liczba a
  57.                      a = a * 10 + x;
  58.                 }
  59.                 out_char(z);
  60.             }else{
  61.                 switch(state){
  62.                     case 0: {
  63.                         state = 1;
  64.                         out_char('+');
  65.                         break;
  66.                     }
  67.                     case 1: {
  68.                         state = 2;
  69.                         out_char('=');
  70.                         c = a + b;
  71.                         //out_char(c);
  72.                         str = itoa(c);
  73.                         out_instr(1);
  74.                         print(str);
  75.                         break;
  76.                     }
  77.                     case 2: {
  78.                         state = 0;
  79.                         a = 0;
  80.                         b = 0;
  81.                         out_instr(1);
  82.                         break;
  83.                     }                  
  84.                 }
  85.                 /*
  86.                 if(state){
  87.                      state = 0;
  88.                      int c = a + b;
  89.                      char *str = itoa(c);
  90.                      print(str);
  91.                 }else{
  92.                      state = 1;
  93.                      out_char('+');
  94.                 }
  95.                 */
  96.             }
  97.         }
  98.         sleep();
  99.     }
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement