cualquier cosa

Dependencies:   mbed

Fork of 00_LAB_matrix8x8_SPI by ferney alberto beltran molina

main.cpp

Committer:
oggonei
Date:
2018-09-03
Revision:
4:b38a9b0501dc
Parent:
3:4a8de2f71ed0
Child:
5:377b23953ba1

File content as of revision 4:b38a9b0501dc:

#include "mbed.h"

SPI deviceM(PB_5, PB_4, PB_3);
DigitalOut ssel (PB_9);

//#define  uint8_t unsigned char
//uint8_t vcol2[8]={0,0,0,0,0,0,0,0};

int enviarficha(int x,int y)
{
    int k=y;
    
    if(x==1) // cuadrado
        {
        return k; 
        }
    else if (x==2) //linea
        {
        return k;
        }
    else if (x==3) //ele
        {
        return k;
        }
    else if (x==4) //te
        {
        return k;
        }
    else if (x==5) //ese
        {
        return k;
        }         
    else
    return 1;
}
 
void sendSPI(uint8_t d1, uint8_t d2)
{
    deviceM.unlock();
    ssel=0;
    deviceM.write(d1);
    deviceM.write(d2);
    ssel=1;
    deviceM.lock();
};

void test()  //test
{
    sendSPI(0x0F,1);
    wait(0.5);
    sendSPI(0x0F,0);
    wait(0.5);    
};

void cuadro(int x)
{
    int j,r;

    if (x==1)
    r=0xC0;
    else if(x==2)
    r=0x60;
    else if(x==3)
    r=0x30;
    else if(x==4)
    r=0x18;
    else if(x==5)
    r=0xC;
    else if(x==6)
    r=0x06;
    else if(x==7)
    r=0x03;
    else if(x==8)
    r=0x01;
    {
         for(j=0;j<=7;j++)
             {
                sendSPI(0x0+j,r);
                sendSPI(0x0+(j+1),r);
                wait_ms(200);
                sendSPI(0x0+j,0x00);
                sendSPI(0x0+(j+1),0x00);
                wait_us(10); 
            } 
                sendSPI(0x07,r);
                sendSPI(0x08,r);  
    }                
};

void linea(int x)
{
    int j,r;

    if (x==1)
    r=0x80;
    else if(x==2)
    r=0x40;
    else if(x==3)
    r=0x20;
    else if(x==4)
    r=0x10;
    else if(x==5)
    r=0x08;
    else if(x==6)
    r=0x04;
    else if(x==7)
    r=0x02;
    else if(x==8)
    r=0x01;
    {
         for(j=0;j<=6;j++)
             {
                sendSPI(0x0+j,r);
                sendSPI(0x0+(j+1),r);
                sendSPI(0x0+(j+2),r);
                wait_ms(200);
                sendSPI(0x0+j,0x00);
                sendSPI(0x0+(j+1),0x00);
                sendSPI(0x0+(j+2),0x00);
                wait_us(10); 
            } 
                sendSPI(0x06,r);
                sendSPI(0x07,r);
                sendSPI(0x08,r);  
    }                
};

void ele(int x)
{
    int j,r,r2;
    if (x==1)
    {
    r=0xC0;
    r2=0x80;
    }
    else if(x==2)
    {
    r=0x60;
    r2=0x40;
    }
    else if(x==3)
    {
    r=0x30;
    r2=0x20;
    }
    else if(x==4)
    {
    r=0x18;
    r2=0x10;
    }
    else if(x==5)
    {
    r=0xC;
    r2=0x08;
    }
    else if(x==6)
    {
    r=0x06;
    r2=0x04;
    }
    else if(x==7)
    {
    r=0x03;
    r2=0x02;
    }
    else if(x==8)
    {
    r=0x01;
    r2=0x01;
    }
    {
         for(j=0;j<=6;j++)
             {
                sendSPI(0x0+j,r2);
                sendSPI(0x0+(j+1),r2);
                sendSPI(0x0+(j+2),r);
                wait_ms(200);
                sendSPI(0x0+j,0x00);
                sendSPI(0x0+(j+1),0x00);
                sendSPI(0x0+(j+2),0x00);
                wait_us(10); 
            } 
                sendSPI(0x06,r2);
                sendSPI(0x07,r2);
                sendSPI(0x08,r);  
    }                
};

void te(int x)
{
    int j,r,r2;

    if (x==1)
    {
    r=0xE0;
    r2=0x40;
    }
    else if(x==2)
    {
    r=0x70;
    r2=0x20;
    }
    else if(x==3)
    {
    r=0x38;
    r2=0x10;
    }
    else if(x==4)
    {
    r=0x1C;
    r2=0x8;
    }
    else if(x==5)
    {
    r=0xE;
    r2=0x4;
    }
    else if(x==6)
    {
    r=0x7;
    r2=0x2;
    }
    else if(x==7)
    {
    r=0x03;
    r2=0x1;
    }
    else if(x==8)
    r=0x01;
    {
         for(j=0;j<=7;j++)
             {
                sendSPI(0x0+j,r2);
                sendSPI(0x0+(j+1),r);
                wait_ms(200);
                sendSPI(0x0+j,0x00);
                sendSPI(0x0+(j+1),0x00);
                wait_us(10); 
            } 
                sendSPI(0x07,r2);
                sendSPI(0x08,r);  
    }                
};

void ese(int x)
{
    int j,r,r2;

    if (x==1)
    {
    r=0xC0;
    r2=0x60;
    }
    else if(x==2)
    {
    r=0x60;
    r2=0x30;
    }
    else if(x==3)
    {
    r=0x30;
    r2=0x18;
    }
    else if(x==4)
    {
    r=0x18;
    r2=0xC;
    }
    else if(x==5)
    {
    r=0xC;
    r2=0x6;
    }
    else if(x==6)
    {
    r=0x6;
    r2=0x3;
    }
    else if(x==7)
    {
    r=0x03;
    r2=0x1;
    }
    else if(x==8)
    r=0x01;
    {
         for(j=0;j<=7;j++)
             {
                sendSPI(0x0+j,r2);
                sendSPI(0x0+(j+1),r);
                wait_ms(200);
                sendSPI(0x0+j,0x00);
                sendSPI(0x0+(j+1),0x00);
                wait_us(10); 
            } 
                sendSPI(0x07,r2);
                sendSPI(0x08,r);  
    }                
};

void borrar()
{
    int i;
    for(i=0;i<=8;i++)
    {
        sendSPI(0x0+i,0x00);
    }
};


int main() {
    sendSPI(0x09,0);        //no decodificacion
    sendSPI(0x0A,0x0);     //intensidad
    sendSPI(0x0B,0x07);     //usa 7 leds                     
    sendSPI(0x0C,1);        //no apaga
    sendSPI(0x0F,0);        //operacion normal  
 
    int x=5,y=6;  // enviar ficha y columna
    
    if (x==1)  //cuadro
    {
    borrar();
    int r=enviarficha(x,y);
    cuadro(r);
    }
    else if (x==2)  //linea
    {
    borrar();    
    int r=enviarficha(x,y);
    linea(r);
    }
    else if (x==3)  //l
    {
    borrar();    
    int r=enviarficha(x,y);
    ele(r);
    }
    else if(x==4)  //t
    {
    borrar();    
    int r=enviarficha(x,y);
    te(r);
    }
    else if(x==5)  //s
    {
    borrar();    
    int r=enviarficha(x,y);
    ese(r);
    }
}