Advertisement
eladha

Code pin smart home

Jan 26th, 2019
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 5.20 KB | None | 0 0
  1. int aa=0;
  2. int bb=0;
  3. int cc=0;
  4. int dd=0;
  5. int ee=0;
  6.  
  7.  
  8. char uart_rd;
  9.  
  10. void main()
  11.  {
  12.  
  13.  
  14.  
  15.  
  16. trisc.f0=1;
  17. trisc.f1=1;
  18. trisc.f2=1;
  19. trisc.f3=1;
  20. trisc.f4=1;
  21. trisc.f5=1;
  22. trisc.f6=1;
  23. trisc.f7=1;
  24.  
  25. trisb=0b00001111;
  26.  
  27. trisd=0b01111;
  28. trise=0;
  29. adcon1=0b0111;
  30. trisa=0;
  31. portb=0;
  32. portc=0;
  33. portd=0;
  34. porte=0;
  35. porta=0;
  36.  
  37.      UART1_Init(9600);               // Initialize UART module at 9600 bps
  38.   Delay_ms(100);                  // Wait for UART module to stabilize
  39.  
  40.   UART1_Write_Text("Start");
  41.  
  42.  
  43.  
  44.   while(1)
  45.   {
  46.  
  47.  
  48.            if (UART1_Data_Ready())
  49.          {
  50.  
  51.            uart_rd = UART1_Read();
  52.            if( uart_rd=='a')
  53.            portb.f4=1;
  54.            
  55.            if( uart_rd=='A')
  56.                 portb.f4=0;
  57.  
  58.  
  59.                 if( uart_rd=='b')
  60.                 portb.f5=1;
  61.  
  62.                 if( uart_rd=='B')
  63.                 portb.f5=0;
  64.  
  65.  
  66.                 if( uart_rd=='c')
  67.                 portb.f6=1;
  68.                 if( uart_rd=='C')
  69.                 portb.f6=0;
  70.  
  71.                 if( uart_rd=='d')
  72.                 portb.f7=1;
  73.                 if( uart_rd=='D')
  74.                 portb.f7=0;
  75.  
  76.  
  77.  
  78.                 if( uart_rd=='z')
  79.                 {
  80.                  portd.f5=1;
  81.                 delay_ms(4000);
  82.                 portd.f5=0;
  83.                 }
  84.  
  85.  
  86.  
  87.                 if( uart_rd=='1')
  88.                 {
  89.  
  90.                 portb.f4=1;
  91.                 portb.f5=1;
  92.                 portb.f6=1;
  93.                 portb.f7=1 ;
  94.                 }
  95.  
  96.  
  97.                 if( uart_rd=='0')
  98.                 {
  99.  
  100.                 portb.f4=0;
  101.                 portb.f5=0;
  102.                 portb.f6=0;
  103.                 portb.f7=0;
  104.  
  105.                 }
  106.  
  107.  
  108.          }
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.               if(portc.f0==1 && portc.f1==0 &&portc.f2==0 &&portc.f3==0 &&portc.f4==1 && aa==0    )
  121.               {
  122.                portb.f4=1;
  123.                aa=1;
  124.                delay_ms(500);
  125.                }
  126.  
  127.                if(portc.f0==0 && portc.f1==1 &&portc.f2==0 &&portc.f3==0 &&portc.f4==1 && bb==0  )
  128.                {
  129.               portb.f5=1;
  130.               bb=1;
  131.               delay_ms(500);
  132.               }
  133.  
  134.  
  135.               if(portc.f0==1 && portc.f1==1 &&portc.f2==0 &&portc.f3==0 &&portc.f4==1 && cc==0  )
  136.               {
  137.                portb.f6=1;
  138.                cc=1;
  139.                delay_ms(500);
  140.                }
  141.  
  142.                if(portc.f0==0 && portc.f1==0&& portc.f2==1 &&portc.f3==0 &&portc.f4==1  && dd==0  )
  143.                {
  144.                 portb.f7=1;
  145.                 dd=1;
  146.                 delay_ms(500);
  147.                 }
  148.  
  149.  
  150.  
  151.                   if(portc.f0==1 && portc.f1==0 &&portc.f2==0 &&portc.f3==0 &&portc.f4==1 && aa==1  )
  152.               {
  153.                portb.f4=0;
  154.                aa=0;
  155.                delay_ms(500);
  156.               }
  157.  
  158.                if(portc.f0==0 && portc.f1==1 &&portc.f2==0 &&portc.f3==0 &&portc.f4==1 && bb==1  )
  159.               {
  160.               portb.f5=0;
  161.               bb=0;
  162.               delay_ms(500);
  163.               }
  164.  
  165.  
  166.               if(portc.f0==1 && portc.f1==1 &&portc.f2==0 &&portc.f3==0 &&portc.f4==1  && cc==1  )
  167.               {
  168.                portb.f6=0;
  169.                cc=0;
  170.                delay_ms(500);
  171.               }
  172.  
  173.                if(portc.f0==0 && portc.f1==0&& portc.f2==1 &&portc.f3==0 &&portc.f4==1 && dd==1  )
  174.                {
  175.                 portb.f7=0;
  176.                 dd=0;
  177.                 delay_ms(500);
  178.               }
  179.  
  180.  
  181.  
  182.     if( portc.f0==0 && portc.f1==0&& portc.f2==1 &&portc.f3==1 &&portc.f4==1 )
  183.      {
  184.      portb.f4=1;
  185.      portb.f5=1;
  186.      portb.f6=1;
  187.      portb.f7=1;
  188.  
  189.       delay_ms(500);
  190.     }
  191.  
  192.      if( portc.f0==1 && portc.f1==1&& portc.f2==0 &&portc.f3==1 &&portc.f4==1 )
  193.      {
  194.       portb=0b0000;
  195.       delay_ms(500);
  196.     }
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204.  
  205.  
  206.  
  207.  
  208.         if(portb.f0==1 && portb.f1==0&& portb.f2==0 &&portb.f3==0  && aa==0   )
  209.     {
  210.      portb.f4=1;
  211.      aa=1;
  212.      delay_ms(500);
  213.      }
  214.  
  215.      if(portb.f0==0 && portb.f1==1&& portb.f2==0 &&portb.f3==0  && bb==0  )
  216.      {
  217.     portb.f5=1;
  218.     bb=1;
  219.     delay_ms(500);
  220.     }
  221.  
  222.  
  223.     if(portb.f0==1 && portb.f1==1&& portb.f2==0 &&portb.f3==0&& cc==0  )
  224.     {
  225.      portb.f6=1;
  226.      cc=1;
  227.      delay_ms(500);
  228.      }
  229.  
  230.      if(portb.f0==0&& portb.f1==0&& portb.f2==1 &&portb.f3==0 && dd==0 )
  231.      {
  232.       portb.f7=1;
  233.       dd=1;
  234.       delay_ms(500);
  235.       }
  236.  
  237.  
  238.  
  239.         if(portb.f0==1 && portb.f1==0&& portb.f2==1 &&portb.f3==0 && aa==1  )
  240.     {
  241.      portb.f4=0;
  242.      aa=0;
  243.      delay_ms(500);
  244.     }
  245.  
  246.      if(portb.f0==0&& portb.f1==1&& portb.f2==1 &&portb.f3==0 && bb==1  )
  247.     {
  248.     portb.f5=0;
  249.     bb=0;
  250.     delay_ms(500);
  251.     }
  252.  
  253.  
  254.     if(portb.f0==1&& portb.f1==1&& portb.f2==1 &&portb.f3==0 && cc==1  )
  255.     {
  256.      portb.f6=0;
  257.      cc=0;
  258.      delay_ms(500);
  259.     }
  260.  
  261.      if( portb.f0==0&& portb.f1==0&& portb.f2==0 &&portb.f3==1 && dd==1  )
  262.      {
  263.       portb.f7=0;
  264.       dd=0;
  265.       delay_ms(500);
  266.     }
  267.  
  268.  
  269.      if(portc.f0==0 && portc.f1==1 &&portc.f2==0 &&portc.f3==1 &&portc.f4==1 ||  portb.f0==0&& portb.f1==1&& portb.f2==0 &&portb.f3==1 )
  270.       {
  271.       portd.f5=1;
  272.       delay_ms(4000);
  273.       portd.f5=0;
  274.      }
  275.      
  276.      
  277.      
  278.      
  279.      
  280.      
  281.      
  282.      
  283.      
  284.  
  285.  
  286.  
  287.  
  288.  
  289.    }
  290.  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement