Alarmas con reloj DS3231, configuración con encoder y control infrarrojo

Dependencies:   mbed QEI DebouncedIn ds3231 TextLCD Pulse1

Files at this revision

API Documentation at this revision

Comitter:
Cam53
Date:
Fri Aug 16 18:30:43 2019 +0000
Commit message:
Alarmas con reloj DS3231

Changed in this revision

DebouncedIn.lib Show annotated file Show diff for this revision Revisions of this file
Pulse1.lib Show annotated file Show diff for this revision Revisions of this file
QEI.lib Show annotated file Show diff for this revision Revisions of this file
TextLCD.lib Show annotated file Show diff for this revision Revisions of this file
ds3231.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 1b7bc758e004 DebouncedIn.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/DebouncedIn.lib	Fri Aug 16 18:30:43 2019 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/cmorab/code/DebouncedIn/#dc1131de43e8
diff -r 000000000000 -r 1b7bc758e004 Pulse1.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Pulse1.lib	Fri Aug 16 18:30:43 2019 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/tony63/code/Pulse1/#48651f86a80c
diff -r 000000000000 -r 1b7bc758e004 QEI.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/QEI.lib	Fri Aug 16 18:30:43 2019 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/aberk/code/QEI/#5c2ad81551aa
diff -r 000000000000 -r 1b7bc758e004 TextLCD.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TextLCD.lib	Fri Aug 16 18:30:43 2019 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/simon/code/TextLCD/#308d188a2d3a
diff -r 000000000000 -r 1b7bc758e004 ds3231.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ds3231.lib	Fri Aug 16 18:30:43 2019 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/teams/Maxim-Integrated/code/ds3231/#11630748e2f2
diff -r 000000000000 -r 1b7bc758e004 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Fri Aug 16 18:30:43 2019 +0000
@@ -0,0 +1,1101 @@
+#include "mbed.h"
+#include "QEI.h"
+#include "TextLCD.h"
+#include "DebouncedIn.h"
+#include "string.h"
+#include "ds3231.h"
+#include <Pulse1.h>
+
+#define ESC 0x1B
+
+
+//Use X4 encoding.
+//QEI wheel(p29, p30, NC, 624, QEI::X4_ENCODING);
+//Use X2 encoding by default.
+PulseInOut irda(PTD5);// en este puerto se pone el sensor infrarrojo
+Serial pc(USBTX, USBRX);
+QEI wheel (PTD7, PTD6, NC, 624);//Encoder
+DebouncedIn bot1(PTA13);//Botón encoder
+DebouncedIn boton(PTA17);//Botón
+TextLCD lcd(PTB10, PTB11, PTE2, PTE3, PTE4, PTE5, TextLCD::LCD16x2); // rs, e, d4-d7
+DigitalOut led1(PTC7);//Salidas
+DigitalOut led2(PTC0);
+DigitalOut led3(PTC3);
+DigitalOut led(LED3);
+DigitalOut ledd2(LED1);
+
+//-----------parametros IRDA -------
+int header =0; //tiempo de cabecera pulso abajo
+const int head_H = 4900; //+10% medida con osciloscopio en microsegundos
+const int head_L = 3500 ;//-10%  medida con osciloscopio
+int il=0, x=0;
+const int T_alto=1694;//ponga su tiempo de la prueba
+const int T_bajo=632;//ponga su tiempo de la prueba
+const int num_bits = 32;//ponga su numero de bits
+int num[num_bits];//cadena para almacenar todos los tiempos que conforman los bits de datos
+char sel[num_bits];//cadena para almacenar la cadena codificada en binario
+char uno[]="1110000011100000001000001101111";
+char dos[]="1110000011100000101000000101111";
+char tres[]="1110000011100000011000001001111";
+char cuatro[]="1110000011100000000100001110111";
+char cinco[]="1110000011100000100100000110111";
+char seis[]="1110000011100000010100001010111";
+char siete[]="1110000011100000001100001100111";
+char ocho[]="1110000011100000101100000100111";
+char nueve[]="1110000011100000011100001000111";
+char cero[]="1110000011100000100010000111011";
+char ok[]="1110000011100000000101101110100";
+char izq[]="1110000011100000101001100101100";
+char der[]="1110000011100000010001101011100";
+int dato; // tiempo de cada dato que se lee
+int irdan(void);
+int y=0;
+int detectar(void);//funcion detecta irda
+int Alarm_IRDA(void);//funcion valor irda
+
+void get_user_input(char* message, uint8_t min, uint8_t max, uint32_t* member);
+void get_user_input(char* message, uint8_t min, uint8_t max, bool* member);
+
+int mode=0;
+int numb=34;
+
+//
+  
+int d;
+int m;
+int mes;
+int an,h,min,sec,a; 
+int Conf=0;
+int s=0;  // 0: si y 1:no alarma ok
+int f=0; // 0: si y 1:no otra alrama
+int Lugar=1,Lugar2=2;
+int pos=0,n=0; // Definen el punto en el cual va el programa
+int i=0;
+int j=1;      //Cuenta las alarmas
+int Select=1;   //Alarma Seleccionada
+int StarReadIR=0;
+int visual=0;  //0: Reloj y 1:Alarm
+int alarma=0;  //0: Desactivar y 1:Posponer
+int Vec1[7];
+int Vec2[7];
+int Vec3[7];
+int Vec4[7];
+int Vec5[7];
+int Vec6[7];
+
+
+
+int main()
+{
+
+    Ds3231 rtc(PTE0, PTE1); 
+    time_t epoch_time;
+    ds3231_cntl_stat_t rtc_control_status = {0,0}; 
+    ds3231_time_t rtc_time={0,0,0,0,0};
+    ds3231_calendar_t rtc_calendar={0,0,0,0};
+    rtc.set_cntl_stat_reg(rtc_control_status);
+    
+    
+    
+loop1: 
+    epoch_time = rtc.get_epoch();
+    rtc.get_time(&rtc_time);
+    rtc.get_calendar(&rtc_calendar);
+    j=1;
+    Conf=0;
+    s=0;
+    f=0;
+    Lugar=1;
+    Lugar2=2;
+    pos=0;
+    i=0;
+    y=0;
+    lcd.cls();
+    lcd.locate(14,0);
+    lcd.printf("-A");
+    lcd.locate(2,0);
+    lcd.printf("\nFecha:%02d/%02d/%02d",rtc_calendar.date,rtc_calendar.month,rtc_calendar.year);
+    m=wheel.getPulses();
+ //Reloj corriendo y comparamdo con alarmas//       
+     while(!bot1.falling() && !boton.falling()){
+            rtc.get_time(&rtc_time);
+            lcd.locate(0,1);
+            lcd.printf("\nHora:%02d:%02d:%02d", rtc_time.hours,rtc_time.minutes,rtc_time.seconds );
+            if(Vec1[1]==rtc_calendar.date && Vec1[2]==rtc_calendar.month && Vec1[3]==rtc_calendar.year && Vec1[4]==rtc_time.hours && Vec1[5]==rtc_time.minutes && Vec1[6]==rtc_time.seconds){
+                    led1=1;}
+            if(Vec2[1]==rtc_calendar.date && Vec2[2]==rtc_calendar.month && Vec2[3]==rtc_calendar.year && Vec2[4]==rtc_time.hours && Vec2[5]==rtc_time.minutes && Vec2[6]==rtc_time.seconds){
+                    led2=1;}
+            if(Vec3[1]==rtc_calendar.date && Vec3[2]==rtc_calendar.month && Vec3[3]==rtc_calendar.year && Vec3[4]==rtc_time.hours && Vec3[5]==rtc_time.minutes && Vec3[6]==rtc_time.seconds){
+                    led3=1;}
+            if(Vec4[1]==rtc_calendar.date && Vec4[2]==rtc_calendar.month && Vec4[3]==rtc_calendar.year && Vec4[4]==rtc_time.hours && Vec4[5]==rtc_time.minutes && Vec4[6]==rtc_time.seconds){
+                    led1=0;}
+            if(Vec5[1]==rtc_calendar.date && Vec5[2]==rtc_calendar.month && Vec5[3]==rtc_calendar.year && Vec5[4]==rtc_time.hours && Vec5[5]==rtc_time.minutes && Vec5[6]==rtc_time.seconds){
+                    led2=0;}
+            if(Vec6[1]==rtc_calendar.date && Vec6[2]==rtc_calendar.month && Vec6[3]==rtc_calendar.year && Vec6[4]==rtc_time.hours && Vec6[5]==rtc_time.minutes && Vec6[6]==rtc_time.seconds){
+                    led3=0;}  
+            }
+                
+    while(1) 
+            {
+            
+            if (bot1.falling()){ //Para que trabaje con encoder
+                Lugar++;
+                }
+            if(boton.falling()){
+                Lugar2++;
+                }
+
+            switch (Lugar)//Encoder
+               {
+               case 2:
+               switch(i)
+                  {
+                   case 0:
+                   if(Conf==0){
+                    lcd.cls();   
+                    lcd.locate(0,0);
+                    lcd.printf("Alarma: ");
+                    i++;
+                    }
+                   break;
+                   case 1:
+                   m=0;
+                   m=wheel.getPulses();
+                   if (m!=0){
+                    a=m;
+                    if(a>8){
+                        a=8;
+                        }
+                    if (a<1){
+                        a=1;
+                        }
+                    }
+                   lcd.locate(10,0);
+                   lcd.printf("%02d   ",a);
+                   if(bot1.falling()){
+loop2:
+                    lcd.cls();
+                    lcd.printf("Config. Alarmas ");
+                    wait(1);
+                    lcd.cls();
+                    i=2;
+                    s=0;
+                    f=0;
+                    Lugar=2;
+                    pos=0;
+                    lcd.locate(0,0);
+                    lcd.printf("Dia: ");
+                    m=0;
+                    wheel.reset();
+                    }
+                    break;
+                    case 2: // Dia
+                    m=0;
+                    m=wheel.getPulses();        
+                    if (m!=0) 
+                        {
+                        d=m;
+                        if(d>31)
+                            {
+                            d=31;
+                            }
+                        if(d<1)
+                            {
+                            d=1;
+                            }
+                            
+                            
+                        }
+                        lcd.locate(5,0);
+                        lcd.printf("%02d   ",d);
+                        
+                        if (bot1.falling())
+                        {
+                            i++;
+                            m=0;
+                            lcd.cls();
+                            lcd.locate(0,0);
+                            lcd.printf("Mes: ");
+                                              
+                            wheel.reset();
+                    
+                        }
+                    break;
+                    
+                    case 3: // Mes
+                        m=0;
+                        m=wheel.getPulses();        
+                        if (m!=0) 
+                        {
+                            mes=m;
+                            if(mes>12)
+                            {
+                                mes=12;
+                            }
+                            if(mes<1)
+                            {
+                                mes=1;
+                            }
+                            
+                            
+                        }
+                        lcd.locate(7,0);
+                        lcd.printf("%02d",mes);
+                        
+                        if (bot1.falling())
+                        {
+                            i++;
+                            m=0;
+                            lcd.cls();
+                            lcd.locate(0,0);
+                            lcd.printf("Anno: ");
+                            wheel.reset();
+                        }
+                    
+                    break;
+                    
+                    case 4: //Año
+                        m=wheel.getPulses();        
+                        if (m!=0) 
+                        {
+                            an=m;
+                            
+                            if(an<0)
+                            {
+                                an=0;
+                            }
+                            if(an>99){
+                                an=99;
+                                }
+                              
+                            
+                        }
+                        lcd.locate(6,0);
+                        lcd.printf("%02d",an);
+                        
+                        if (bot1.falling())
+                        {
+                            i++;
+                            m=0;
+                            lcd.cls();
+                            lcd.locate(0,0);
+                        lcd.printf("Config. Hora");
+                        wait(1);
+                        lcd.cls();
+                        lcd.printf("Hora: ");
+                        wheel.reset();
+                                                    
+                        }
+                    
+                    break;
+                    
+                    case 5: //HORA
+                    
+
+                        m=0;
+                        m=wheel.getPulses();       
+                        if (m!=0) 
+                        {
+                            h= m;
+                            if(h>23)
+                            {
+                                h=23;
+                            }
+                            if(h<0)
+                            {
+                                h=0;
+                            }  
+                            
+                        }
+                        lcd.locate(6,0);
+                        lcd.printf("%02d",h);
+                        
+                        if (bot1.falling())
+                        {
+                            i++;
+                            m=0;
+                            lcd.cls();
+                            lcd.locate(0,0);
+                            lcd.printf("Minuto: ");
+                            wheel.reset();
+                        }
+                    
+                    break;
+                    
+                    case 6: //MINUTOS
+                        m=0;
+                        m=wheel.getPulses();        
+                        if (m!=0) 
+                        {
+                            min=m;
+                            if(min>59)
+                            {
+                                min=59;
+                            }
+                            if(min<0)
+                            {
+                                min=0;
+                            }  
+                            
+                        }
+                        lcd.locate(8,0);
+                        lcd.printf("%02d",min);
+                        
+                        if (bot1.falling())
+                        {
+                            i++;
+                            
+                            lcd.cls();
+                            lcd.locate(0,0);
+                            lcd.printf("Segundo: ");
+                            wheel.reset();
+                        }
+                    
+                    break;
+                    
+                    
+                    case 7: //SEGUNDOS
+                    m=0;
+                        m=wheel.getPulses();        
+                        if (m!=0) 
+                        {
+                            sec=m;
+                            if(sec>59)
+                            {
+                                sec=59;
+                            }
+                            if(sec<0)
+                            {
+                                sec=0;
+                            }
+
+                        }
+                        
+                        lcd.locate(8,0);
+                        lcd.printf("%02d",sec);
+                        if(bot1.falling()){
+                            
+                            i++;
+                            
+                            lcd.cls();
+                            wheel.reset();
+                    
+                        }
+                    break;
+                    case 8:
+                        m=0;
+                        lcd.locate(0,1);
+                        lcd.printf("\nAlarm:%02d:%02d:%02d",h,min,sec);
+                        lcd.locate(2,0);
+                        lcd.printf("\nFecha:%02d/%02d/%02d",d,mes,an);
+                        wait(2);
+                        lcd.cls();
+                        lcd.locate(0,1);
+                        lcd.printf("Alarma OK ?");
+                        lcd.locate(2,0);
+                        lcd.printf("--Si      --No");
+                        i++;
+                        wheel.reset();
+                break;
+        
+            case 9:
+                
+                m=wheel.getPulses();  // m son los datos del encoder
+                if(m!=0 && s==0){
+                    s=1;
+                    wheel.reset();  
+                    m=0;              
+                }
+                
+                if(m!=0 && s==1){
+                    s=0;
+                    wheel.reset();  
+                    m=0;              
+                }
+                
+                if(s==0){
+                    
+                    lcd.locate(11,0);
+                    lcd.printf("-");                    
+                    lcd.locate(1,0);
+                    lcd.printf(">");
+                    lcd.locate(0,1);                    
+                    wait(0.1);
+                }
+                 if(s==1){
+                    
+                    lcd.locate(1,0);
+                    lcd.printf("-");                    
+                    lcd.locate(11,0);
+                    lcd.printf(">");
+                    lcd.locate(0,1);                    
+                    wait(0.1);
+                    }
+                
+                 if(s==1){
+                    
+                    lcd.locate(1,0);
+                    lcd.printf("-");                    
+                    lcd.locate(11,0);
+                    lcd.printf(">");
+                    lcd.locate(0,1);                    
+                    wait(0.1);
+                }
+                
+                if (bot1.falling()){  //si se pulsa boton encoder
+                    pos++;
+                    m=0;       
+                }
+            
+            break;
+            
+                       
+                     
+                }
+                switch (pos)
+                {
+                    case 1:
+                        if(s==0){
+                            lcd.cls();
+                        lcd.locate(0,1);
+                        if(a==1){
+                        Vec1[1]=d;
+                        Vec1[2]=mes;
+                        Vec1[3]=an;
+                        Vec1[4]=h;
+                        Vec1[5]=min;
+                        Vec1[6]=sec;
+                            }
+                        if(a==2){
+                        Vec2[1]=d;
+                        Vec2[2]=mes;
+                        Vec2[3]=an;
+                        Vec2[4]=h;
+                        Vec2[5]=min;
+                        Vec2[6]=sec;
+                            }
+                        if(a==3){
+                        Vec3[1]=d;
+                        Vec3[2]=mes;
+                        Vec3[3]=an;
+                        Vec3[4]=h;
+                        Vec3[5]=min;
+                        Vec3[6]=sec;
+                            }
+                        if(a==4){
+                        Vec4[1]=d;
+                        Vec4[2]=mes;
+                        Vec4[3]=an;
+                        Vec4[4]=h;
+                        Vec4[5]=min;
+                        Vec4[6]=sec;
+                            }
+                        if(a==5){
+                        Vec5[1]=d;
+                        Vec5[2]=mes;
+                        Vec5[3]=an;
+                        Vec5[4]=h;
+                        Vec5[5]=min;
+                        Vec5[6]=sec;
+                            }
+                        if(a==6){
+                        Vec6[1]=d;
+                        Vec6[2]=mes;
+                        Vec6[3]=an;
+                        Vec6[4]=h;
+                        Vec6[5]=min;
+                        Vec6[6]=sec;
+                            }
+                        lcd.printf("Otra alarma? %0.2d",Vec1[6]);
+                        lcd.locate(2,0);
+                        lcd.printf("--Si      --No");
+                        wheel.reset();
+                        pos++;
+                        }
+                        
+                        if(s==1){
+                            lcd.cls();
+                            goto loop2;
+                            }
+                            
+                            break;
+                    case 2:
+                        m=wheel.getPulses();  // m son los datos del encoder
+                if(m!=0 && f==0){
+                    f=1;
+                    wheel.reset();  
+                    m=0;              
+                }
+                
+                if(m!=0 && f==1){
+                    f=0;
+                    wheel.reset();  
+                    m=0;              
+                }
+                
+                if(f==0){
+                    
+                    lcd.locate(11,0);
+                    lcd.printf("-");                    
+                    lcd.locate(1,0);
+                    lcd.printf(">");
+                    lcd.locate(0,1);                    
+                    wait(0.1);
+                }
+                 if(f==1){
+                    
+                    lcd.locate(1,0);
+                    lcd.printf("-");                    
+                    lcd.locate(11,0);
+                    lcd.printf(">");
+                    lcd.locate(0,1);                    
+                    wait(0.1);
+                    }
+                
+                 if(f==1){
+                    
+                    lcd.locate(1,0);
+                    lcd.printf("-");                    
+                    lcd.locate(11,0);
+                    lcd.printf(">");
+                    lcd.locate(0,1);                    
+                    wait(0.1);
+                }
+                
+                if (bot1.falling()){  //si se pulsa boton encoder
+                   wheel.reset();
+                    lcd.cls(); 
+                    pos++;
+                    
+                
+                          
+                }
+                break;
+                    case 3:
+                    if(f==0){
+                        wheel.reset();
+                        lcd.cls();
+                        goto loop1;
+                        }
+                    if(f==1){
+                        wheel.reset();
+                        lcd.cls();
+                        goto loop1; //Va al reloj
+                        }
+                    break;
+                    
+                    }
+               
+        }
+        
+          switch (Lugar2)//Control
+                {
+                case 3:
+            
+               switch(i)
+                  {
+                   
+                   case 0: 
+                   if(Conf==0){
+loop3:
+                    lcd.cls();   
+                    lcd.locate(0,0);
+                    lcd.printf("Alarma: ");
+                    i++;
+                    Conf++;
+                    m=0;
+                    }
+                   
+                   case 1:
+                   if (Conf==1){
+                   
+                   m=Alarm_IRDA();
+                   if(m!=0){
+                   a=m;
+                   if(a>8){
+                        a=8;
+                        }
+                    if (a<1){
+                        a=1;
+                        }
+                   }
+                   lcd.locate(10,0);
+                   pc.printf("Alarma: %02d",a);
+                   lcd.printf("%02d",a);
+                   
+loop5:
+                    if(Alarm_IRDA()==-8){
+                    lcd.cls();
+                    lcd.printf("Config. Alarmas ");
+                    wait(1);
+                    lcd.cls();
+                    i=2;
+                    s=0;
+                    f=0;
+                    Lugar=2;
+                    pos=0;
+                    lcd.locate(0,0);
+                    lcd.printf("Dia: ");
+                    m=0;
+                    }
+                    }
+                    
+                    case 2: // Dia
+                    m=0;
+                    m=Alarm_IRDA();        
+                    if (m!=0) 
+                        {
+                        d=m;
+                        if(d>31)
+                            {
+                            d=31;
+                            }
+                        if(d<1)
+                            {
+                            d=1;
+                            }
+                            
+                            
+                        }
+                        lcd.locate(5,0);
+                        lcd.printf("%02d   ",d);
+                        
+                        if (Alarm_IRDA()==-8)
+                        {
+                            i++;
+                            m=0;
+                            lcd.cls();
+                            lcd.locate(0,0);
+                            lcd.printf("Mes: ");
+                                              
+                            
+                    
+                        }
+                    
+                    
+                    case 3: // Mes
+                        m=0;
+                        m=Alarm_IRDA();        
+                        if (m!=0) 
+                        {
+                            mes=m;
+                            if(mes>12)
+                            {
+                                mes=12;
+                            }
+                            if(mes<1)
+                            {
+                                mes=1;
+                            }
+                            
+                            
+                        }
+                        lcd.locate(7,0);
+                        lcd.printf("%02d",mes);
+                        
+                        if (Alarm_IRDA()==-8)
+                        {
+                            i++;
+                            m=0;
+                            lcd.cls();
+                            lcd.locate(0,0);
+                            lcd.printf("Anno: ");
+                            
+                        }
+                    
+                    
+                    
+                    case 4: //Año
+                        m=Alarm_IRDA();        
+                        if (m!=0) 
+                        {
+                            an=m;
+                            
+                            if(an<0)
+                            {
+                                an=0;
+                            }
+                            if(an>99){
+                                an=99;
+                                }
+                              
+                            
+                        }
+                        lcd.locate(6,0);
+                        lcd.printf("%02d",an);
+                        
+                        if (Alarm_IRDA()==-8)
+                        {
+                            i++;
+                            m=0;
+                            lcd.cls();
+                            lcd.locate(0,0);
+                        lcd.printf("Config. Hora");
+                        wait(1);
+                        lcd.cls();
+                        lcd.printf("Hora: ");
+                        
+                                                    
+                        }
+                    
+                    
+                    
+                    case 5: //HORA
+                    
+
+                        m=0;
+                        m=Alarm_IRDA();       
+                        if (m!=0) 
+                        {
+                            h= m;
+                            if(h>23)
+                            {
+                                h=23;
+                            }
+                            if(h<0)
+                            {
+                                h=0;
+                            }  
+                            
+                        }
+                        lcd.locate(6,0);
+                        lcd.printf("%02d",h);
+                        
+                        if (Alarm_IRDA()==-8)
+                        {
+                            i++;
+                            m=0;
+                            lcd.cls();
+                            lcd.locate(0,0);
+                            lcd.printf("Minuto: ");
+                            
+                        }
+                    
+                    
+                    
+                    case 6: //MINUTOS
+                        m=0;
+                        m=Alarm_IRDA();        
+                        if (m!=0) 
+                        {
+                            min=m;
+                            if(min>59)
+                            {
+                                min=59;
+                            }
+                            if(min<0)
+                            {
+                                min=0;
+                            }  
+                            
+                        }
+                        lcd.locate(8,0);
+                        lcd.printf("%02d",min);
+                        
+                        if (Alarm_IRDA()==-8)
+                        {
+                            i++;
+                            
+                            lcd.cls();
+                            lcd.locate(0,0);
+                            lcd.printf("Segundo: ");
+                            
+                        }
+                    
+                    
+                    
+                    
+                    case 7: //SEGUNDOS
+                    m=0;
+                        m=Alarm_IRDA();        
+                        if (m!=0) 
+                        {
+                            sec=m;
+                            if(sec>59)
+                            {
+                                sec=59;
+                            }
+                            if(sec<0)
+                            {
+                                sec=0;
+                            }
+
+                        }
+                        
+                        lcd.locate(8,0);
+                        lcd.printf("%02d",sec);
+                        if(Alarm_IRDA()==-8){
+                            
+                            i++;
+                            
+                            lcd.cls();
+                            
+                    
+                        }
+                    
+                    case 8:
+                        m=0;
+                        lcd.locate(0,1);
+                        lcd.printf("\nAlarm:%02d:%02d:%02d",h,min,sec);
+                        lcd.locate(2,0);
+                        lcd.printf("\nFecha:%02d/%02d/%02d",d,mes,an);
+                        wait(2.5);
+                        lcd.cls();
+                        lcd.locate(0,1);
+                        lcd.printf("Alarma OK ?");
+                        lcd.locate(2,0);
+                        lcd.printf("--Si      --No");
+                        i++;
+                        
+                
+        
+            case 9:
+                
+                m=Alarm_IRDA();  // 
+               if(m==-2){
+                goto loop5;
+                
+                }
+                if (m==-1){  //
+                    pos++;
+                          
+                }
+                m=0;           
+        
+            
+                       
+                     
+                }
+                switch (pos)
+                {
+                    case 1:
+                        if(s==0){
+                            lcd.cls();
+                        lcd.locate(0,1);
+                        if(a==1){
+                        Vec1[1]=d;
+                        Vec1[2]=mes;
+                        Vec1[3]=an;
+                        Vec1[4]=h;
+                        Vec1[5]=min;
+                        Vec1[6]=sec;
+                            }
+                        if(a==2){
+                        Vec2[1]=d;
+                        Vec2[2]=mes;
+                        Vec2[3]=an;
+                        Vec2[4]=h;
+                        Vec2[5]=min;
+                        Vec2[6]=sec;
+                            }
+                        if(a==3){
+                        Vec3[1]=d;
+                        Vec3[2]=mes;
+                        Vec3[3]=an;
+                        Vec3[4]=h;
+                        Vec3[5]=min;
+                        Vec3[6]=sec;
+                            }
+                        if(a==4){
+                        Vec4[1]=d;
+                        Vec4[2]=mes;
+                        Vec4[3]=an;
+                        Vec4[4]=h;
+                        Vec4[5]=min;
+                        Vec4[6]=sec;
+                            }
+                        if(a==5){
+                        Vec5[1]=d;
+                        Vec5[2]=mes;
+                        Vec5[3]=an;
+                        Vec5[4]=h;
+                        Vec5[5]=min;
+                        Vec5[6]=sec;
+                            }
+                        if(a==6){
+                        Vec6[1]=d;
+                        Vec6[2]=mes;
+                        Vec6[3]=an;
+                        Vec6[4]=h;
+                        Vec6[5]=min;
+                        Vec6[6]=sec;
+                            }
+                        lcd.printf("Otra alarma? %0.2d",Vec1[6]);
+                        lcd.locate(2,0);
+                        lcd.printf("--Si      --No");
+                        
+                        pos++;
+                        m=0;
+                        }
+                                                    
+                    case 2:
+                        m=Alarm_IRDA();  // m son los datos del 
+                    
+                    if(m==-2){
+                        
+                        lcd.cls();
+                        m=0;
+                        goto loop1;// Va al reloj
+                        }
+                    if(m==-1){
+                        
+                        lcd.cls();
+                        m=0;
+                        goto loop3; //Va a alarma
+                        }
+                    break;
+                    
+                    }
+               
+        }
+        
+}
+}
+// ---- IRDA ----//
+
+int detectar(void){
+    int y = 0;
+      header=0;
+      ledd2=1;
+      led=1;
+      header = irda.read_low_us();    //funcion para leer un pulso de caida o bajo en header
+      if (header > head_L && header < head_H){wait_us(2000);//verificar que este en la tolerancia +-20%
+
+      // ES EL TIEMPO DE HEADER QUE NO SE Lee O EL ALTO 
+      ledd2=0;
+      for(il=0;il<(num_bits-1);++il){ // POR OSCILOSCOPIO se determina que llegan (num_bits),datos
+      dato = irda.read_high_us(); //leer un bit de datos que es pulso arriba en este control
+      num[il]=dato;
+      wait_us(300);   
+      }
+       //espero un poquito luego de leer todo el arreglo y ponerlo en pantalla 
+      
+      for(il=0;il<(num_bits-1);++il){  
+      if(num[il] > ((T_alto+T_bajo)/2)){ pc.printf("1");sel[il]='1';}
+      else {pc.printf("0");sel[il]='0';}
+            }
+        pc.printf("\n");
+        y = 1;
+        pc.printf("%d",y);
+}
+    return y;
+} 
+
+int irdan(void){
+    int numirda;
+  
+    
+    for(il=0; il<32; ++il)
+        {
+            if(!strcmp(sel,uno)) 
+            {
+                numirda=1;
+                break;
+            }
+            if(!strcmp(sel,dos)) 
+            {
+                numirda=2;
+            }
+            if(!strcmp(sel,tres)) 
+            {
+                numirda=3;
+            }
+             if(!strcmp(sel,cuatro)) 
+            {
+                numirda=4;
+            }
+            if(!strcmp(sel,cinco))
+            {
+                numirda=5;
+            }
+            if(!strcmp(sel,seis)) 
+            {
+                numirda=6;
+            }
+             if(!strcmp(sel,siete)) 
+            {
+                numirda=7;
+            }
+            if(!strcmp(sel,ocho)) 
+            {
+                numirda=8;
+            }
+            if(!strcmp(sel,nueve)) 
+            {
+                numirda=9;
+            }
+            if(!strcmp(sel,cero)) 
+            {
+                numirda=0;
+            }
+            if(!strcmp(sel,ok)) 
+            {
+                numirda=-8;
+            }
+            if(!strcmp(sel,izq)) 
+            {
+                numirda=-1;
+            }
+            if(!strcmp(sel,der))
+            {
+                numirda=-2;
+            }
+        }
+        return numirda;
+        }
+
+int Alarm_IRDA(void){
+    int x1 = 0, x2 = 0, x3 = 0, c = 0;
+    
+    
+    while(1){
+        if (detectar() == 1){
+            c++;
+            if(c == 1){
+                x1 = irdan();
+                pc.printf("\nx1: %d c: %d\n",x1,c);
+                x = x1;
+                if(x1==-8){
+                    x=x1;
+                    break;
+                    }
+                pc.printf("\nx: %02d",x);
+                pc.printf("num: %032d",irdan());
+            }//c1
+            
+            if(c == 2){
+                x2 = irdan();
+                pc.printf("\nx2: %d c: %d\n",x2,c);
+                if( x2 == -8){
+                    x = x1;
+                    pc.printf("\nx: %02d",x);
+                     pc.printf("num: %032d",sel);
+                    break;
+                }
+                else{
+                     x = x1*10 + x2;
+                     pc.printf("\nx: %02d",x);
+                      pc.printf("num: %032d",sel);
+                
+                }
+                
+                
+            }//c2
+            if (c == 3){
+                x3 = irdan();
+                pc.printf("\nx3: %d c: %d\n",x3,c);
+                pc.printf("\nx: %02d",x);
+                pc.printf("num: %032d",sel);
+                if( x3 == -8){
+                    x = ((x1*10) + x2);
+                    pc.printf("\nx: %02d",x);
+                     pc.printf("num: %032d",sel);
+                    break;
+                } 
+            }  //c3
+        }//detectar
+        
+        }//while
+        return x; 
+          
+    }//funcion
\ No newline at end of file
diff -r 000000000000 -r 1b7bc758e004 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Fri Aug 16 18:30:43 2019 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400
\ No newline at end of file