Tareita

Dependencies:   TextLCD mbed

Fork of UART0 by Huy Hoang Nguyen

Files at this revision

API Documentation at this revision

Comitter:
a00958821
Date:
Wed Nov 16 18:04:03 2016 +0000
Parent:
1:9f10be874ce0
Commit message:
Lab 8 Efrain

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Wed Nov 09 18:43:15 2016 +0000
+++ b/main.cpp	Wed Nov 16 18:04:03 2016 +0000
@@ -12,20 +12,18 @@
 DigitalIn fila3 (A3);
 DigitalIn fila4 (A2);
  
-RawSerial Uart1(A0, A1);  // tx, rx
-RawSerial Uart2(PC_10, PC_11);  // tx, rx
-
-
+RawSerial Uart1(A0, A1);  // tx, rx Define los pines de la Uart a usar
  
-char Simbolos[4][4] = {
+char Simbolos[4][4] = {             //Matriz de caracteres del teclado
                      {'1','2','3','A'},
                      {'4','5','6','B'},
                      {'7','8','9','C'},
                      {'*','0','#','D'}
                      };   
 
-volatile char Data[2];
-              
+volatile char Data[11];
+volatile char Data2[11];     
+             
 int usrInput();
 void turnOffteclado();
 int * teclado();
@@ -34,54 +32,65 @@
 void Uart2Rx_interrupt();
  
 int main() {
+    
+    int * Index;            //Da la ubicacion en la matriz de caracteres
+    while (Simbolos[Index[0]][Index[1]] != '*')     //Espera a que el usuario ingrese * para comenzar
+    {
+        Index = teclado();
+    }
+    wait(.5);   
+    
+    Data2[0] = '\0'; //Vacia el primer espacio del arreglo
+        
     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();
+    Uart1.baud(9600);    //define baudrate
     
-    
-    if (Simbolos[Index[0]][Index[1]] != '#')
+    Uart1.attach(Uart1Rx_interrupt,Serial::RxIrq); //Indica que hay un interrup para la Uart
+                                                    //Se activa cuando hay un dato en el pin Rx (receptor)
+   
+    while(1)
+    {
+        int i = 0;
+        
+    do  //Imprime en pantalla lo teclado (hasta 10 caracteres) y lo envia si se recibe un #
     {
-        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'){
+        Index = teclado(); //Recibe el indice del caracter ingresado por el usuario
+        if(i < 10 and Simbolos[Index[0]][Index[1]] != '#') //Si no se teclea un # 
+        {
+            if(i == 0){ //Si es el primer caracter (i = 0) se limpia el primer renglon de la pantalla
+                lcd.locate(0,0);
+        lcd.printf("                ");
+        lcd.locate(0,0);
+        }
+            Data[i] = Simbolos[Index[0]][Index[1]]; //Guarda el valor ingresado por el usuario caracter por caracter
+            lcd.printf("%c",Data[i]);   //Imprime el caracter ingresado
+            wait(.15);
+            i = i+1;    //Se mueve a la siguiente posicion de la matriz de datos
+        }
+
+    }while(Simbolos[Index[0]][Index[1]] != '#'); //Condicion para que se acabe el Do - while, si se ingresa un #
+                            //Ya que sale del Do - While, la matriz Data tiene todos los caracteres ingresados por el usuario
+    lcd.locate(0,1);            //Limpia el segundo renglon
+    lcd.printf("                ");
+    lcd.locate(0,1);
+    for(int x = 0; x < i ; x += 1) //Envia dato por dato de la matriz Data al pin Tx de la Uart.
+    {
+    Uart1.putc(Data[x]);  //Putc envia el caracter de la matriz Data en posicion x
+    wait(.025);             //esperamos un poco para asegurar que llegue el dato
+    } 
     
-    while(Uart1.writeable() != 1){}
-    Uart1.putc(Data[0]);
+    wait(.5);
         
-    while (Uart1.readable() != 1){}
-    lcd.locate(0,1);
+    }
     
-    Data[1] = Uart1.getc();
-    lcd.printf("%c",Data[1]);
-    }
-    }*/
 }
 
-void Uart1Rx_interrupt()
+void Uart1Rx_interrupt()    //Este interrup se llama si llega algo al pin Rx de la Uart
 {
-    
+    lcd.printf("%c",Uart1.getc());  //Imprime en pantalla el caracter que actualmente hay en el pin Rx de la Uart
+    return;
 }
-void Uart2Rx_interrupt()
-{
-    
-}
+ 
 
 int * teclado() 
 {