Advertisement
Macrovision

Systema para riego automatico con regadera

May 18th, 2022 (edited)
27
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 9.71 KB | None | 0 0
  1. /*-systema para riego automatico con manguera y regadera-*/
  2. /*-en este update el display muestra el rate flow en litros. -*/
  3.  
  4. # include <16F877A.h>
  5. #include <stdbool.h>
  6. //# include <ios.h>
  7. # use Delay(clock=4000000)
  8. # use Fast_io(c)
  9. # fuses XT,NOWDT
  10. #USE FAST_IO (A)
  11. #USE FAST_IO (B)
  12. //-"direccionamiento de ports-//
  13. #byte port_A = 0x05  
  14. #byte port_B = 0x06
  15. #byte port_c = 0x07  
  16. #byte port_d = 0x08
  17. #byte port_e = 0x09
  18. #byte PCON = 0x8e
  19. #define data_pin PIN_b1
  20. #define clock_pin PIN_b4
  21. #define latch_pin PIN_b3
  22.  
  23. /*-"Declaracion de funciones"-*/
  24.  
  25.  //int32 seg(int32 num);
  26.  void write_data(int16 disply );
  27.  void write_Nunbers(int16 numbers[]);
  28.  Void AnimationDisply(void);
  29. //void write_Nunbers(void);
  30.  void Retardo_30seg(void);
  31.  void timer_on(void);
  32.  //void timer_off(void);    
  33.        
  34.    /*-"Declaracion de VARIABLES Globales"-*/
  35.  
  36.     int const animationNun=0b00000000000110;   //variable usada para la animacion del disply cuando hay un reset por hardware
  37.     int16 const digitos[]={0x3f3f,0x4f3f,0x7d3f        // Digitos para mostrar por Display del 0 al 29
  38.                           ,0x6f3f,0x7171,0x7171,
  39.                            0x7171,0x7171,0x7171,0x7171,0x3f5b, 0x065b,0x5B5b,0x4f5b,
  40.                            0x665b,0x6d5b,0x7d5b,0x075b,0x7f5b,0x6f5b
  41.                           };
  42.     int16 const RateFlow[]={0x383f,0x3806,0x385B,0x384f,0x3866,0x386d,0x387d,0x3807,0x387f,0x386f};     // caracteres o-li to 9-li a mostrar en el dysplay
  43.    
  44.     int const EE_Address[]={0x00,0x01};  // Registro de la eeprom donde se guarda el tiempo de docificacion
  45.    
  46.     int16 TimerOn[]={0x00,0x00,0x0600,0x3100,0x4031,0x543f,0x543f,0x543f}; //variable usada para animation de caracteres t-on
  47.     int16 TimerOff[]={0x00,0x00,0x0600,0x3100,0x4031,0x715c,0x715c,0x715C};//variable usada para animation de caracteres t-off
  48.     short i;
  49.     int g=0;
  50.     int z =0;
  51.     int n=0x00;
  52.     int j=0;
  53.     int w=0;
  54.     //short boot=1;
  55.      
  56.     VOID MAIN() {
  57.        
  58.         SET_TRIS_A(0x07);
  59.         SET_TRIS_b(0x01);
  60.         SET_TRIS_c(0x00);
  61.         SET_TRIS_d(0x00);
  62.         SET_TRIS_e(0x00);
  63.         output_b(0xff);
  64.         output_HIGH(pin_B6);
  65.         output_c(0x00);
  66.         output_d(0x00);
  67.         output_e(0x00);
  68.         write_eeprom(0x00,0);
  69.         write_eeprom(0x01,0);
  70.        
  71.      
  72.   if(!bit_test(PCON,1)){
  73.        
  74.        BIT_SET(PCON,1);
  75.       do
  76.       {
  77.         write_data(0x543f);          
  78.         delay_ms(100);
  79.         g++;
  80.       }while(G<=10);//me paro aqui un segundo
  81.        Goto  T_forward;
  82.       }else if (bit_test(PCON,1))
  83.       {
  84.           for(int i=0;i<=15;i++)          
  85.           {      
  86.              write_eeprom(i,0x00);//limpio la eeprom
  87.           }
  88.       }
  89. //while(true)
  90.      
  91.    do{
  92.        if(input(pin_b0) == 0) {goto override;}
  93.        AnimationDisply();
  94.        output_Toggle(pin_B6);
  95.      }while(input(pin_a1));           // preciono la Entrada A1 para selecionar el timer A setiar
  96.        output_high(pin_B6);           // encienfo fijo el led de power
  97.        T_forward:                     // etiqueta T_fowar para regresar de la parte donde le doy valor al timer
  98.  while(true)//(Linea 98 to 126) Rutina para Seleccionar Rate Flow  o el Tiempo entere cada riego.
  99.  {
  100.    do{
  101.    
  102.         if(!input(pin_a0) || (!input(pin_a2))) {GOTO set_timer;} // si pin A0 o Pin_a1 ==0 ir al timer para add o disminuir Tiempo
  103.         if(input(pin_b0) == 0) {goto  Automatic;}
  104.      }while(input(pin_a1));          
  105.      
  106.        if(w==0)
  107.        {
  108.           write_Nunbers(Timeron);
  109.           n=0;
  110.           Z=(read_eeprom(0x00));
  111.        }else{
  112.          write_Nunbers(TimerOff);
  113.          n=1;
  114.          Z=(read_eeprom(0x01));
  115.        }
  116.            
  117.          delay_ms(500);
  118.          if(n==0)
  119.          {
  120.             write_data(RateFlow[z]);
  121.          }else{
  122.             write_data(digitos[(read_eeprom(w))]);    
  123.          }
  124.            w++;      
  125.            if(w>1){w=0;}
  126.  }
  127.    //Rutina para comenzar la temporizacion del riego.
  128.   Automatic:
  129.      
  130.     write_Nunbers(Timeron);
  131.     delay_ms(1000);
  132.     output_high(pin_c7);// Salida donde que activa  el contactor para la water poomp
  133.     Retardo_30seg();
  134.    while(1){
  135.  OpenValvula:
  136.     write_Nunbers(Timeron);          
  137.     output_high(pin_D4); // salida para acivar la valvula de 24volt
  138.     delay_ms(1000);
  139.     output_low(pin_c5); //  Red led used to disply manual overide
  140.   for(int i=1;i<=read_eeprom(0x00);i++)
  141.   {
  142.       for(int j=0;j<=11;j++)
  143.      {
  144.        if(input(pin_b0) == 0) {goto override;}
  145.          delay_ms(500);
  146.      }
  147.   }
  148.    
  149.             write_Nunbers(TimerOff);
  150.             output_low(pin_D4);
  151.             delay_ms(1000);
  152.             output_low(pin_D0);
  153.     for (int h=1;h<=read_eeprom(0x01);h++)
  154.     {
  155.        for(int x=0;x<=3;x++)
  156.        {
  157.          if(input(pin_b0) == 0) {goto override;}
  158.          delay_ms(1000);
  159.        }    
  160.     }
  161.    if(input(pin_b0) == 0) {goto override;}
  162.    }
  163.    
  164.    
  165.     override:
  166.      
  167. while(true)
  168. {
  169.            
  170.    do {
  171.           if(!input(pin_a1))
  172.            {
  173.              goto  Automatic;
  174.            }
  175.            output_Toggle(pin_c5);
  176.            delay_ms(250);
  177.        }while(input(pin_b0));
  178.             write_data(0x543f);//display t-on.
  179.             output_low(pin_D4);//apagar valvula de riego.
  180.             output_high(pin_c7);//encender water poomp.
  181.            // delay_ms(1000);
  182.             //output_high(pin_D0);
  183.             output_high(pin_c5);
  184.            // write_data(0x543f);
  185.             delay_ms(450);
  186.    do {
  187.            output_Toggle(pin_c5);
  188.            delay_ms(250);
  189.             if(!input(pin_a1))
  190.             {
  191.               goto OpenValvula;
  192.             }
  193.        }while(input(pin_b0));
  194.             write_data(0x715c);//display t-off.
  195.             delay_ms(50);
  196.             output_low(pin_D4);//apagar valvula de riego.
  197.             output_low(pin_c7);//apagar water poomp.
  198.             //delay_ms(50);
  199.            // output_low(pin_D0);
  200.             output_high(pin_c5);
  201.             write_data(0x715c);
  202.             delay_ms(450);
  203. }
  204.  
  205.    
  206.    
  207.  
  208.     set_timer:
  209.  WHILE(1)
  210.  {
  211.            if(input(pin_a0) == 0)
  212.            {        
  213.               if (z <=0)
  214.               {
  215.                z = 9;  //z = 5;            
  216.               }
  217.                 z--;
  218.              delay_ms(100);
  219.            }
  220.                            
  221.            if(input(pin_a2) == 0)
  222.            {
  223.              if (z >=9)
  224.              {
  225.                z = 0;                            
  226.              }
  227.                z++;
  228.                delay_ms(100);
  229.            }
  230.            
  231.            write_eeprom(EE_Address[n],z);           // escribo en la EE el valor decimal de Z en direcion N, N puede tomar valores desde 0 o 1....
  232.          
  233.            if(!input(pin_a1)) {GOTO T_forward;}     //llamado desde la rutina que seleciona el numero de timer....
  234.            if(input(pin_b0) == 0) {goto  Automatic;}        
  235.            if(n==0){
  236.               write_data(RateFlow[z]);// esta linea para mostrar los litros.....
  237.            }else{
  238.             write_data(digitos[z]);   // esta linea es para mostrar el tiempo ensegundos.....
  239.            }
  240.            delay_ms(250);
  241.  }
  242.          
  243.          
  244.          
  245.       // }
  246.      }// End del Main
  247.      
  248.      
  249.      //FUNCION PARA ESCRBIR LOS  DIGITOS EN EL DISPLAY
  250.  
  251.  void write_data( int16 disply){    
  252.        for( int16 j = 0x8000; j > 0; j = j >> 1) {
  253.        if(disply & j)                               //and ligico entre j y number para detectar bit a bit 0 o 1 de number
  254.        output_high(data_pin);
  255.        //output_low(data_pin);
  256.        //output_high(clock_pin);
  257.        else
  258.        output_low(data_pin);
  259.        output_high(clock_pin);
  260.        output_low(clock_pin);
  261.        }
  262.        output_high(latch_pin);
  263.        output_low(latch_pin);
  264.          
  265.        }
  266.        
  267.        
  268.     Void AnimationDisply()
  269.     {
  270.         for(long j=0;j<=1275;j++)
  271.         {
  272.          if(j<=0  && j<=125){write_data(animationNun<<3);} //Primera barra
  273.          if(j>125 && j<=250){write_data(animationNun);}//Segunda Barra
  274.          if(j>250 && j<=375){write_data(animationNun<<11);}//Tercera Barra
  275.          if(j>375 && j<=500 ) {write_data(animationNun<<8);}//Cuarta Barra
  276.          if(j>500 && j<=625){write_data(0x00);}//
  277.          if(j>625 && j<=750){write_data(animationNun<<8);}//tersera Barra
  278.          if(j>750 && j<=825){write_data(animationNun<<11);}//2da barra
  279.          if(j>825 && j<=975 ){write_data(animationNun);}//1ra barra
  280.          if(j>975 && j<=1125){write_data(animationNun<<3);}//1ra barra
  281.          if(j>1125  && j<=1274 ){write_data(0x00);}
  282.          delay_ms(1);
  283.        }
  284.    }  
  285.        
  286.        
  287.        
  288.         void Retardo_30seg(){
  289.        
  290.         for (int i=0;i<=10;i++){
  291.            for(long j=0;j<=999;j++){
  292.             //if(input(pin_a2) == 0) {goto override;}
  293.            delay_ms(1);
  294.            }
  295.          }
  296.        }
  297.        
  298.        void timer_on(){
  299.        for (int i=0;i<=read_eeprom(0x00);i++){
  300.            for(int j=0;j<=11;j++){
  301.             //if(input(pin_a2) == 0) {goto override;}
  302.            delay_ms(500);
  303.            }
  304.            j=0;
  305.          }
  306.        }
  307.        
  308.        
  309.        void timer_off(){
  310.        for (int i=1;i<=read_eeprom(0x01);i++){
  311.            for(long j=0;j<=20;j++){
  312.            //if(input(pin_a2) == 0) {goto override;}
  313.            delay_ms(500);
  314.            }
  315.            j=0;
  316.          }
  317.        }
  318.        
  319.    
  320.     // Funcion Que Hace el Efecto que  Los Numero mayor de 9 se desplacen de Derecha a Isquierda //
  321.    
  322.  void write_Nunbers(int16 numbers[]){  //
  323.   for(int j=0;j<=7;j++){
  324.       write_data(numbers[j]);
  325.       delay_ms(200);
  326.     }
  327.       j=0;
  328.     }
  329.    
  330.    
  331.    
  332.    
  333.    
  334.    
  335.    
  336.    
  337.    
  338.    
  339.    
  340.    
  341.    
  342.    
  343.    
  344.    
  345.    
  346.    
  347.    
  348.    
  349.    
  350.    
  351.    
  352.    
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement