Guest User

Untitled

a guest
Nov 11th, 2018
278
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 13.76 KB | None | 0 0
  1. #include <simples_2.h>
  2.  
  3. int1 LD = 0;
  4. int chavefun = 0;
  5.  
  6. void piscaled(int16 qtd, int16 temp)
  7. {
  8.    for(int16 i=0; i < qtd; i++)
  9.    {
  10.       output_high(LED);
  11.       delay_ms(temp);
  12.       output_low(LED);
  13.       delay_ms(temp);
  14.    }
  15. }
  16.  
  17. /*void bip(int16 temp)
  18. {
  19.    for(int16 i = 0; i <= temp; i++)
  20.    {
  21.       output_high(buzzer);
  22.       delay_us(250);
  23.       output_low(buzzer);
  24.       delay_us(250);
  25.    }
  26. }*/
  27.  
  28. void freio(int1 at)
  29. {
  30.    
  31.    output_toggle(at_freio);
  32.    
  33.    if (at == 1)
  34.    {
  35.       piscaled(5,500);
  36.    }
  37. }
  38.  
  39. void encher(int temp)
  40. {
  41.    if(input(pressostato) == 0)
  42.    {
  43.       output_low(valvula1);
  44.       output_low(valvula2);
  45.      
  46.       freio(1);
  47.      
  48.       do{
  49.          output_high(motor1);
  50.          output_low(motor2);
  51.          delay_ms(500);
  52.          output_low(motor1);
  53.          output_low(motor2);
  54.          
  55.          piscaled(temp,500);
  56.          
  57.          output_high(motor1);
  58.          output_low(motor2);
  59.          delay_ms(500);
  60.          output_low(motor1);
  61.          output_low(motor2);
  62.          
  63.          piscaled(temp,500);
  64.          
  65.          
  66.       }while(input(pressostato) == 0);
  67.    
  68.       output_high(motor1);
  69.       output_low(motor2);
  70.       delay_ms(800);
  71.       output_low(motor1);
  72.       output_low(motor2);
  73.      
  74.       output_high(valvula1);
  75.       output_high(valvula2);
  76.      
  77.       freio(0);
  78.    }
  79. }
  80.  
  81. void bater(int16 batidas, int16 intervalo, int mult)
  82. {
  83.    for(int x=0; x < mult; x++)
  84.    {
  85.       for (int16 i=0; i < batidas; i++)
  86.       {
  87.          output_high(motor1);
  88.          output_low(motor2);
  89.          delay_ms(500);
  90.          output_low(motor1);
  91.          output_low(motor2);
  92.          delay_ms(250);
  93.          output_low(motor1);
  94.          output_high(motor2);
  95.          delay_ms(500);
  96.          output_low(motor1);
  97.          output_low(motor2);
  98.          delay_ms(intervalo);
  99.       }
  100.    }
  101. }
  102.  
  103. void molho(int16 intervalom, int mult)
  104. {
  105.    for(int x=0; x < mult; x++)
  106.    {
  107.       for(int16 x=0; x < intervalom; x++)
  108.       {
  109.          output_high(LED);
  110.          delay_ms(500);
  111.          output_low(LED);
  112.          delay_ms(500);
  113.       }
  114.    }
  115. }
  116.  
  117. void exaustao(int16 duracao)
  118. {
  119.    output_low(bomba);
  120.    piscaled(duracao,500);
  121.    output_high(bomba);
  122. }
  123.  
  124. void enxague(int duracao)
  125. {
  126.    freio(1);
  127.    
  128.    //int dividir = (duracao/10);
  129.    int dividir = (duracao/2);
  130.    //int j = 0;
  131.    
  132.    for(int i=0; i < duracao; i++)
  133.    {    
  134.       if(i == dividir)
  135.       {
  136.          output_low(bomba);
  137.          output_low(valvula1);
  138.          output_low(valvula2);
  139.       }
  140.      
  141.       output_high(motor1);
  142.      
  143.       piscaled(3,500);
  144.      
  145.       output_low(motor1);
  146.            
  147.       piscaled(7,500);
  148.    }
  149.    
  150.    freio(0);
  151.    
  152.    output_high(bomba);
  153.    
  154.    output_high(valvula1);
  155.    output_high(valvula2);
  156.      
  157.    piscaled(1,500);
  158. }
  159.  
  160. void centrifugar(int16 duracao)
  161. {
  162.    freio(1);
  163.    
  164.    output_low(bomba);
  165.    
  166.    piscaled(1,500);
  167.    
  168.    output_high(motor1);
  169.    
  170.    piscaled(duracao,500);
  171.      
  172.    output_low(motor1);
  173.        
  174.    output_high(bomba);
  175.    
  176.    piscaled(10,500);
  177.    
  178.    freio(0);
  179. }
  180.  
  181. /*void funcao1()
  182. {
  183.    encher(20);
  184.    for(int i=0; i < 6; i++)
  185.    {
  186.       bater(86,500);
  187.       molho(150);
  188.    }
  189.    exaustao(300);
  190.    centrifugar1(300);
  191.    centrifugar2(300);
  192.    encher(20);
  193.    for(int x=0; x < 6; x++)
  194.    {
  195.       bater(86,500);
  196.       molho(150);
  197.    }
  198.    exaustao(600);
  199.    centrifugar1(300);
  200.    centrifugar2(600);
  201.    
  202. }*/
  203.  
  204. #INT_TIMER1
  205. void  TIMER1_isr(void)              // 8:1 500ms
  206. {
  207.    set_timer1 (3036);               //Iniciar o Timer1 em
  208.    //t1++;
  209.    if(input(chave1) == 1 && input(chave2) == 1 && input(chave3) == 1 && input(chave4) == 1) // 0 - inicio/fim
  210.       {
  211.          chavefun = 0;
  212.       }
  213.      
  214.    if(input(chave1) == 1 && input(chave2) == 1 && input(chave3) == 0 && input(chave4) == 1) // 1 - N/C
  215.       {
  216.          chavefun = 1;
  217.       }
  218.      
  219.    if(input(chave1) == 1 && input(chave2) == 0 && input(chave3) == 0 && input(chave4) == 1) // 2 - N/C
  220.       {
  221.          chavefun = 2;
  222.       }
  223.      
  224.    if(input(chave1) == 1 && input(chave2) == 0 && input(chave3) == 1 && input(chave4) == 1)  // 3 - N/C
  225.       {
  226.          chavefun = 3;
  227.       }
  228.      
  229.    if(input(chave1) == 1 && input(chave2) == 0 && input(chave3) == 1 && input(chave4) == 0) // 4 - Molho Longo + agitação
  230.       {
  231.          chavefun = 4;
  232.       }
  233.      
  234.    if(input(chave1) == 1 && input(chave2) == 0 && input(chave3) == 0 && input(chave4) == 0) // 5 -
  235.       {
  236.          chavefun = 5;
  237.       }
  238.      
  239.    if(input(chave1) == 1 && input(chave2) == 1 && input(chave3) == 0 && input(chave4) == 0) // 6 - molho + agitação
  240.       {
  241.          chavefun = 6;
  242.       }
  243.      
  244.    if(input(chave1) == 1 && input(chave2) == 1 && input(chave3) == 1 && input(chave4) == 0) // 7 -
  245.       {
  246.          chavefun = 7;
  247.       }
  248.      
  249.    if(input(chave1) == 0 && input(chave2) == 1 && input(chave3) == 1 && input(chave4) == 0) // 8 - molho curto + agitação
  250.       {
  251.          chavefun = 8;
  252.       }
  253.      
  254.    if(input(chave1) == 0 && input(chave2) == 1 && input(chave3) == 0 && input(chave4) == 0) // 9 -
  255.       {
  256.          chavefun = 9;
  257.       }
  258.      
  259.    if(input(chave1) == 0 && input(chave2) == 0 && input(chave3) == 0 && input(chave4) == 0) // 10 - agitação
  260.       {
  261.          chavefun = 10;
  262.       }
  263.      
  264.    if(input(chave1) == 0 && input(chave2) == 0 && input(chave3) == 1 && input(chave4) == 0) // 11 -
  265.       {
  266.          chavefun = 11;
  267.       }
  268.      
  269.    if(input(chave1) == 0 && input(chave2) == 0 && input(chave3) == 1 && input(chave4) == 1) // 12 - enxágue
  270.       {
  271.          chavefun = 12;
  272.       }
  273.      
  274.    if(input(chave1) == 0 && input(chave2) == 0 && input(chave3) == 0 && input(chave4) == 1) // 13 -
  275.       {
  276.          chavefun = 13;
  277.       }
  278.      
  279.    if(input(chave1) == 0 && input(chave2) == 1 && input(chave3) == 0 && input(chave4) == 1) // 14 - centrifugação
  280.       {
  281.          chavefun = 14;
  282.       }
  283.    
  284.    if(input(chave1) == 0 && input(chave2) == 1 && input(chave3) == 1 && input(chave4) == 1) // 15 -
  285.       {
  286.          chavefun = 15;
  287.       }
  288.  
  289.    if(input(power) == 0)
  290.    {
  291.       switch(LD)
  292.       {
  293.         case 0:
  294.          LD = 1;
  295.          
  296.         break;
  297.         case 1:
  298.          reset_cpu();
  299.         break;
  300.       }
  301.    }
  302. }
  303.  
  304. void main()
  305. {
  306.    output_high(bomba);
  307.    output_high(at_freio);
  308.    output_high(motorchave);
  309.    output_high(valvula1);
  310.    output_high(valvula2);
  311.    output_low(motor1);
  312.    output_low(motor2);
  313.    output_low(buzzer);
  314.    
  315.    piscaled(1,500);
  316.    //bip(1000);
  317.    
  318.    setup_timer_1(T1_INTERNAL|T1_DIV_BY_4);      //524 ms overflow
  319.  
  320.    enable_interrupts(GLOBAL);
  321.    enable_interrupts(INT_TIMER1);
  322.  
  323.  
  324.    
  325.    while(TRUE)
  326.    {
  327.       if (LD == 1)
  328.       {
  329.          delay_ms(200);
  330.          //bip(500);
  331.          output_low(LED);
  332.          
  333.          switch(chavefun)
  334.          {
  335.             case 0: //maquina desligada ou inicio/fim do processo
  336.             //chavefun = 1;
  337.            
  338.             output_low(motorchave);
  339.            
  340.             do
  341.             {
  342.                piscaled(1,250);
  343.             }
  344.             while(chavefun == 0);
  345.            
  346.             output_high(motorchave);
  347.            
  348.             break;
  349.            
  350.             case 1: // posição sem função
  351.            
  352.             output_low(motorchave);
  353.            
  354.             do
  355.             {
  356.                piscaled(1,250);
  357.             }
  358.             while(chavefun == 1);
  359.            
  360.             output_high(motorchave);
  361.            
  362.             break;
  363.            
  364.             case 2: // posição sem função
  365.            
  366.             output_low(motorchave);
  367.            
  368.             do
  369.             {
  370.                piscaled(1,250);
  371.             }
  372.             while(chavefun == 2);
  373.            
  374.             output_high(motorchave);
  375.            
  376.             break;
  377.            
  378.             case 3: // posição sem função, passa direto...
  379.            
  380.             output_low(motorchave);
  381.            
  382.             do
  383.             {
  384.                piscaled(1,250);
  385.             }
  386.             while(chavefun == 3);
  387.            
  388.             output_high(motorchave);
  389.            
  390.             break;
  391.            
  392.             case 4: // molho longo (30 minutos)
  393.            
  394.             encher(40);
  395.            
  396.             bater(172,500,1);
  397.            
  398.             molho(300,6);
  399.            
  400.             output_low(motorchave);
  401.            
  402.             do
  403.             {
  404.                piscaled(1,250);
  405.             }
  406.             while(chavefun == 4);
  407.            
  408.             output_high(motorchave);
  409.            
  410.             break;
  411.            
  412.             case 5: // continuação do molho longo (30 minutos)
  413.            
  414.             encher(40);
  415.            
  416.             bater(172,500,1);
  417.            
  418.             molho(300,6);
  419.                
  420.             output_low(motorchave);
  421.            
  422.             do
  423.             {
  424.                piscaled(1,250);
  425.             }
  426.             while(chavefun == 5);
  427.            
  428.             output_high(motorchave);
  429.            
  430.             break;
  431.            
  432.             case 6: // molho (15 minutos)
  433.            
  434.             encher(20);
  435.            
  436.             bater(172,500,1);
  437.            
  438.             molho(300,3);
  439.            
  440.             output_low(motorchave);
  441.            
  442.             do
  443.             {
  444.                piscaled(1,250);
  445.             }
  446.             while(chavefun == 6);
  447.            
  448.             output_high(motorchave);
  449.                        
  450.             break;
  451.            
  452.             case 7: // continuação molho (+15 minutos)
  453.            
  454.             encher(20);
  455.            
  456.             bater(172,500,1);
  457.            
  458.             molho(300,3);
  459.            
  460.             output_low(motorchave);
  461.            
  462.             do
  463.             {
  464.                piscaled(1,250);
  465.             }
  466.             while(chavefun == 7);
  467.            
  468.             output_high(motorchave);
  469.            
  470.             break;
  471.            
  472.             case 8: // molho cuto (10 minutos)
  473.            
  474.             encher(20);
  475.            
  476.             bater(86,500,1);
  477.            
  478.             molho(300,2);
  479.            
  480.             output_low(motorchave);
  481.            
  482.             do
  483.             {
  484.                piscaled(1,250);
  485.             }
  486.             while(chavefun == 8);
  487.            
  488.             output_high(motorchave);
  489.            
  490.             break;
  491.            
  492.             case 9: // continuação do molhor curto (+10 minutos)
  493.            
  494.             encher(20);
  495.            
  496.             bater(86,500,1);
  497.            
  498.             molho(300,2);
  499.            
  500.             output_low(motorchave);
  501.            
  502.             do
  503.             {
  504.                piscaled(1,250);
  505.             }
  506.             while(chavefun == 9);
  507.            
  508.             output_high(motorchave);
  509.            
  510.             //bip(500);
  511.            
  512.             break;
  513.            
  514.             case 10: // agitação por 20 minutos
  515.            
  516.             encher(20);
  517.            
  518.             bater(172,500,4);
  519.            
  520.             output_low(motorchave);
  521.            
  522.             do
  523.             {
  524.                piscaled(1,250);
  525.             }
  526.             while(chavefun == 10);
  527.            
  528.             output_high(motorchave);
  529.            
  530.             break;
  531.            
  532.             case 11: // continuação da agitação (+ 20 minutos)
  533.            
  534.             encher(20);
  535.            
  536.             bater(172,500,4);
  537.            
  538.             output_low(motorchave);
  539.            
  540.             do
  541.             {
  542.                piscaled(1,250);
  543.             }
  544.             while(chavefun == 11);
  545.            
  546.             output_high(motorchave);
  547.            
  548.             //bip(500);
  549.            
  550.             break;
  551.            
  552.             case 12: // enxágue (extração da agua (5 minutos)
  553.            
  554.             exaustao(180);
  555.             enxague(15);
  556.            
  557.             output_low(motorchave);
  558.            
  559.             do
  560.             {
  561.                piscaled(1,250);
  562.             }
  563.            
  564.             while(chavefun == 12);
  565.            
  566.             output_high(motorchave);
  567.                        
  568.             break;
  569.            
  570.             case 13: // continuação do anchague (começa a centrifugar jogando agua dentro e fora) +5 minutos
  571.                        
  572.             encher(20);
  573.            
  574.             bater(172,500,6);
  575.            
  576.             exaustao(300);
  577.            
  578.             output_low(motorchave);
  579.            
  580.             do
  581.             {
  582.                piscaled(1,250);
  583.             }
  584.             while(chavefun == 13);
  585.            
  586.             output_high(motorchave);
  587.            
  588.             //bip(500);
  589.            
  590.             break;
  591.            
  592.             case 14: // inicio da centrifugação (começa a centrifugar jogando agua dentro e fora) +5 minutos
  593.            
  594.             enxague(15);
  595.            
  596.             output_low(motorchave);
  597.            
  598.             do
  599.             {
  600.                piscaled(1,250);
  601.             }
  602.             while(chavefun == 14);
  603.            
  604.             output_high(motorchave);
  605.            
  606.            
  607.             break;
  608.            
  609.             case 15: // centrfugação por 10 minutos.
  610.            
  611.             centrifugar(600);
  612.            
  613.             output_low(motorchave);
  614.            
  615.             do
  616.             {
  617.                piscaled(1,250);
  618.             }
  619.             while(chavefun == 15);
  620.            
  621.             output_high(motorchave);
  622.            
  623.             //bip(1000);
  624.             LD = 0;
  625.            
  626.             break;
  627.          }
  628.          
  629.      
  630.       }
  631.       else if (LD == 0)
  632.       {
  633.          delay_ms(50);
  634.          output_high(LED);
  635.       }
  636.    }
  637.  
  638. }
Add Comment
Please, Sign In to add comment