Macrovision

Matriz de LED de 64 pixels

Aug 31st, 2017 (edited)
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 10.43 KB | None | 0 0
  1. /* **********************************************************************
  2.    ** Matriz de LED de 64 pixels **.
  3.     ** Autor: El Guajirigallo**
  4.      ** https://youtu.be/3geIbQzH6Xc **
  5. */
  6.              
  7. # include <16F877A.h>
  8. # use Delay(clock=4000000)
  9. # use Fast_io(b)
  10. # use Fast_io(c)
  11. # use fast_io(d)
  12. # fuses XT,NOWDT
  13. # byte PoRt_a = 0x05
  14. # byte PoRt_B = 0x06
  15. # byte PoRt_c = 0x07
  16. # byte PoRt_d = 0x08
  17. //# int_ext
  18.  
  19.   void Stop(){
  20.   int j,x,y,z;
  21.   char *w;
  22.   long r,s=0;  
  23.   int a;
  24.   int b=0;
  25.    
  26.  char LeTra[]=  {
  27.                    0x00,0x00,0x00,0x00,0x00,0x00,//espacio
  28.                    0x72,0xf9,0x89,0x89,0x8f,0x46,//S                
  29.                    0x01,0x01,0xff,0xff,0x01,0x01,//T
  30.                    0x3c,0x7e,0x81,0x81,0x7e,0x3c,//O
  31.                    0x0e,0x11,0x91,0xff,0xff,0x81,//P  
  32.                    0x00,0x00,0x00,0x00,0x00,0x00,//espacio
  33.                 };
  34.                
  35.    do{
  36.       a=0;
  37.       r=0;
  38.       w=&LeTra[b];
  39.      
  40.        
  41.         for(j=0;j<6;j++){        // MUETRA LAS 6 LETRAS          
  42.          s=0b0100000000000000;   //EMPIEZO EN EL BIT MAS SIGNIFICATIVO Y FUERA DE LA MATRIZ.
  43.         for(x=0;x<5;x++){        // DESPLAZO S A LA DERECHA 2 POSICIONES 5 VECES PARA LOGRAR EL ARRAY    
  44.          r=s;
  45.        
  46.         for(y=0;y<=15;y++){     //AQUI REPITO LA LETRA 15 VECES PARA QUE SEA VISIBLE.      
  47.          for(z=0;z<6;z++){      // EN ESTE FOR FORMO LA LETRA QUE SE VA A MOSTRAR        
  48.          PoRt_c=r;
  49.          PoRt_D= *(w+b);        //MUESTRO DE SEIS BYTES AND SEIS BYTE POR EL PUERTO_D(LETRAS)
  50.          DeLay_ms(1);
  51.          b++;
  52.          r=r>>1;              
  53.        }                        // FIN DEL FOR QUE FORMA LAS LETRAS
  54.          r=s;      
  55.          b=0;
  56.        }
  57.          s=s>>2;
  58.          //e++;
  59.        }
  60.          a=a+6;                //INCREMENTO A DE SEIS EN SEIS  QUE ES EL ANCHO DE LAS LETRAS.                                    
  61.          w=&LeTra[a];          //ME MUEVO EN EL ARRAY CADA SEIS POCICIONES PARA RECORRER TODAS LAS LETRAS.        
  62.        }
  63.      
  64.      }while(!input(pin_a0) || (!input(pin_a1)));
  65.  }
  66.  //End_Rb0_Interrupt------------------------------------------------------------
  67.  
  68.   int R_arrow[]={ 0x08,0x14,0x22,0x49,0x08,0x08,0x08,0x08} ;//RIGHT ARROW
  69.   int l_arrow[]={ 0x08,0x08,0x08,0x08,0x49,0x22,0x14,0x08} ;//LEFT ARROW
  70.   int Clear_Dir[8]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};// _limpiar_Direccion
  71.   int direction[8];//ARREGLO DE 8 BYTE PARA USARLO COMO DIREECION EN QUE SE MUEVE LA FLECHA.
  72.   long v;
  73.   //----------------------------------------------------------------------------
  74.   void arrow_right(void);//FUNTION QUE MUUEVE LA FLECHA ALA DERECHA
  75.   void arrow_left(void);//FUNTION QUE MUEVE LA FLECHA ALA ISQUIERDA
  76.   void Adv(void); //FUNTION QUE MUSTRA LOS ANUNCIOS
  77.   void strobe(void);
  78.   //main------------------------------------------------------------------------
  79.   void main(){  
  80.         //EnaBle_InteRRupts(global);
  81.         //EnaBle_InteRRupts(int_ext);
  82.         //ext_int_edge(h_to_l);
  83.         set_tris_a(0x0f);
  84.         set_tris_b(0x00);
  85.         set_tris_c(0x00);
  86.         set_tris_d(0x00);
  87.          //strobe();
  88.  WHILE(1){      
  89.            Adv();
  90.        
  91.  do{
  92.    
  93.     if(!input(pin_a0)&& (!input(pin_a1))){
  94.    
  95.       Stop();
  96.     }else
  97.      if(!input(pin_a0)&& input(pin_a1))
  98.    {
  99.      strcpy(direction,Clear_Dir);
  100.      strcpy(direction,R_arrow);
  101.      v=0b0000000010000000;
  102.      arrow_right();
  103.    
  104.    }
  105.     if(!input(pin_a0)&& (!input(pin_a1)))
  106.     {
  107.    
  108.       Stop();
  109.     }else
  110.     if(!input(pin_a1))//&& input(pin_a0))
  111.    {
  112.      strcpy(direction,Clear_Dir);
  113.      StRcpy(direction,l_arrow);
  114.      v=0b0000000100000000;
  115.      arrow_left();
  116.      
  117.    }
  118.      
  119.  }While((!input(pin_a0))||(!input(pin_a1)));
  120.      
  121. }
  122.   }
  123.  
  124. //Funtions----------------------------------------------------------------------
  125.    void arrow_right(){
  126.      
  127.        int t,*p,R,h,i=0;
  128.        long c=0;
  129.        p=&direction[i];      
  130.        for(h=0;h<15;h++){        
  131.        c=v;
  132.        for(R=0;R<=8;R++){    
  133.        for(t=0;t<8;t++){      
  134.          PorT_C=c;
  135.          PorT_D= *(p+i);
  136.          deLay_ms(1);
  137.          i++;
  138.          c>>=1;
  139.        }
  140.          c=v;        
  141.          i=0;
  142.        }
  143.        v=v<<1;
  144.          
  145.        }  
  146.          port_d=0x00;
  147.          deLay_ms(50);
  148.        }
  149.    
  150.    
  151.  //arrow_left-------------------------------------------------------------------
  152.  
  153.  void arrow_left(){
  154.    
  155.        int t,*p,R,h,i=0;
  156.        long c=0;
  157.        p=&direction[i];        
  158.        for(h=0;h<15;h++){        
  159.        c=v;
  160.        for(R=0;R<=8;R++){    
  161.        for(t=0;t<8;t++){      
  162.          port_c=c;
  163.          PORT_D= *(p+i);
  164.          deLay_ms(1);
  165.          i++;
  166.          c>>=1;
  167.        }
  168.          c=v;        
  169.          i=0;
  170.        }
  171.        v=v>>1;
  172.          
  173.        }
  174.          port_d=0x00;
  175.          deLay_ms(50);
  176.        }
  177.    
  178.   ///////////////////////////////////////////////////////////////////////
  179.   void Adv(){                      
  180.                        if((!input(pin_a0))||(!input(pin_a1))){goto salir ;} //
  181.                        deLay_ms(10);
  182.                        if((!input(pin_a0))||(!input(pin_a1))){goto salir ;}
  183.                        deLay_ms(10);
  184.                        if(!input(pin_a3)){strobe();}
  185.                        
  186.                            
  187. int const tabla[]={
  188.                          
  189.                         /*
  190.                           aqui dentro van los caracteres que la matriz va a mostrar
  191.                           ejemplo:
  192.                            
  193.                           0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  194.                          0xfc,0xfe,0x12,0x12,0x12,0xfc,0x00,      //A
  195.                          0x6c,0xfe,0x92,0xaa,0x44,0xa0,0x10,0x00, //&
  196.                          0xfc,0xfe,0x12,0x12,0x12,0xfc,0x00,      //A
  197.                          0x00,0x00,0x00,
  198.                          0xfe,0xfe,0x92,0x92,0x82,0x00,           //E
  199.                          0xfe,0xfe,0x80,0x80,0x80,0x00,           //L
  200.                          0x78,0xfc,0x94,0x94,0x9c,0x98,0x00,      //e
  201.                          0x78,0xfc,0x84,0x84,0x48,0x00,           //c
  202.                          0x04,0x7e,0xfe,0x84,0x40,0x00,           //t
  203.                          0xf8,0xfc,0x04,0x04,0x08,0x00,           //r
  204.                          0xf6,0xf6,0x00,0x00,                     //i
  205.                          0x78,0xfc,0x84,0x84,0x48,0x00,           //c
  206.                          0x60,0xf4,0x94,0xfc,0xf8,0x80,0x00,      //a
  207.                          0xfe,0xfe,0x80,0x80,0x00,//                l
  208.                          0x00,0x00,0x00,0x00,
  209.                          0x86,0x8f,0x89,0x89,0xf9,0x71,0x00,      //S
  210.                          0x78,0xfc,0x84,0xfc,0x78,0x00,           //o
  211.                          0xfe,0xfe,0x80,0x80,0x00,                //l
  212.                          0x7c,0xfc,0x80,0x80,0x7c,0x00,           //u
  213.                          0x04,0x7e,0xfe,0x84,0x40,0x00,           //t
  214.                          0xf6,0xf6,0x00,0x00,                     //i
  215.                          0x78,0xfc,0x84,0xfc,0x78,0x00,           //o
  216.                          0xfc,0xfc,0x0c,0x04,0xfc,0xf8,0x00,      //n
  217.                          0x88,0x9c,0x94,0x94,0xf4,0x64,0x00,      //s
  218.                         */
  219.                   };
  220.                                        
  221.                         if((!input(pin_a0))||(!input(pin_a1))){goto salir ;}
  222.             int h;
  223.             long t, r;
  224.          
  225.              const byte  ColuMn[8]={1,2,4,8,16,32,64,128};                                                                
  226.  while(1){
  227.      
  228.           for(R=0;R<995;R++){      
  229.           for(h=0;h<10;h++){
  230.           for(t=0;t<8;t++){
  231.           port_c=(ColuMn[t]);
  232.           port_D=(tabla[t+r]);      
  233.           deLay_ms(1);                        
  234.        }
  235.                           if((!input(pin_a0))||(!input(pin_a1))){goto salir ;}                        
  236.                           if(!input(pin_a3)){strobe();}                      
  237.      }
  238.                              
  239.    }                                                        
  240.                           if((!input(pin_a0))||(!input(pin_a1))){goto salir ;}                          
  241.                           if(!input(pin_a3)){strobe();}  
  242.  }
  243.                                        
  244.             port_c=3;
  245.             port_d=0x18;
  246.             delay_ms(20);
  247.             port_d=0x00;;
  248.             delay_ms(50);
  249.   salir:
  250.   deLay_ms(1);
  251. }
  252. //strobe------------------------------------------------------------------------
  253.   void strobe(){
  254.     int i,j,x;
  255.     long k=0b0000000000111;
  256.   while(1){
  257.   if((!input(pin_a0))||(!input(pin_a1))){goto loop ;}
  258.       for(j=0;j<40;j++){
  259.        port_c=0x00;
  260.        delay_ms(50);
  261.       for(i=0;i<2;i++){
  262.        port_d=0x00;
  263.        port_c=0x00;
  264.        delay_ms(50);
  265.        port_d=0x18;
  266.       if(j<5 ){port_c=0x03;}
  267.       if(j>5 && j<10 ){port_c=0x07;}
  268.       if(j>10 && j<25){port_c=0x0f;}
  269.       if(j>25 && j<32){port_c=0xff; port_d=0x0f;}
  270.       if(j>32 && j<40){port_c=0x0f; port_d=0xff;}      
  271.        delay_ms(20);
  272.        port_c=0x00;
  273.        delay_ms(50);      
  274.       if(j>5 && j<10 ){port_c=0x07;}
  275.       if(j>10 && j<25){port_c=0x0f;}
  276.       if(j>25 && j<32){port_c=0xff; port_d=0x0f;}
  277.       if(j>32 && j<40){port_c=0x0f; port_d=0xff;}
  278.        delay_ms(20);
  279.     }
  280.         if((!input(pin_a0))||(!input(pin_a1))){goto loop ;}
  281.          port_c=0x00;
  282.          delay_ms(50);
  283.       if(j<5 ){port_c=0xc0;}
  284.       if(j>5 && j<10 ){port_c=0xe0;}
  285.       if(j>10 && j<25 ){port_c=0xf0;}
  286.       if(j>25 && j<35){port_c=0xff; port_d=0xf0;}
  287.       if(j>35 && j<40){port_c=0xf0; port_d=0xff;}
  288.         delay_ms(20);
  289.         port_c=0x00;
  290.         delay_ms(50);
  291.       if(j<5 ){port_c=0xc0;}
  292.       if(j>5 && j<10 ){port_c=0xe0;}
  293.       if(j>10 && j<25 ){port_c=0xf0;}
  294.       if(j>25 && j<35){port_c=0xf0; port_d=0xff;}
  295.       if(j>35 && j<40){port_c=0xff; port_d=0xf0;}
  296.        delay_ms(20);
  297.      
  298.  }
  299.       for(i=0;i<=5;i++){
  300.       k=0b0000000000111;
  301.       for(x=0;x<10;x++){
  302.       k<<=1;
  303.       for(j=0;j<=5;++j){
  304.       if((!input(pin_a0))||(!input(pin_a1))){goto loop ;}
  305.              
  306.             port_c=k;
  307.             delay_ms(50);
  308.             port_d=0xff;              
  309.             delay_ms(20);              
  310.             port_d=0x00;;              
  311.  }  
  312.   }
  313.        if((!input(pin_a0))||(!input(pin_a1))){goto loop ;}
  314.   }
  315.      i=0;
  316.      port_d=0x00;
  317.      port_c=0x00;
  318.      delay_ms(500);
  319.  }
  320.   loop:
  321.   delay_ms(1);
  322.  }
Add Comment
Please, Sign In to add comment