bien spi no se queda pegado

Dependencies:   mbed

Revision:
0:4b2603e81763
Child:
1:d99b6299bad8
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tets_pc.cpp	Tue Sep 11 21:09:41 2018 +0000
@@ -0,0 +1,195 @@
+#include "mbed.h"
+
+#define DEBUG 1
+
+Serial pc(USBTX,USBRX);   
+SPI deviceM(PB_15, PB_14, PB_13);
+DigitalOut ssel (PB_12);
+
+int matriz[8]={0};
+
+void debuging(char*s,...){
+    
+    #if DEBUG
+    pc.printf(s);
+    #endif
+    
+    }
+
+void sendSPI(uint8_t d1, uint8_t d2)
+{
+    deviceM.unlock();
+    ssel=0;
+    deviceM.write(d1); 
+    deviceM.write(d2);  
+    ssel=1;
+    deviceM.lock();
+};
+ void imprimir(){
+    // Sele aplica corrmiento a las posiciones del vecteor para facilitar selecccion de la posicion. 
+  
+        for(int i=0;i<=12;i++)
+         {
+        for (int j= 1; j<=8; j++){
+            
+        sendSPI(j,matriz[j-1]>>i);           
+            }                 
+        wait(1.0);                        
+         }
+      
+    }
+ void mostrar(){
+     
+         pc.baud(38400);
+         char pos= 0;
+         char figura= 0;
+         char giro= 0;
+         debuging("\n Ingrese el posicion. ");
+         pos=pc.getc();
+         debuging("\n Seleccione la Figura. ");
+         figura=pc.getc();
+         debuging("\n Seleccione la rotacion. ");
+         giro=pc.getc();
+         
+         
+         switch(figura){
+             case 1:
+              // Cuadrado
+             switch(giro){
+             case 1: case 2: case 3: case 4:
+             matriz[pos]=  0b11000000000;
+             matriz[pos+1]=0b11000000000;
+             imprimir();
+             break;
+             }
+             break;
+             case 2:
+             //T
+             switch(giro){
+                 case 1:
+                 matriz[pos]=  0b10000000000;
+                 matriz[pos+1]=0b11000000000;
+                 matriz[pos+2]=0b10000000000;
+                 imprimir();
+                 break;
+                 case 2:
+                 matriz[pos]=  0b01000000000;
+                 matriz[pos+1]=0b11100000000;
+                 imprimir();
+                 break;
+                 case 3:
+                 matriz[pos]=  0b11100000000;
+                 matriz[pos+1]=0b01000000000;
+                 imprimir();
+                 break;
+                 case 4:
+                 matriz[pos]=  0b01000000000;
+                 matriz[pos+1]=0b11000000000;
+                 matriz[pos+2]=0b01000000000;
+                 imprimir();
+                 break;
+                 }
+        
+             break;
+             case 3:
+             //L
+             switch(giro){
+                 case 1:
+                 matriz[pos]=  0b11000000000;
+                 matriz[pos+1]=0b10000000000;
+                 matriz[pos+2]=0b10000000000;
+                 imprimir();
+                 break;
+                 case 2:
+                 matriz[pos]=  0b111000000000;
+                 matriz[pos+1]=0b001000000000;
+                 imprimir();
+                 break;
+                 case 3:
+                 matriz[pos]=  0b01000000000;
+                 matriz[pos+1]=0b01000000000;
+                 matriz[pos+2]=0b11000000000;
+                 imprimir();
+                 break;
+                 case 4:
+                 matriz[pos]=  0b10000000000;
+                 matriz[pos+1]=0b11100000000;
+                 imprimir();
+                 break;
+                 }
+             break;
+             case 4:
+             //Z
+             switch(giro){
+                 case 1: case 3:
+                 matriz[pos]=  0b01000000000;
+                 matriz[pos+1]=0b11000000000;
+                 matriz[pos+2]=0b10000000000;
+                 imprimir();
+                 break;
+                 case 2: case 4:
+                 matriz[pos]=  0b11000000000;
+                 matriz[pos+1]=0b01100000000;
+                 imprimir();
+                 break;
+    
+                 }
+             break;
+             case 5:
+             switch(giro){
+                 case 1: case 3:
+                 matriz[pos]=  0b10000000000;
+                 matriz[pos+1]=0b10000000000;
+                 matriz[pos+2]=0b10000000000;
+                 imprimir();
+                 break;
+                 case 2: case 4:
+                 matriz[pos]=  0b11100000000;
+                 imprimir();
+                 break;
+                 }
+             
+             break;
+             
+             
+             
+             
+             
+             }
+        matriz[0]=0;
+        matriz[1]=0;
+        matriz[2]=0;
+        matriz[3]=0;
+        matriz[4]=0;
+        matriz[5]=0;
+        matriz[6]=0;
+        matriz[7]=0;
+     
+     }
+void inicializar(){
+    
+    sendSPI(0x0c,1);
+    sendSPI(0x0b,7);
+    sendSPI(0x09,0);
+    sendSPI(0x0A,0x0f);
+    int i;
+    for (i=0;i<2;i++){
+        sendSPI(0x0F,1);
+        wait (0.5);
+        sendSPI(0x0f,0);
+        wait (0.5);
+    }
+    
+    }
+
+ 
+int main() {
+    inicializar();
+    while(1){
+            mostrar();
+            }
+        
+       
+        
+     
+}