Conjunto de 4 alarmas on/off con reloj de tiempo real

Dependencies:   Debounced QEI RTC-DS1307 TextLCD mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "DebouncedIn.h"
00003 #include "TextLCD.h"
00004 #include "QEI.h"
00005 #include "Rtc_Ds1307.h"
00006  
00007 TextLCD lcd(PTB10, PTB11, PTE2, PTE3, PTE4, PTE5, TextLCD::LCD20x4); // rs, e, d4-d7 Teclado
00008 Rtc_Ds1307 rtc(PTE0, PTE1);//SCL,SDA
00009 QEI wheel (PTA13, PTD5, NC, 624, QEI::X4_ENCODING);
00010 Serial pc(USBTX, USBRX, "pc");
00011 DebouncedIn b_en(PTC16);
00012 
00013  
00014 DigitalOut red(LED_RED);
00015 DigitalOut green(LED_GREEN);
00016 DigitalOut blue(LED_BLUE);
00017 
00018 PwmOut Sonido(PTA5);
00019  
00020 float periodo;
00021 float Frecuencia=4000;
00022 int C1=0x0C;
00023 int m,k,x1,x2,x3,x4;
00024 int numero=1;
00025 int Conf=0;  // 0: Alarma y 1:Reloj
00026 int Lugar=0; // Definen el punto en el cual va el programa
00027 int i=0;
00028 int visual=0;
00029 int alarma=0; 
00030 int a = 0;
00031  
00032 int main()
00033 {
00034     Rtc_Ds1307::Time_rtc t = {};
00035     Rtc_Ds1307::Time_rtc Hora = {};
00036     Rtc_Ds1307::Time_rtc Alm = {};
00037     Rtc_Ds1307::Time_rtc Alm2 = {};
00038     Rtc_Ds1307::Time_rtc Alm3 = {};
00039     Rtc_Ds1307::Time_rtc Alm4 = {};
00040     Rtc_Ds1307::Time_rtc Alm_d = {};
00041     Rtc_Ds1307::Time_rtc Alm2_d = {};
00042     Rtc_Ds1307::Time_rtc Alm3_d = {};
00043     Rtc_Ds1307::Time_rtc Alm4_d = {};
00044     lcd.cls();
00045     lcd.writeCommand(C1);//escribimos un comando segun el manual del modulo LCD
00046        
00047     periodo=(1/Frecuencia);
00048     Sonido.period(periodo);
00049     
00050     rtc.getTime(Hora);
00051     rtc.stopClock(); 
00052     while(1){
00053         menu:
00054         switch (Lugar){
00055 
00056             case 0:     //Menu principal
00057                 lcd.cls();
00058                 rtc.getTime(Hora); //lee el tiempo del DS1307 
00059                 lcd.locate(0,0);
00060                 lcd.printf("%02d:%02d %02d/%02d/%02d", Hora.hour, Hora.min, Hora.date, Hora.mon, Hora.year);
00061                 lcd.locate(0,1);
00062                 lcd.printf("-Cambiar Hora");
00063                 lcd.locate(0,2);
00064                 lcd.printf("-Cambiar Alarma");
00065                 lcd.locate(0,3);
00066                 lcd.printf("-Visualizar");
00067                 m=wheel.getPulses();  // m son los datos del encoder
00068                 if(m!=0 && Conf==0){
00069                     Conf=1;
00070                     wheel.reset();  
00071                     m=0;              
00072                 }
00073                 if(m!=0 && Conf==1){
00074                     Conf=2;
00075                     wheel.reset();  
00076                     m=0;              
00077                 }
00078                 
00079                 if(m!=0 && Conf==2){
00080                     Conf=0;
00081                     wheel.reset();  
00082                     m=0;              
00083                 }
00084                 if(Conf==0){
00085                     lcd.locate(0,1);
00086                     lcd.printf(">");                    
00087                     lcd.locate(0,2);
00088                     lcd.printf("-");
00089                     lcd.locate(0,3);
00090                     lcd.printf("-");
00091                     //lcd.locate(0,1);                    
00092                     wait(0.1);
00093                 }
00094                 if(Conf==1){
00095                     lcd.locate(0,1);
00096                     lcd.printf("-");                    
00097                     lcd.locate(0,2);
00098                     lcd.printf(">");
00099                     lcd.locate(0,3);
00100                     lcd.printf("-");                    
00101                     //lcd.locate(0,1);                    
00102                     wait(0.1);
00103                 }
00104  
00105                 if(Conf==2){
00106                     lcd.locate(0,1);
00107                     lcd.printf("-");                    
00108                     lcd.locate(0,2);
00109                     lcd.printf("-");
00110                     lcd.locate(0,3);
00111                     lcd.printf(">");                    
00112                     //lcd.locate(0,1);                    
00113                     wait(0.1);
00114                 }               
00115                 if (b_en.falling()){  //si se pulsa boton encoder
00116                     if(Conf == 0){ 
00117                     Lugar++;
00118                     }
00119                     if(Conf == 1){ 
00120                     Lugar++;
00121                     }
00122                     if(Conf == 2){ 
00123                     Lugar=3;
00124                     }
00125                     m=0;       
00126                 }
00127             break;
00128     
00129             case 1://Configurar
00130                        if(Conf==0){
00131                             lcd.cls();
00132                             lcd.locate(0,0);
00133                             lcd.printf("Configurar Hora ");
00134                            goto hora;                               
00135                         }
00136                         
00137                        if(Conf==1){
00138                             lcd.cls();
00139                             lcd.locate(0,0);
00140                             lcd.printf("Configurar Alarma");
00141                             goto alarm;
00142                         }
00143                         if(Conf==2){
00144                             Lugar=3;
00145                         }     
00146     case 2:
00147     goto desactivar;
00148  
00149     case 3:     //Visualizar y Activacion Alarmas
00150         rtc.getTime(Hora);
00151         m=wheel.getPulses();
00152         if(x1==1){
00153             red=1;
00154         }
00155         if(x2==1){
00156             green=1;
00157         }
00158         if(x3==1){
00159             blue=1;
00160         }
00161         if(x4==1){
00162             red=1;
00163         }                
00164         if(m!=0){
00165             visual=visual+m;
00166             if(visual<0){
00167                 visual=0;
00168             }
00169             if(visual>4){
00170                 visual=4;
00171             }                    
00172             wheel.reset();  
00173             m=0;
00174         }
00175                 
00176         if(visual==0){//Visualiza hora
00177             lcd.cls();
00178             lcd.locate(0,0);    
00179             lcd.printf(" Ver   %02d:%02d:%02d",Hora.hour,Hora.min,Hora.sec);
00180             lcd.locate(0,1);
00181             lcd.printf("Hora :%02d/%02d/%04d",Hora.date,Hora.mon,Hora.year);
00182             wait(0.1);
00183         }   
00184         if(visual==1){//Visualilza alarma1
00185             lcd.cls();
00186             lcd.locate(0,0);    
00187             lcd.printf(" Ver   %02d:%02d:%02d",Alm.hour, Alm.min,Alm.sec);
00188             lcd.locate(0,1);
00189             lcd.printf("Alar1: %02d/%02d/%04d",Alm.date,Alm.mon,Alm.year);
00190             lcd.locate(0,2);    
00191             lcd.printf("Desact:%02d:%02d:%02d",Alm_d.hour, Alm_d.min,Alm_d.sec);
00192             lcd.locate(0,3);
00193             lcd.printf("Alar1: %02d/%02d/%04d",Alm_d.date,Alm_d.mon,Alm_d.year);
00194             wait(0.1);
00195         }
00196         if(visual==2){//Visualiza alarma2
00197             lcd.cls();
00198             lcd.locate(0,0);    
00199             lcd.printf(" Ver   %02d:%02d:%02d",Alm2.hour, Alm2.min,Alm2.sec);
00200             lcd.locate(0,1);
00201             lcd.printf("Alar2: %02d/%02d/%04d",Alm2.date,Alm2.mon,Alm2.year);
00202             lcd.locate(0,2);    
00203             lcd.printf("Desact %02d:%02d:%02d",Alm2_d.hour, Alm2_d.min,Alm2_d.sec);
00204             lcd.locate(0,3);
00205             lcd.printf("Alar2: %02d/%02d/%04d",Alm2_d.date,Alm2_d.mon,Alm2_d.year);
00206             wait(0.1);
00207         }
00208         if(visual==3){//Visualiza alarma3
00209             lcd.cls();
00210             lcd.locate(0,0);    
00211             lcd.printf(" Ver   %02d:%02d:%02d",Alm3.hour, Alm3.min,Alm3.sec);
00212             lcd.locate(0,1);
00213             lcd.printf("Alar3: %02d/%02d/%04d",Alm3.date,Alm3.mon,Alm3.year);
00214             lcd.locate(0,2);    
00215             lcd.printf("Desact: %02d:%02d:%02d",Alm3_d.hour, Alm3_d.min,Alm3_d.sec);
00216             lcd.locate(0,3);
00217             lcd.printf("Alar3: %02d/%02d/%04d",Alm3_d.date,Alm3_d.mon,Alm3_d.year);
00218             wait(0.1);
00219             
00220         }
00221         if(visual==4){//Visualiza alarma4
00222             lcd.cls();
00223             lcd.locate(0,0);    
00224             lcd.printf(" Ver    %02d:%02d:%02d",Alm4.hour, Alm4.min,Alm4.sec);
00225             lcd.locate(0,1);
00226             lcd.printf("Alar4:  %02d/%02d/%04d",Alm4.date,Alm4.mon,Alm4.year);
00227             lcd.locate(0,2);    
00228             lcd.printf("Desact: %02d:%02d:%02d",Alm4_d.hour, Alm4_d.min,Alm4_d.sec);
00229             lcd.locate(0,3);
00230             lcd.printf("Alar4:  %02d/%02d/%04d",Alm4_d.date,Alm4_d.mon,Alm4_d.year);
00231             wait(0.1);
00232         }
00233                      
00234         if (b_en.falling()){
00235             lcd.cls();
00236             Lugar=0;
00237         }
00238                 //Activacion  Alarma1               
00239         if((Hora.date==Alm.date)&&(Hora.mon==Alm.mon)&&(Hora.year==Alm.year)&&(Hora.hour==Alm.hour)&&(Hora.min==Alm.min)&&(Hora.sec==Alm.sec))
00240         {
00241                     lcd.cls();
00242                     lcd.locate(0,0);                        
00243                     lcd.printf("Alarma 1  Activa!!");
00244                     red =0;
00245                     wait(.2);
00246                     red =1;
00247                     wait(.2);
00248                     red =0;
00249                     wait(.2);
00250                     red =1;
00251                     wait(.2);
00252                     red =0;
00253                     lcd.locate(0,0);
00254                     lcd.printf("Esperando Desactivacion");
00255                     wait(1);                       
00256                     m=0;
00257                     k=1;
00258                     alarma = 1;
00259                     goto menu;
00260                 }
00261  
00262                 //Activacion  Alarma2               
00263                 if((Hora.date==Alm2.date)&&(Hora.mon==Alm2.mon)&&(Hora.year==Alm2.year)&&(Hora.hour==Alm2.hour)&&(Hora.min==Alm2.min)&&(Hora.sec==Alm2.sec))
00264                 {
00265                     lcd.cls();
00266                     lcd.locate(0,0);                        
00267                     lcd.printf("Alarma 2  Activa!!");
00268                     green =0;
00269                     wait(.2);
00270                     green =1;
00271                     wait(.2);
00272                     green =0;
00273                     wait(.2);
00274                     green =1;
00275                     wait(.2);
00276                     green =0;
00277                     lcd.locate(0,0);
00278                     lcd.printf("Esperando desactivacion");
00279                     wait(1);
00280                     Lugar = 3;                       
00281                     m=0;
00282                     k=2;
00283                     alarma = 1;
00284                     goto menu;
00285                 }
00286  
00287                 //Activacion  Alarma3               
00288                 if((Hora.date==Alm3.date)&&(Hora.mon==Alm3.mon)&&(Hora.year==Alm3.year)&&(Hora.hour==Alm3.hour)&&(Hora.min==Alm3.min)&&(Hora.sec==Alm3.sec))
00289                 {
00290                     lcd.cls();
00291                     lcd.locate(0,0);                        
00292                     lcd.printf("Alarma 3  Activa!!");
00293                     blue =0;
00294                     wait(.2);
00295                     blue =1;
00296                     wait(.2);
00297                     blue =0;
00298                     wait(.2);
00299                     blue =1;
00300                     wait(.2);
00301                     blue =0;
00302                     lcd.locate(0,0);
00303                     lcd.printf("Esperando desactivacion");
00304                     wait(1);
00305                     lcd.locate(0,1);             
00306                     m=0;
00307                     k=3;
00308                     alarma = 1;
00309                     goto menu;
00310                 }
00311                 //Activacion  Alarma4               
00312                 if((Hora.date==Alm4.date)&&(Hora.mon==Alm4.mon)&&(Hora.year==Alm4.year)&&(Hora.hour==Alm4.hour)&&(Hora.min==Alm4.min)&&(Hora.sec==Alm4.sec))
00313                 {
00314                     lcd.cls();
00315                     lcd.locate(0,0);                        
00316                     lcd.printf("Alarma 4  Activa!!");
00317                     red =0;
00318                     wait(.2);
00319                     red =1;
00320                     wait(.2);
00321                     red =0;
00322                     wait(.2);
00323                     red =1;
00324                     wait(.2);
00325                     red =0;
00326                     lcd.locate(0,0);
00327                     lcd.printf("Esperando desactivacion");
00328                     wait(1);                     
00329                     m=0;
00330                     alarma =1;
00331                     k=4;
00332                 }
00333                  
00334             //Desactivar Alarma
00335                 
00336                 if(alarma==1){
00337                     Sonido.write(0.5);
00338                     red = 0;
00339                     wait(0.2);
00340                     red = 1;
00341                     Sonido.write(0);
00342                     wait(0.2);
00343                     blue = 0;
00344                     Sonido.write(0.5);
00345                     wait(0.2);
00346                     blue = 1;
00347                     Sonido.write(0);
00348                     wait(0.2);
00349                 }
00350                 //Desactivacion  Alarma1               
00351         if((Hora.date==Alm_d.date)&&(Hora.mon==Alm_d.mon)&&(Hora.year==Alm_d.year)&&(Hora.hour==Alm_d.hour)&&(Hora.min==Alm_d.min)&&(Hora.sec==Alm_d.sec))
00352         {
00353                     lcd.cls();
00354                     lcd.locate(0,0);                        
00355                     lcd.printf("Alarma 1 Desactivada");
00356                     wait(1);
00357                     red =0;
00358                     wait(.2);
00359                     red =1;
00360                     wait(.2);
00361                     red =0;
00362                     wait(.2);
00363                     red =1;
00364                     wait(.2);
00365                     red =0;
00366                     lcd.cls();
00367                     lcd.locate(0,0);
00368                     lcd.printf("Adios");
00369                     alarma = 0;
00370                     wait(1);                       
00371                     m=0;
00372                     k=1;
00373                 }
00374  
00375                 //Desactivacion  Alarma2               
00376                 if((Hora.date==Alm2_d.date)&&(Hora.mon==Alm2_d.mon)&&(Hora.year==Alm2_d.year)&&(Hora.hour==Alm2_d.hour)&&(Hora.min==Alm2_d.min)&&(Hora.sec==Alm2_d.sec))
00377                 {
00378                     lcd.cls();
00379                     lcd.locate(0,0);                        
00380                     lcd.printf("Alarma 2  Desactivada");
00381                     wait(1);
00382                     green =0;
00383                     wait(.2);
00384                     green =1;
00385                     wait(.2);
00386                     green =0;
00387                     wait(.2);
00388                     green =1;
00389                     wait(.2);
00390                     green =0;
00391                     lcd.cls();
00392                     lcd.locate(0,0);
00393                     lcd.printf("Adios");
00394                     alarma = 0; 
00395                     wait(1);                      
00396                     m=0;
00397                     k=2;
00398                 }
00399  
00400                 //Desactivacion  Alarma3               
00401                 if((Hora.date==Alm3_d.date)&&(Hora.mon==Alm3_d.mon)&&(Hora.year==Alm3_d.year)&&(Hora.hour==Alm3_d.hour)&&(Hora.min==Alm3_d.min)&&(Hora.sec==Alm3_d.sec))
00402                 {
00403                     lcd.cls();
00404                     lcd.locate(0,0);                        
00405                     lcd.printf("Alarma 3 Desactivada");
00406                     blue =0;
00407                     wait(.2);
00408                     blue =1;
00409                     wait(.2);
00410                     blue =0;
00411                     wait(.2);
00412                     blue =1;
00413                     wait(.2);
00414                     blue =0;
00415                     lcd.locate(0,0);
00416                     lcd.printf("Adios"); 
00417                     wait(1);                      
00418                     m=0;
00419                     alarma = 0;
00420                     k=3;
00421                 }
00422                 //Desactivacion  Alarma4               
00423                 if((Hora.date==Alm4_d.date)&&(Hora.mon==Alm4_d.mon)&&(Hora.year==Alm4_d.year)&&(Hora.hour==Alm4_d.hour)&&(Hora.min==Alm4_d.min)&&(Hora.sec==Alm4_d.sec))
00424                 {
00425                     lcd.cls();
00426                     lcd.locate(0,0);                        
00427                     lcd.printf("Alarma 4  Desactivada");
00428                     wait(1);
00429                     red =0;
00430                     wait(.2);
00431                     red =1;
00432                     wait(.2);
00433                     red =0;
00434                     wait(.2);
00435                     red =1;
00436                     wait(.2);
00437                     red =0;
00438                     lcd.locate(0,0);
00439                     lcd.printf("Adios"); 
00440                     alarma = 0; 
00441                     wait(1);                     
00442                     m=0;
00443                     k=4;
00444                 }                          
00445                 ///////////////////
00446                 
00447                         break;
00448             
00449             
00450         }
00451     }
00452 
00453 // Lazo de config de hora
00454 
00455 hora:
00456     int i = 0;
00457     wait(1);
00458     lcd.cls();
00459     lcd.locate(0,0);
00460     lcd.printf("Segundos: ");
00461     Hora.sec=0;
00462     m=0;
00463     while(i == 0){
00464             m=wheel.getPulses();        
00465             if (m!=0){
00466                 Hora.sec=Hora.sec+m;
00467                 if(Hora.sec>59){
00468                         Hora.sec=59;
00469                 }
00470                 if(Hora.sec<0){
00471                         Hora.sec=0;
00472                 }
00473                 wheel.reset();  
00474                 m=0;
00475                 }
00476                 lcd.locate(0,1);
00477                 lcd.printf(" "); 
00478                 lcd.locate(0,1);
00479                 lcd.printf("%02d",Hora.sec);
00480                         
00481                 if (b_en.falling()){
00482                     lcd.cls();
00483                     lcd.locate(0,0);
00484                     lcd.printf("Minutos: ");
00485                     Hora.min = 0;
00486                     i++;
00487                     m=0;
00488                 }
00489         } 
00490     while(i == 1){
00491             m=wheel.getPulses();        
00492             if (m!=0){
00493                 Hora.min=Hora.min+m;
00494                 if(Hora.min>59){
00495                     Hora.min=59;
00496                 }
00497                 if(Hora.min<0){
00498                     Hora.min=0;
00499                 }
00500                 wheel.reset();  
00501                 m=0;
00502             }
00503             lcd.locate(0,1);
00504             lcd.printf(" "); 
00505             lcd.locate(0,1);
00506             lcd.printf("%02d",Hora.min);
00507             if (b_en.falling()){
00508                 lcd.cls();
00509                 lcd.locate(0,0);
00510                 lcd.printf("Hora: ");
00511                 Hora.hour = 0;
00512                 i++;
00513                 m=0;
00514             }
00515     }
00516                     
00517     while(i == 2){
00518         m=wheel.getPulses();        
00519         if (m!=0){
00520             Hora.hour=Hora.hour+m;
00521             if(Hora.hour>12){
00522                 Hora.hour=12;
00523             }
00524             if(Hora.hour<0){
00525                 Hora.hour=0;
00526             }
00527             wheel.reset();  
00528             m=0;
00529         }
00530         lcd.locate(0,1);
00531         lcd.printf("%02d",Hora.hour);
00532         if (b_en.falling()){
00533             lcd.cls();
00534             lcd.locate(0,0);
00535             lcd.printf("Hora definida: ");
00536             wait(1);
00537             lcd.cls();
00538             lcd.locate(0,0);
00539             lcd.printf("Fecha: ");
00540             wait(1);
00541             lcd.cls();
00542             lcd.locate(0,0);
00543             lcd.printf("Dia: ");
00544             Hora.date = 1; 
00545             i++;
00546             m=0;                            
00547         }
00548     }
00549     
00550     
00551     while (i == 3){
00552                 m=wheel.getPulses();                             
00553                 if (m!=0){
00554                     Hora.date=Hora.date+m;
00555                         if(Hora.date>59){
00556                             Hora.date=59;
00557                         }
00558                         if(Hora.date<1){        
00559                              Hora.date=1;
00560                         }
00561                         wheel.reset();  
00562                         m=0;
00563                         lcd.locate(0,1);
00564                         lcd.printf("%02d",Hora.date);
00565                 }
00566                         
00567                 if (b_en.falling()){
00568                             i++;
00569                             m=0;
00570                             lcd.cls();
00571                             lcd.locate(0,0);
00572                             lcd.printf("Mes: ");
00573                             Hora.mon = 1;
00574 
00575                 }
00576     } 
00577     
00578     while (i == 4){
00579                 m=wheel.getPulses();                             
00580                 if (m!=0){
00581                     Hora.mon=Hora.mon+m;
00582                         if(Hora.mon>12){
00583                             Hora.mon=12;
00584                         }
00585                         if(Hora.mon<1){        
00586                              Hora.mon=1;
00587                         }
00588                         wheel.reset();  
00589                         m=0;
00590                         lcd.locate(0,1);
00591                         lcd.printf("%02d",Hora.mon);
00592                 }
00593                 
00594                 if (b_en.falling()){
00595                             i++;
00596                             m=0;
00597                             lcd.cls();
00598                             lcd.locate(0,0);
00599                             lcd.printf("Ano: ");
00600                             Hora.year = 2016;
00601                 }
00602         }      
00603     while (i == 5){
00604                 m=wheel.getPulses();                             
00605                 if (m!=0){
00606                     Hora.year=Hora.year+m;
00607 
00608                         if(Hora.year<2016){        
00609                              Hora.year=2016;
00610                         }
00611                         wheel.reset();  
00612                         m=0;
00613                         lcd.locate(0,1);
00614                         lcd.printf("%02d",Hora.year);
00615                 }
00616                 
00617                 if (b_en.falling()){
00618                             i++;
00619                             m=0;
00620                             lcd.cls();
00621                             rtc.setTime(Hora, false, false);
00622                             rtc.startClock();
00623                 }
00624      }           
00625          
00626                     
00627     while(i == 6){  
00628             
00629             lcd.locate(0,0);
00630             lcd.printf("Esperando Hora ");
00631             if(rtc.getTime(Hora)){
00632             
00633             pc.printf("La hora actual es : %02d:%02d:%02d\n", Hora.hour, Hora.min, Hora.sec); // Me entrega la hora actual
00634             red = 0;
00635             lcd.cls();
00636             lcd.locate(0,0);
00637             lcd.printf("Hora: ");
00638             lcd.locate(0,1);
00639             lcd.printf("%02d:%02d:%02d", Hora.hour, Hora.min,Hora.sec);
00640             red = 1;
00641             wait(1);
00642             }
00643             if (b_en.falling()){
00644                 i++;  
00645                 Lugar = 3;                     
00646             }
00647         }
00648           
00649     while(i == 7){
00650     goto menu;
00651     }             
00652                 
00653                     
00654 
00655 // Lazo de Config Alarmas   
00656  
00657 alarm:  
00658 int pos=1;
00659 int l =0;
00660 
00661         while(l == 0){    
00662                 m=wheel.getPulses(); 
00663                 lcd.locate(0,0);
00664                 lcd.printf("Configurar Alarma %02d",pos);
00665                 lcd.locate(0,1);
00666                 lcd.printf("-1  -2   -3  -4");
00667                 if (m!=0){
00668                     pos=pos+m;
00669                     if(pos<1){
00670                         pos=1;
00671                         }
00672                     if(pos>4){
00673                         pos=4;
00674                         }
00675                     wheel.reset();  
00676                     m=0;
00677                 }
00678                 if(pos==1){
00679                     red =0;
00680                     green =1;
00681                     blue =1;
00682                     lcd.locate(0,1);
00683                     lcd.printf(">");                    
00684                     lcd.locate(4,1);
00685                     lcd.printf("-");
00686                     lcd.locate(9,1);                    
00687                     lcd.printf("-");
00688                     lcd.locate(13,1);                    
00689                     lcd.printf("-");
00690                     wait(0.1);    
00691                 }
00692                 if(pos==2){
00693                     red =1;
00694                     green =0;
00695                     blue =1;
00696                     lcd.locate(0,1);
00697                     lcd.printf("-");                    
00698                     lcd.locate(4,1);
00699                     lcd.printf(">");
00700                     lcd.locate(9,1);                    
00701                     lcd.printf("-");
00702                     lcd.locate(13,1);                    
00703                     lcd.printf("-");                  
00704                     wait(0.1);
00705                 }
00706                 if(pos==3){         
00707                     red =1;
00708                     green =1;
00709                     blue =0;
00710                     lcd.locate(0,1);
00711                     lcd.printf("-");                    
00712                     lcd.locate(4,1);
00713                     lcd.printf("-");
00714                     lcd.locate(9,1);                    
00715                     lcd.printf(">");
00716                     lcd.locate(13,1);                    
00717                     lcd.printf("-");                  
00718                     wait(0.1);    
00719                 }
00720                 if(pos==4){
00721                     red =0;
00722                     green =0;
00723                     blue =0;
00724                     lcd.locate(0,1);
00725                     lcd.printf("-");                    
00726                     lcd.locate(4,1);
00727                     lcd.printf("-");
00728                     lcd.locate(9,1);                    
00729                     lcd.printf("-");
00730                     lcd.locate(13,1);                    
00731                     lcd.printf(">");                  
00732                     wait(0.1);
00733                 }
00734                         
00735                 if (b_en.falling()){
00736                     m=0;
00737                     l = 1;
00738                     lcd.cls();
00739                     lcd.locate(0,0);                        
00740                     lcd.printf("Selecciono la");
00741                     lcd.locate(0,2);                        
00742                     lcd.printf("Alarma numero %02d ",pos);
00743                     wait(1.5);
00744                     lcd.cls();
00745                     
00746                 }
00747 
00748         }       
00749 
00750         lcd.cls();
00751         lcd.locate(0,0);
00752         lcd.printf("Dia: ");
00753         t.date = 1; 
00754 
00755     while (l == 1){
00756                 m=wheel.getPulses();                             
00757                 if (m!=0){
00758                     t.date=t.date+m;
00759                         if(t.date>31){
00760                             t.date=31;
00761                         }
00762                         if(t.date<1){        
00763                              t.date=1;
00764                         }
00765                         wheel.reset();  
00766                         m=0;
00767                         lcd.locate(0,1);
00768                         lcd.printf("%02d",t.date);
00769                 }
00770                         
00771                 if (b_en.falling()){
00772                             a++;
00773                             m=0;
00774                             lcd.cls();
00775                             lcd.locate(0,0);
00776                             lcd.printf("Mes: ");
00777                             t.mon = 1;
00778                             l = 2;
00779                 }
00780     }
00781     while (l == 2){
00782                 m=wheel.getPulses();                             
00783                 if (m!=0){
00784                     t.mon=t.mon+m;
00785                         if(t.mon>12){
00786                             t.mon=12;
00787                         }
00788                         if(t.mon<1){        
00789                              t.mon=1;
00790                         }
00791                         wheel.reset();  
00792                         m=0;
00793                         lcd.locate(0,1);
00794                         lcd.printf("%02d",t.mon);
00795                 }
00796                 
00797                 if (b_en.falling()){
00798                             a++;
00799                             m=0;
00800                             lcd.cls();
00801                             lcd.locate(0,0);
00802                             lcd.printf("Ano: ");
00803                             t.year = 2016;
00804                             l = 3;
00805                 }
00806         }      
00807     while (l == 3){
00808                 m=wheel.getPulses();                             
00809                 if (m!=0){
00810                     t.year=t.year+m;
00811 
00812                         if(t.year<2016){        
00813                              t.year=2016;
00814                         }
00815                         wheel.reset();  
00816                         m=0;
00817                         lcd.locate(0,1);
00818                         lcd.printf("%02d",t.year);
00819                 }
00820                 
00821                 if (b_en.falling()){
00822                             a++;
00823                             m=0;
00824                             lcd.cls();
00825                             lcd.locate(0,0);
00826                             lcd.printf("Hora: ");
00827                             t.hour = 0;
00828                             l = 4;
00829                 }
00830      }           
00831     while (l == 4){
00832                 m=wheel.getPulses();                             
00833                 if (m!=0){
00834                     t.hour=t.hour+m;
00835                     if(t.hour>23){
00836                         t.hour=23;
00837                     }
00838 
00839                     if(t.hour<0){        
00840                         t.hour=0;
00841                     }
00842                     wheel.reset();  
00843                     m=0;
00844                     lcd.locate(0,1);
00845                     lcd.printf("%02d",t.hour);
00846                 }
00847               
00848                 if (b_en.falling()){
00849                     a++;
00850                     m=0;
00851                     lcd.cls();
00852                     lcd.locate(0,0);
00853                     lcd.printf("Minuto: ");
00854                     t.min = 0;
00855                     l = 5;
00856                 }
00857         }
00858     while (l == 5){
00859                 m=wheel.getPulses();                             
00860                 if (m!=0){
00861                     t.min=t.min+m;
00862                     if(t.min>59){
00863                         t.min=59;
00864                     }
00865 
00866                     if(t.min<0){        
00867                         t.min=0;
00868                     }
00869                     wheel.reset();  
00870                     m=0;
00871                     lcd.locate(0,1);
00872                     lcd.printf("%02d",t.min);
00873                 }
00874                 
00875                 if (b_en.falling()){
00876                     a++;
00877                     m=0;
00878                     lcd.cls();
00879                     lcd.locate(0,0);
00880                     lcd.printf("Segundo: ");
00881                     t.sec = 0;
00882                     l = 6;
00883                 }
00884             
00885         }
00886     while (l == 6){
00887                 m=wheel.getPulses();                             
00888                 if (m!=0){
00889                     t.sec=t.sec+m;
00890                     if(t.sec>59){
00891                         t.sec=59;
00892                     }
00893 
00894                     if(t.sec<0){        
00895                         t.sec=0;
00896                     }
00897                     wheel.reset();  
00898                     m=0;
00899                     lcd.locate(0,1);
00900                     lcd.printf("%02d",t.sec);
00901                 }
00902                 
00903                 if (b_en.falling()){
00904 
00905                             if(pos ==1){
00906                                     Alm=t;
00907                                     x1=1;    
00908                                 }
00909                                 if(pos ==2){
00910                                     Alm2=t;
00911                                     x2=1;    
00912                                 }
00913                                 if(pos ==3){
00914                                     Alm3=t;    
00915                                     x3=1;
00916                                 }
00917                                 if(pos ==4){
00918                                     Alm4=t;    
00919                                     x4=1;
00920                                 }
00921                                 lcd.cls();
00922                                 lcd.locate(0,1);
00923                                 lcd.printf("Alarma %02d config",pos);
00924                                 wait(1);
00925                                 m=0;
00926                                 lcd.cls();
00927                                 l = 7;
00928                         }                                               
00929     }
00930     
00931     while(l == 7){
00932         lcd.cls();
00933         lcd.locate(0,0);
00934         lcd.printf("Prog Desactivacion");
00935         wait(2);
00936         l = 8;
00937     }
00938     
00939     while(l == 8){
00940         if (b_en.falling()){
00941         l = 9;
00942         lcd.cls();
00943         wait(1);
00944         }
00945     while(l == 9){
00946         Lugar=2;
00947         goto menu;
00948         }
00949     }   
00950 desactivar:
00951 l = 1;
00952         lcd.cls();
00953         lcd.locate(0,0);
00954         lcd.printf("Dia: ");
00955         t.date = 1; 
00956 
00957     while (l == 1){
00958                 m=wheel.getPulses();                             
00959                 if (m!=0){
00960                     t.date=t.date+m;
00961                         if(t.date>31){
00962                             t.date=31;
00963                         }
00964                         if(t.date<1){        
00965                              t.date=1;
00966                         }
00967                         wheel.reset();  
00968                         m=0;
00969                         lcd.locate(0,1);
00970                         lcd.printf("%02d",t.date);
00971                 }
00972                         
00973                 if (b_en.falling()){
00974                             a++;
00975                             m=0;
00976                             lcd.cls();
00977                             lcd.locate(0,0);
00978                             lcd.printf("Mes: ");
00979                             t.mon = 1;
00980                             l = 2;
00981                 }
00982     }
00983     while (l == 2){
00984                 m=wheel.getPulses();                             
00985                 if (m!=0){
00986                     t.mon=t.mon+m;
00987                         if(t.mon>12){
00988                             t.mon=12;
00989                         }
00990                         if(t.mon<1){        
00991                              t.mon=1;
00992                         }
00993                         wheel.reset();  
00994                         m=0;
00995                         lcd.locate(0,1);
00996                         lcd.printf("%02d",t.mon);
00997                 }
00998                 
00999                 if (b_en.falling()){
01000                             a++;
01001                             m=0;
01002                             lcd.cls();
01003                             lcd.locate(0,0);
01004                             lcd.printf("Ano: ");
01005                             t.year = 2016;
01006                             l = 3;
01007                 }
01008         }      
01009     while (l == 3){
01010                 m=wheel.getPulses();                             
01011                 if (m!=0){
01012                     t.year=t.year+m;
01013 
01014                         if(t.year<2016){        
01015                              t.year=2016;
01016                         }
01017                         wheel.reset();  
01018                         m=0;
01019                         lcd.locate(0,1);
01020                         lcd.printf("%02d",t.year);
01021                 }
01022                 
01023                 if (b_en.falling()){
01024                             a++;
01025                             m=0;
01026                             lcd.cls();
01027                             lcd.locate(0,0);
01028                             lcd.printf("Hora: ");
01029                             t.hour = 0;
01030                             l = 4;
01031                 }
01032      }           
01033     while (l == 4){
01034                 m=wheel.getPulses();                             
01035                 if (m!=0){
01036                     t.hour=t.hour+m;
01037                     if(t.hour>23){
01038                         t.hour=23;
01039                     }
01040 
01041                     if(t.hour<0){        
01042                         t.hour=0;
01043                     }
01044                     wheel.reset();  
01045                     m=0;
01046                     lcd.locate(0,1);
01047                     lcd.printf("%02d",t.hour);
01048                 }
01049               
01050                 if (b_en.falling()){
01051                     a++;
01052                     m=0;
01053                     lcd.cls();
01054                     lcd.locate(0,0);
01055                     lcd.printf("Minuto: ");
01056                     t.min = 0;
01057                     l = 5;
01058                 }
01059         }
01060     while (l == 5){
01061                 m=wheel.getPulses();                             
01062                 if (m!=0){
01063                     t.min=t.min+m;
01064                     if(t.min>59){
01065                         t.min=59;
01066                     }
01067 
01068                     if(t.min<0){        
01069                         t.min=0;
01070                     }
01071                     wheel.reset();  
01072                     m=0;
01073                     lcd.locate(0,1);
01074                     lcd.printf("%02d",t.min);
01075                 }
01076                 
01077                 if (b_en.falling()){
01078                     a++;
01079                     m=0;
01080                     lcd.cls();
01081                     lcd.locate(0,0);
01082                     lcd.printf("Segundo: ");
01083                     t.sec = 0;
01084                     l = 6;
01085                 }
01086             
01087         }
01088     while (l == 6){
01089                 m=wheel.getPulses();                             
01090                 if (m!=0){
01091                     t.sec=t.sec+m;
01092                     if(t.sec>59){
01093                         t.sec=59;
01094                     }
01095 
01096                     if(t.sec<0){        
01097                         t.sec=0;
01098                     }
01099                     wheel.reset();  
01100                     m=0;
01101                     lcd.locate(0,1);
01102                     lcd.printf("%02d",t.sec);
01103                 }
01104                 
01105                 if (b_en.falling()){
01106 
01107                             if(pos ==1){
01108                                     Alm_d=t;
01109                                     x1=1;    
01110                                 }
01111                                 if(pos ==2){
01112                                     Alm2_d=t;
01113                                     x2=1;    
01114                                 }
01115                                 if(pos ==3){
01116                                     Alm3_d=t;    
01117                                     x3=1;
01118                                     
01119                                 }
01120                                 if(pos ==4){
01121                                     Alm4_d=t;    
01122                                     x4=1;
01123                                 }
01124                                 lcd.cls();
01125                                 lcd.locate(0,1);
01126                                 lcd.printf("Alarma %02d Finalizo",pos);
01127                                 wait(1);
01128                                 m=0;
01129                                 lcd.cls();
01130                                 l = 7;
01131                         }                                               
01132     }
01133     while (l == 7){
01134         Lugar=3;
01135         goto menu;
01136     }        
01137 }