Yosef Guevara Salamanca
/
TETS_PC
bien spi no se queda pegado
tets_pc.cpp
- Committer:
- djinn77
- Date:
- 2018-09-12
- Revision:
- 6:c80ec2cdfb9e
- Parent:
- 5:106def451c41
- Child:
- 7:5677ded8ff2a
File content as of revision 6:c80ec2cdfb9e:
#include "mbed.h" #include "piezas.h" //#define DEBUG 1 Serial pc(USBTX,USBRX); SPI deviceM(PB_15, PB_14, PB_13); DigitalOut ssel (PB_12); int memoria[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 captura_matriz(uint16_t* imprimir){ int i=0; while(i <8){ int j=0; while(j<=8){ sendSPI(j, memoria[j-1]|(imprimir[j-1]>>i)); if(i==7){ memoria[j-1]= memoria[j-1]|(imprimir[j-1]>>i); } j++; } wait(1.0); i++; } } void desplazar(uint16_t* datos, char des){ uint16_t desplazamiento[8]={0}; int j= 0; for(int i=des; i<(des+3);i++){ desplazamiento[i]=datos[j]; j++; } captura_matriz(desplazamiento); } void read(){ 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 0: // L switch(giro){ case 0: desplazar(PZA_LD,pos); break; case 1: desplazar(PZA_LDN,pos); break; case 2: desplazar(PZA_LDO,pos); break; case 3: desplazar(PZA_LDD, pos); break; } break; case 1://T switch(giro){ case 0: desplazar(PZA_T, pos); break; case 1: desplazar(PZA_TN, pos); break; case 2: desplazar(PZA_TO, pos); break; case 3: desplazar(PZA_TD, pos); break; } break; case 2://I switch(giro){ case 0: case 2: desplazar(PZA_I, pos); break; case 1: case 3: desplazar(PZA_IR, pos); break; } break; case 3://Cuadrado switch(giro){ case 1: case 2: case 3: case 4: desplazar(PZA_C,pos); break; } break; case 5: //Z switch(giro){ case 0: desplazar(PZA_Z,pos); break; case 1: desplazar(PZA_ZN,pos); break; case 2: desplazar(PZA_ZO,pos); break; case 3: desplazar(PZA_ZD, pos); break; } break; } } 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); } for (int j= 1; j<=8;j++){ // limpia la pantalla al encenderce o reiniarcea asi //no quedan leds encendidos cuando se ejecute el programa nuevamente sendSPI(j, 0x00); } } int main() { inicializar(); while(1){ read(); } }