Tareita

Dependencies:   TextLCD mbed

Fork of UART0 by Huy Hoang Nguyen

main.cpp

Committer:
a00958821
Date:
2016-11-09
Revision:
1:9f10be874ce0
Parent:
0:9e15cfed60ea
Child:
2:c3d5b9e7a5dd

File content as of revision 1:9f10be874ce0:

#include "mbed.h"
#include "TextLCD.h"

TextLCD lcd(D2, D3, D4, D5, D6, D7); // rs, e, d4-d7

DigitalOut col1 (D8);
DigitalOut col2 (D9);
DigitalOut col3 (D10);
DigitalOut col4 (D11);
DigitalIn fila1 (A5);
DigitalIn fila2 (A4);
DigitalIn fila3 (A3);
DigitalIn fila4 (A2);
 
RawSerial Uart1(A0, A1);  // tx, rx
RawSerial Uart2(PC_10, PC_11);  // tx, rx


 
char Simbolos[4][4] = {
                     {'1','2','3','A'},
                     {'4','5','6','B'},
                     {'7','8','9','C'},
                     {'*','0','#','D'}
                     };   

volatile char Data[2];
              
int usrInput();
void turnOffteclado();
int * teclado();

void Uart1Rx_interrupt();
void Uart2Rx_interrupt();
 
int main() {
    lcd.cls();
    Uart1.baud(9600);    
    Uart2.baud(9600);
    //lcd.printf("%d",Uart1.writeable());
    //lcd.printf("%d",Uart1.readable());
    while (Uart1.writeable() != 1){}
    //Uart1.putc('b');
    Uart1.printf("hola amigos");
    while(Uart2.readable() != 1){}
    Data[0] = Uart2.getc();
    lcd.printf("%c",Data[0]);
    
    /*Data[0] = 'n';
 
    while(1)
    {        
    int * Index; 
    Index = teclado();
    
    
    if (Simbolos[Index[0]][Index[1]] != '#')
    {
        Data[0] = Simbolos[Index[0]][Index[1]];
        lcd.cls();
        lcd.printf("%c",Data[0]);
    }
    else if(Simbolos[Index[0]][Index[1]] == '#' and Data[0] != 'n'){
    
    while(Uart1.writeable() != 1){}
    Uart1.putc(Data[0]);
        
    while (Uart1.readable() != 1){}
    lcd.locate(0,1);
    
    Data[1] = Uart1.getc();
    lcd.printf("%c",Data[1]);
    }
    }*/
}

void Uart1Rx_interrupt()
{
    
}
void Uart2Rx_interrupt()
{
    
}

int * teclado() 
{
    static int r[2];
    turnOffteclado();
    int numero;
  while(1) 
  {           
    col1 = 1;
    numero = usrInput();
    if (numero != 0)
    {
    r[0]=numero-1;
    r[1]=0;
    wait_ms(50);
    return r;
    }
    turnOffteclado();
    col2 = 1;
    numero = usrInput();
    if (numero != 0)
    {
    r[0]=numero-1;
    r[1]=1;
    wait_ms(50);
    return r;
    }
    turnOffteclado();
    col3 = 1;
    numero = usrInput();
    if (numero != 0)
    {
     r[0]=numero-1;
     r[1]=2;
     wait_ms(50);
     return r;
    }
    turnOffteclado();
    col4 = 1;
    numero = usrInput();
    if (numero != 0)
    {
     r[0]=numero-1;
     r[1]=3;
     wait_ms(50);
     return r;
    }
    turnOffteclado();
    
  }
}

void turnOffteclado()
{
    col1 = col2 = col3 = col4 = 0;
}
 
int usrInput()
{
    if (fila1 == 1)
    {
        return 1;
    }
    else if (fila2 == 1)
    {
        return 2;
    }
    else if (fila3 == 1)
    {
        return 3;
    }
    else if (fila4 == 1)
    {
        return 4;
    }  
    else{
    return 0;  
    }
}