interrupciones matriz

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
Nicolas_11
Date:
Thu Oct 18 13:14:45 2018 +0000
Commit message:
interrupciones

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Oct 18 13:14:45 2018 +0000
@@ -0,0 +1,215 @@
+#include "mbed.h"
+SPI deviceM(PB_15, PB_14, PB_13);
+DigitalOut ssel (PB_12);
+Serial a(USBTX,USBRX);
+InterruptIn button(USER_BUTTON);
+InterruptIn button2(PA_13);
+#define  uint8_t unsigned char
+int Tipofig=0;
+int vcol;
+float Vel=0.3;
+int grado=0;
+int in,out;
+int lim;
+int lim2;
+int m;
+int hhh;
+int col;
+uint8_t Matr[9]={0,0,0,0,0,0,0,0,0};
+uint8_t F_t[3]={0b11100000,0b01000000,0};
+uint8_t F_s[3]={0b11000000,0b01100000,0};
+uint8_t F_c[3]={0b11000000,0b11000000,0};
+uint8_t F_l[3]={0b11000000,0b10000000,0b10000000};
+uint8_t F_I[3]={0b10000000,0b10000000,0b10000000};
+int poscol;
+ 
+void sendSPI(uint8_t d1, uint8_t d2)
+{
+    deviceM.unlock();
+    ssel=0;
+    deviceM.write(d1); 
+    deviceM.write(d2);  
+    ssel=1;
+    deviceM.lock(); 
+}
+   
+void borrar()
+{
+ for(int i;i<=8;i++)   {
+     sendSPI(i,0);
+     }
+}
+   
+void inicializar(){
+                
+                    a.baud(9600);
+                    sendSPI(0x0c,1);
+                    sendSPI(0x09,0);
+                    sendSPI(0x0A,0x01);
+                    sendSPI(0x0F,1);
+                    wait (0.5);
+                    sendSPI(0x0F,0);
+                    wait(0.5);
+                    sendSPI(0xB,0x7);    
+                    borrar();
+    }
+    
+void Rx_interrupt();
+
+void pressed()
+{
+     lim2--;
+     if(lim2<2){
+        lim2=1;
+        }
+     lim2=(hhh)-lim2;
+    a.printf("valor  %d\n",lim2);
+    return;
+}
+void pressed2()
+{
+    lim2++;
+    if(lim2>=8){
+        lim2=8;
+        }  
+    a.printf("valor2  %d\n",lim2);
+    return;
+}
+
+void scan(uint8_t *sc,uint8_t *fli,uint8_t tras)
+{
+    int i;
+    int f;
+    uint8_t t;
+    for(i=1;i<=8;i++)
+    {   
+        t=*(fli)>>(tras-1);
+        if(i>7){f=(*(sc+(8)))&(t);break;}
+        
+        else{f=(*(sc+(i+1)))&(t);}
+              
+        if(f>0){lim=i;break;}    
+        else{lim=8;} 
+    }  
+    a.printf("\n stop de fila \n %d",i);
+    a.printf("\n limite \n %d",lim);
+}
+
+void save(uint8_t *vC,uint8_t  col)
+{  
+    hhh=col;
+    if((*(vC))==0b10000000 && (*(vC+1))==0b10000000&& (*(vC+2))==0b10000000 && col==7 ){col=7;}
+    if((*(vC))==0b10000000 && (*(vC+1))==0b10000000&& (*(vC+2))==0b10000000 && col==8 ){col=7;}
+    if((*(vC))==0b11000000 && (*(vC+1))==0b11000000 && col==8 ){col=8;}
+    if(col>=6){col=6;}
+    uint8_t dat [8];
+    scan(Matr,vC,col);
+    int i;
+    int j=1;
+    int h=1;
+    lim2=col;
+    a.printf("\n limite led \n %d",lim);
+ 
+    for(i=1;i<=lim;i++){
+    
+             if(i>=1){
+            
+            //button.fall(&pressed);
+            //button2.fall(&pressed2);
+             j=i-1;
+             h=i-2;
+             col=lim2;
+             dat[1]=((*(vC))>>col-1) ;
+             dat[2]=(*(vC+1)>>col-1) ;
+             dat[3]=(*(vC+2)>>col-1) ;
+             uint8_t e=~((0b11100000)>>col-1);
+             /*
+             if(i>=2){
+             dat[1]=(((*(vC))>>col-1))<<(m) ;
+             dat[2]=((*(vC+1)>>col-1))<<(m) ;
+             dat[3]=((*(vC+2)>>col-1))<<(m);
+             a.printf("\n limit \n %d",m);
+             }
+             */
+             Matr[i]=dat[1] | Matr[i];
+             Matr[j]=((dat[2] | Matr[j])&(dat[2]|e));
+             Matr[h]=((dat[3] | Matr[h])&(dat[3]|e));
+             if(i>=3){Matr[i-3]=Matr[i-3]&e;}
+             
+             sendSPI(i,(Matr[i]));
+             sendSPI(j,(Matr[j]));
+             sendSPI(h,(Matr[h]));
+             sendSPI((i-3),(Matr[i-3]));
+             wait(Vel);  
+             }
+    if(i>=8){break;}
+    }   
+}
+
+
+
+void giro(uint8_t *f,uint8_t col,uint8_t gi)
+     {  
+     uint8_t a[3]={0,0,0};
+     int i;
+     int j;
+         switch(gi){    
+         case 0:save(f,col);break;
+         case 1:
+         for(j=0;j<3;j++){
+            for(i=0;i<3;i++){
+             a[i]=((((*(f+j))<<2-i)&0b10000000)>>j)+a[i];
+            }
+         }   
+         save(a,col);
+         break;
+         case 2:
+         for(j=0;j<3;j++){
+            for(i=0;i<3;i++){
+             a[i]=((((*(f+(2-i)))>>2-j)&0b00100000)<<j)+a[i];
+            }
+            }
+         save(a,col);
+         break;
+         case 3:
+         for(j=0;j<3;j++){
+            for(i=0;i<3;i++){
+             a[i]=((((*(f+j))>>2-i)&(0b00100000))<<j)+a[i];
+            }
+          }   
+         save(a,col);
+         break;
+         default:
+         break;
+         }     
+     }
+
+int main() {
+                    inicializar();   
+                      button2.fall(&pressed;
+                      button.fall(&pressed);              
+                    while(1){
+                          
+                        in=a.getc();
+                        Tipofig=a.getc();
+                        vcol=a.getc();
+                        grado=a.getc();
+                        out=a.getc();
+                        if(in==60 && 1<=Tipofig<=5 && 0<vcol<=7 && 0<=grado<=3 && out==62){
+                          switch(Tipofig)
+                          {
+                           case 1:giro(F_t,vcol,grado); break;
+                           case 2:giro(F_s,vcol,grado); break;
+                           case 3:giro(F_c,vcol,grado); break;
+                           case 4:giro(F_l,vcol,grado); break;
+                           case 5:giro(F_I,vcol,grado); break;
+                           default:break;
+                          }
+                        }
+                        else{
+                            break;
+                            }
+                     }
+                    
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Thu Oct 18 13:14:45 2018 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed/builds/e95d10626187
\ No newline at end of file