Advertisement
Macrovision

16 Channel Timer

May 18th, 2022 (edited)
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 10.87 KB | Software | 0 0
  1. //Autor: El Guajirigallo//
  2. //Docificador Ver3.0//
  3.  
  4. # include <16F877A.h>
  5. //# include <ios.h>
  6. # use Delay(clock=4000000)
  7. # use Fast_io(c)
  8. # fuses XT,NOWDT
  9. #USE FAST_IO (A)
  10. #USE FAST_IO (B)
  11. //-"direccionamiento de ports-//
  12. #byte port_A = 0x05  
  13. #byte port_B = 0x06
  14. #byte port_c = 0x07  
  15. #byte port_d = 0x08
  16. #byte port_e = 0x09
  17. #byte PCON = 0x8e
  18. #define data_pin PIN_b1
  19. #define clock_pin PIN_b4
  20. #define latch_pin PIN_b3
  21.  
  22. /*-"Declaracion de funciones"-*/
  23.  
  24.  void write_data(int16 number);
  25.  void write_Nunbers(int16 numbers[]);
  26.  void Retardo_03seg(void);
  27.  void Docis(int MemoryValue,int PinValue )  ;
  28.        
  29.        
  30.     # int_ext
  31.  void interrupt()
  32. {
  33. int16 const  mapaTimer[]={0x631,0x5B31,0x4f31,0x6631,0x6d31,0x7d31,0x0731,0x7f31,0x6f31,0x3F06,0x0606,0x5b06,0x4f06,0x6606,0x6d06,0x7d06};
  34. int i=0;
  35.  
  36. do{
  37.      write_data(mapaTimer[i]);
  38.      delay_ms(500);
  39.      SwitCh(i){
  40. case(0):          //timer1
  41.    //docis0();
  42.    Docis(0,63 );
  43.    Retardo_03seg();
  44.    break;
  45. case(1):          //timer2
  46.   //docis1();
  47.    Docis(1,68 );
  48.    Retardo_03seg();
  49.    break;
  50.  case(2):          //timer3
  51.   //docis2();
  52.    Docis(2,64 );
  53.    Retardo_03seg();
  54.    break;
  55.  case(3):          //timer4
  56.    //docis3();
  57.    Docis(3,65 );
  58.    Retardo_03seg();
  59.    break;
  60.  case(4):          //timer5
  61.    //docis4();
  62.    Docis(4,59 );
  63.    Retardo_03seg();
  64.    break;
  65.  case(5):          //timer6
  66.    //docis5();
  67.    Docis(5,58 );
  68.    Retardo_03seg();
  69.    break;
  70.  case(6):        //timer7
  71.    //docis6();
  72.    Docis(6,57 );
  73.    Retardo_03seg();
  74.    break;
  75.  case(7):          //timer8
  76.    //docis7();
  77.    Docis(7,56 );
  78.    Retardo_03seg();
  79.    break;
  80.  case(8):         //timer9
  81.    //docis8();
  82.    Docis(8,67 );
  83.    Retardo_03seg();
  84.    break;
  85.  case(9):          //timer10
  86.    //docis9();
  87.    Docis(9,66 );
  88.    Retardo_03seg();
  89.    break;
  90.  case(10):          //timer11
  91.    //docis10();
  92.    Docis(10,60 );
  93.    Retardo_03seg();
  94.    break;
  95.  case(11):          //timer12
  96.    //docis11();
  97.    Docis(11,61 );
  98.    Retardo_03seg();
  99.    break;
  100.  case(12):          //timer13
  101.    //docis12();
  102.    Docis(12,62 );
  103.    Retardo_03seg();
  104.    break;
  105.  case(13):          //timer14
  106.    //docis13();
  107.    Docis(13,72 );
  108.    Retardo_03seg();
  109.    break;
  110.    case(14)://timer15
  111.    //docis14();
  112.    Docis(14,73 );
  113.    Retardo_03seg();
  114.    break;
  115.  case(15):          //timer16
  116.    //docis15();
  117.    Docis(15,74 );
  118.    Retardo_03seg();
  119.    write_data(0x543f);
  120.    delay_ms(50);
  121.    break;
  122.  
  123.  }//find del sw
  124.  i++;
  125. }while(i<=15);//fin del do-while
  126.    delay_ms(500);
  127.    clear_interrupt(int_ext);
  128.  }//fin de la int
  129.      
  130.  /*-"Declaracion de VARIABLES Globales"-*/
  131.     int16 const digitos[]={0x3f3f,0x063f,0x5B3F,0x4f3f,0x663f,0x6d3f,0x7d3f,0x073f,        // Digitos para mostrar por Display del 1 al 99
  132.                            0x7f3f,0x6f3f,0x3F06,0x0606,0x5b06,0x4f06,0x6606,0x6d06,
  133.                            0x7d06,0x0706,0x7f06,0x6f06,0x3f5b, 0x065b,0x5B5b,0x4f5b,
  134.                            0x665b,0x6d5b,0x7d5b,0x075b,0x7f5b,0x6f5b,0x3F4f,0x064f,
  135.                            0x5b4f,0x4f4f,0x664f,0x6d4f,0x7d4f,0x074f,0x7f4f,0x6f4f,
  136.                            0x3f66,0x0666,0x5B66,0x4f66,0x6666,0x6d66,0x7d66,0x0766,
  137.                            0x7f66,0x6f66,0x3F6d,0x066d,0x5b6d,0x4f6d,0x666d,0x6d6d,
  138.                            0x7d6d,0x076d,0x7f6d,0x6f6d,0x3f7d,0x067d,0x5B7d,0x4f7d,
  139.                            0x667d,0x6d7d,0x7d7d,0x077d,0x7f7d,0x6f7d,0x3F07,0x0607,
  140.                            0x5b07,0x4f07,0x6607,0x6d07,0x7d07,0x0707,0x7f07,0x6f07,
  141.                            0x3f7f,0x067f,0x5B7f,0x4f7f,0x667f,0x6d7f,0x7d7f,0x077f,
  142.                            0x7f7f,0x6f7f,0x3F6f,0x066f,0x5b6f,0x4f6f,0x666f,0x6d6f,
  143.                            0x7d6f,0x076f,0x7f6f,0x6f6f
  144.                           };
  145.    
  146.     int const EE_Address[]={0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f};  // Registro de la eeprom donde se guarda el tempo de docificacion
  147.     int16 const  mapaTimer[]={0x631,0x5B31,0x4f31,0x6631,0x6d31,0x7d31,0x0731,0x7f31,0x6f31};//Numeros del uno al Nueve.
  148.     int16  numeroDies[]={0x00,0x00,0x0600,0x3100,0x0631,0x3F06,0x3F06,0x3F06};
  149.     int16  numeroEleven[]={0x00,0x00,0x0600,0x3100,0x0631,0x0606,0x0606,0x0606};
  150.     int16  numeroTuelve[]={0x00,0x00,0x0600,0x3100,0x0631,0x5b06,0x5b06,0x5b06};
  151.     int16  numero13[]={0x00,0x00,0x0600,0x3100,0x0631,0x4f06,0x4f06,0x4f06};
  152.     int16  numero14[]={0x00,0x00,0x0600,0x3100,0x0631,0x6606,0x6606,0x6606};
  153.     int16  numero15[]={0x00,0x00,0x0600,0x3100,0x0631,0x6d06,0x6d06,0x6d06};
  154.     int16  numero16[]={0x00,0x00,0x0600,0x3100,0x0631,0x7d06,0x7d06,0x7d06};
  155.    // int16  animation[]={0x30,0x06,0x600,0x3000};
  156.     int const animationNun=0b00000000000110;
  157.     //int16 const numbers[]=0x00;
  158.     short i;
  159.     int g=0;
  160.     int z =0;
  161.     int n=0x00;
  162.     int j=0;
  163.     int w=0;
  164.  
  165.      
  166.     VOID MAIN() {
  167.         enable_interrupts(global);
  168.         enable_interrupts(int_ext);
  169.         ext_int_edge(h_to_l);
  170.         SET_TRIS_A(0x07);
  171.         SET_TRIS_b(0x01);
  172.         SET_TRIS_c(0x00);
  173.         SET_TRIS_d(0x00);
  174.         SET_TRIS_e(0x00);
  175.         output_b(0xff);
  176.         output_HIGH(pin_B6);
  177.         output_c(0xff);
  178.         output_d(0xff);
  179.         output_e(0xff);
  180.        
  181.        
  182.      if(!bit_test(PCON,1)){
  183.        BIT_SET(PCON,1);
  184.       do{
  185.         write_data(0x543f);          // Entro por Apagon / Muestro T1 en el dsplay y espero 1 segundo
  186.         delay_ms(100);
  187.         g++;
  188.      }while(G<=10);
  189.        
  190.   }else if (bit_test(PCON,1)){       // Set 0x00 Para Limpiar los registros de la EEprom  Desde 0x00 hasta 0x0f Cuando entro por Reset
  191.      
  192.         write_data(0x631);           // Escrivo en el Display T1
  193.         for(int i=0;i<=15;i++){      //
  194.         write_eeprom(i,0x00);        // limpio la eeprom
  195.         }
  196.   }
  197. //while(true){
  198.        write_data(0x543f);            // Write On Again (Muesto On en el display)
  199.    do{
  200.        output_Toggle(pin_B6);         //Ago que el led de power blinkin a 250 ms)
  201.        delay_Ms(250);                 //Aqui Paro El contador del Programa para evitar que no sea llamado desde otro punto que no sea precionando A1
  202.      }while(input(pin_a1));           // preciono la Entrada A1 para selecionar el timer A setiar
  203.        output_high(pin_B6);           // encienfo fijo el led de power
  204.                          
  205.  while(true){
  206.     do{
  207.         if(!input(pin_a0) || (!input(pin_a2))){// si pin A0 o Pin_a1 ==0 ir al timer para add o disminuir Tiempo
  208.          //WHILE(1){
  209.      
  210.            if(input(pin_a2) == 0) {        //inc o dec z depen del pin que este precionado A0,A2        
  211.               if (z <= 0){                          
  212.                z = 99;              
  213.              }
  214.              z--;
  215.              delay_ms(100);
  216.            }
  217.                            
  218.           if(input(pin_a0) == 0) {                  
  219.              if (z >= 99){                          
  220.                z = 0;                            
  221.            }
  222.            z++;
  223.            delay_ms(100);
  224.          }
  225.                          
  226.            write_eeprom(EE_Address[n],z);           // escribo en la EE el valor decimal de Z en direcion N, N puede tomar valores desde 0x00 hasta 0x0f
  227.           // if(!input(pin_a2)) {GOTO T_backward;}
  228.            //if(!input(pin_a1)) {GOTO T_forward;}     //llamado desde la rutina que seleciona el numero de timer.
  229.                      
  230.            write_data(digitos[z]);                  //muetro por display el valor de Z que es el setpoint del timer.
  231.            //delay_ms(250);
  232.          //}// setTimerEnd
  233.         }
  234.       }while(input(pin_a1));          // preciono la Entrada A1 para selecionar el timer a setiar o moverme entre ellos(timer del 1 al 16)
  235.      
  236.       if(w<=8) write_data(mapaTimer[w]);//Aqui si el registro W toma valor de 0 a 7 y ese valor lo uso para escrivir  el valor almacenado en el Array MapaTimer
  237.         switch(w){    
  238.       case(9):write_Nunbers(numeroDies);
  239.           break;
  240.       case(10):write_Nunbers(numeroEleven);
  241.           break;
  242.       case(11):write_Nunbers(numeroTuelve);
  243.           break;
  244.       case(12):write_Nunbers(numero13);
  245.           break;
  246.       case(13):write_Nunbers(numero14);
  247.           break;
  248.       case(14):write_Nunbers(numero15);
  249.           break;
  250.      case(15):write_Nunbers(numero16);
  251.           break;
  252.         }
  253.            
  254.       delay_ms(500);
  255.       //write_data(read_eeprom(0x00));
  256.       write_data(digitos[(read_eeprom(w))]);        //Printeo  el valor decimal almacenado en la variable Z (timer_1 Valor-actual)    
  257.       w++;      
  258.       n=w-1;
  259.       z=0;    
  260.       if(w>=16){
  261.       w=0;
  262.       }
  263.   }
  264.  
  265.  
  266.      }// End del Main
  267.      
  268.      
  269.      //FUNCION PARA ESCRBOR LOS  DIGITOS EN EL DISPLAY
  270.  
  271.  void write_data( int16 number){    
  272.        for( int16 j = 0x8000; j > 0; j = j >> 1) {
  273.        if(number & j)                            //and ligico entre j y number para detectar bit a bit 0 o 1 de number
  274.        output_high(data_pin);
  275.        //output_low(data_pin);
  276.        //output_high(clock_pin);
  277.        else
  278.        output_low(data_pin);
  279.        output_high(clock_pin);
  280.        output_low(clock_pin);
  281.        }
  282.        output_high(latch_pin);
  283.        output_low(latch_pin);
  284.          
  285.        }
  286.        
  287.        /* Fucion Para La animacion del dispaly Entre Un timer Y otro */
  288.        
  289.        Void Retardo_03seg(){
  290.        delay_ms(250);
  291.      for(int i=0;i<=1;i++){
  292.       for(long j=0;j<=999;j++){
  293.        //delay_ms(1);
  294.          if(j<=125/2){write_data(animationNun<<3);} //Primera barra
  295.          if(j>125/2 && j<=250/2){write_data(animationNun);}//Segunda Barra
  296.          if(j>250/2 && j<=375/2){write_data(animationNun<<11);}//Tercera Barra
  297.          if(j>375/2 && j<=500/2) {write_data(animationNun<<8);}//Cuarta Barra
  298.          if(j>500/2 && j<=625/2){write_data(0x00);}//
  299.          if(j>625/2 && j<=750/2){write_data(animationNun<<11);}//tersera Barra
  300.          if(j>750/2 && j<=825/2){write_data(animationNun);}//2da barra
  301.          if(j>825/2 && j<=1000/2 ){write_data(animationNun<<3);}//1ra barra
  302.          if(j>500 ){write_data(0x00);}
  303.          
  304.         delay_ms(1);
  305.        }
  306.      }
  307.    }  
  308.  
  309.        
  310.  
  311.    
  312.     /* Funcion Que Hace el Efecto que  Los Numero mayor de 9 se desplacen de Derecha a Isquierda */
  313.    
  314.  void write_Nunbers(int16 numbers[]){  // funcion que escribe los numeros del 10 al 16.
  315.   for(int j=0;j<=7;j++){
  316.       write_data(numbers[j]);
  317.       delay_ms(200);
  318.     }
  319.       j=0;
  320.     }
  321.    
  322.    
  323.    
  324.   /* Fucion Para Temporizary  visualizar en el display el conteo regrecivo */
  325.        
  326.  
  327.  
  328. void Docis(int MemoryValue,int PinValue ){
  329.  
  330.     output_low(PinValue);
  331.     int f=read_eeprom(MemoryValue);
  332.     for(int i=0;i<=(read_eeprom(MemoryValue));i++){
  333.       for(long j=0;j<=1000;j++){
  334.         delay_ms(1);
  335.       }
  336.           write_data(digitos[f]);
  337.           f--;
  338.           output_Toggle(pin_B6);
  339.       }
  340.           output_high(PinValue);
  341.           output_high(pin_B6);
  342. }
  343.  
  344.  
  345.  
  346.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement